Exemplo n.º 1
0
def insert_pages(request, flat_page_dict=None, plist=None,
                 without_files=False, global_pages=True):
    timenow = time.time()
    cursor = request.cursor
    if not flat_page_dict:
        if global_pages:
            flat_page_dict = all_pages
        else:
            flat_page_dict = basic_pages
    if not plist:
        plist = flat_page_dict.keys()
    file_dict = { 'uploaded_time': 0, 'uploaded_by': None,
                  'uploaded_by_ip': None }
    for pagename in plist:
        request.req_cache['pagenames'][
            pagename.lower()] = pagename # for caching
        flatpage = flat_page_dict[pagename]
        cursor.execute("""INSERT into curPages (name, text, cachedText,
                                                editTime, cachedTime,
                                                userEdited, propercased_name,
                                                wiki_id)
                          values (%(pagename)s, %(pagetext)s, NULL,
                                  %(timenow)s, NULL, NULL,
                                  %(propercased_name)s, %(wiki_id)s);""",
                       {'pagename':pagename.lower(), 'pagetext':flatpage.text,
                        'propercased_name':pagename,
                        'wiki_id': request.config.wiki_id,
                        'timenow': timenow}, isWrite=True)
        cursor.execute("""INSERT into allPages (name, text, editTime,
                                                userEdited, editType, comment,
                                                userIP, propercased_name,
                                                wiki_id)
                          values (%(pagename)s, %(pagetext)s, %(timenow)s,
                                  NULL, 'SAVENEW', 'System page', NULL,
                                  %(propercased_name)s, %(wiki_id)s);""",
                       {'pagename':pagename.lower(), 'pagetext':flatpage.text,
                       'propercased_name':pagename,
                       'wiki_id': request.config.wiki_id, 'timenow': timenow},
                       isWrite=True)
        file_dict['pagename'] = pagename
        for filename, content in flatpage.files:
            file_dict['filename'] = filename
            file_dict['filecontent'] = content
            if wikiutil.isImage(filename):
                xsize, ysize = Files.openImage(content).size
                file_dict['xsize'] = xsize
                file_dict['ysize'] = ysize
            wikidb.putFile(request, file_dict)
     
    insert_acl(plist, flat_page_dict, request)
Exemplo n.º 2
0
from Sycamore import config, request, wikidb, wikiutil
from PIL import Image

#################################################
# This script will rebuild the imageInfo table.
#################################################
req = request.RequestDummy()

req.cursor.execute("SELECT files.name, files.attached_to_pagename, wikis.name from files, wikis where files.wiki_id=wikis.id")
files_list = req.cursor.fetchall()
for file_info in files_list:
    name, attached_to_pagename, wiki_name = file_info
    print name
    
    if wikiutil.isImage(name):
        d = {'filename': name, 'page_name': attached_to_pagename}
        req.switch_wiki(wiki_name)
        file_get = wikidb.getFile(req, d)
	if not file_get:  continue
        filecontent, last_modified = file_get

    
        file = cStringIO.StringIO(filecontent)
        img = Image.open(file)
        img_size = img.size
        file.close()
    
        d['x'] = img_size[0]
        d['y'] = img_size[1]
        d['wiki_name'] = wiki_name
Exemplo n.º 3
0
def execute(macro, args, formatter=None):
    if not formatter:
        formatter = macro.formatter
    if line_has_just_macro(macro, args, formatter):
      macro.parser.inhibit_br = 2

    macro_text = ''

    baseurl = macro.request.getScriptname()
    action = 'Files' # name of the action that does the file stuff
    html = []
    ticketString = None # for temporary thumbnail generation
    pagename = formatter.page.page_name
    urlpagename = wikiutil.quoteWikiname(formatter.page.proper_name())

    if not args:
        macro_text += formatter.rawHTML(
            '<b>Please supply at least an image name, e.g. '
            '[[Image(image.jpg)]], where image.jpg is an image that\'s been '
            'uploaded to this page.</b>')
	return macro_text

    # image.jpg, "caption, here, yes", 20, right --- in any order
    # (filename first)
    # the number is the 'max' size (width or height) in pixels

    # parse the arguments
    try:
        (image_name, caption, thumbnail, px_size, alignment,
         border) = getArguments(args)
    except:
        macro_text += formatter.rawHTML('[[Image(%s)]]' % wikiutil.escape(args))
        return macro_text

    if not wikiutil.isImage(image_name):
        macro_text += "%s does not seem to be an image file." % image_name
        return macro_text

    url_image_name = urllib.quote(image_name.encode(config.charset))

    if (macro.formatter.processed_thumbnails.has_key(
            (pagename, image_name)) and
        (thumbnail or caption)):
        macro_text += ('<em style="background-color: #ffffaa; padding: 2px;">'
                       'A thumbnail or caption may be displayed only once per '
                       'image.</em>')
        return macro_text

    macro.formatter.processed_thumbnails[(pagename, image_name)] = True
    
    #is the original image even on the page?
    macro.request.cursor.execute("""SELECT name
                                    FROM files
                                    WHERE name=%(image_name)s and
                                    attached_to_pagename=%(pagename)s and
                                    wiki_id=%(wiki_id)s""",
                                 {'image_name':image_name,
                                  'pagename':pagename.lower(),
                                  'wiki_id':macro.request.config.wiki_id})
    result = macro.request.cursor.fetchone()
    image_exists = result

    if not image_exists:
        # lets make a link telling them they can upload the image,
        # just like the normal attachment
        linktext = 'Upload new image "%s"' % (image_name)
        macro_text += wikiutil.attach_link_tag(macro.request,
                  '%s?action=Files&amp;rename=%s#uploadFileArea' % (
                      wikiutil.quoteWikiname(formatter.page.proper_name()),
                      url_image_name),
                  linktext)
        return macro_text

    full_size_url = (baseurl + "/" + urlpagename + "?action=" + action +
                     "&amp;do=view&amp;target=" + url_image_name)
    # put the caption in the db if it's new and if we're not in preview mode
    if not formatter.isPreview():
        touchCaption(pagename, pagename, image_name, caption, macro.request)
    if caption:
        # parse the caption string
        caption = wikiutil.stripOuterParagraph(wikiutil.wikifyString(
            caption, formatter.request, formatter.page, formatter=formatter))

    if thumbnail:
        # let's generated the thumbnail or get the dimensions if it's
        # already been generated
        if not px_size:
            px_size = default_px_size
        (x, y), ticketString = touchThumbnail(macro.request, pagename,
                                              image_name, px_size, formatter)

        d = {'right':'floatRight', 'left':'floatLeft', '':'noFloat'}
        floatSide = d[alignment]
        if caption and border:
            html.append('<span class="%s thumb" style="width: %spx;">'
                        '<a style="color: black;" href="%s">'
                        '<img src="%s" alt="%s" style="display:block;"/></a>'
                        '<span>%s</span>'
                        '</span>' %
                        (floatSide, int(x)+2, full_size_url,
                         Files.getAttachUrl(pagename, image_name,
                                            macro.request, thumb=True,
                                            size=px_size, ticket=ticketString),
                         image_name, caption))
        elif border:
            html.append('<span class="%s thumb" style="width: %spx;">'
                        '<a style="color: black;" href="%s">'
                        '<img src="%s" alt="%s" style="display:block;"/></a>'
                        '</span>' %
                        (floatSide, int(x)+2, full_size_url,
                         Files.getAttachUrl(pagename, image_name,
                                            macro.request, thumb=True,
                                            size=px_size, ticket=ticketString),
                         image_name))
        elif caption and not border:
            html.append('<span class="%s thumb noborder" style="width: %spx;">'
                        '<a style="color: black;" href="%s">'
                        '<img src="%s" alt="%s" style="display:block;"/></a>'
                        '<span>%s</span></span>' %
                        (floatSide, int(x)+2, full_size_url,
                         Files.getAttachUrl(pagename, image_name,
                                            macro.request, thumb=True,
                                            size=px_size, ticket=ticketString),
                         image_name, caption))
        else:
            html.append('<span class="%s thumb noborder" style="width: %spx;">'
                        '<a style="color: black;" href="%s">'
                        '<img src="%s" alt="%s" style="display:block;"/></a>'
                        '</span>' %
                        (floatSide, int(x)+2, full_size_url,
                         Files.getAttachUrl(pagename, image_name,
                                            macro.request, thumb=True,
                                            size=px_size, ticket=ticketString),
                         image_name))
    else:
        x, y = getImageSize(pagename, image_name, macro.request)

        if not x and not y:
            # image has no size..something went amuck
            setImageSize(pagename, image_name, macro.request)
            x, y = getImageSize(pagename, image_name, macro.request)

        if not border and not caption:
            img_string = ('<a href="%s">'
                          '<img class="borderless" src="%s" alt="%s"/></a>' %
                          (full_size_url,
                           Files.getAttachUrl(pagename, image_name,
                                              macro.request,
                                              ticket=ticketString),
                           image_name))
        elif border and not caption:
            img_string = ('<a href="%s">'
                          '<img class="border" src="%s" alt="%s"/></a>' %
                          (full_size_url,
                           Files.getAttachUrl(pagename, image_name,
                                              macro.request,
                                              ticket=ticketString),
                           image_name))
        elif border and caption:
            img_string = ('<a href="%s">'
                          '<img class="border" src="%s" alt="%s"/></a>'
                          '<div style="width: %spx;">'
                          '<p class="normalCaption">%s</p></div>' %
                          (full_size_url,
                           Files.getAttachUrl(pagename, image_name,
                                              macro.request,
                                              ticket=ticketString),
                           image_name, x, caption))
        elif not border and caption:
            img_string = ('<a href="%s">'
                          '<img class="borderless" src="%s" alt="%s"/></a>'
                          '<div style="width: %spx;">'
                          '<p class="normalCaption">%s</p></div>' %
                          (full_size_url,
                           Files.getAttachUrl(pagename, image_name,
                                              macro.request,
                                              ticket=ticketString),
                           image_name, x, caption))

        if alignment == 'right':
            img_string = '<span class="floatRight">' + img_string + '</span>'
        elif alignment == 'left':
            img_string = '<span class="floatLeft">' + img_string + '</span>'

        html.append(img_string)
      
    macro_text += ''.join(html)
    return macro_text
Exemplo n.º 4
0
def copy_files(oldpagename, newpagename, request):
    """
    copies files from oldpagename to newpagename.
    keeps the files on oldpagename for manual deletion.
    if there is an file on the page newpagename that has the same name as a
    file on oldpagename, then the file from newpagename superseeds the old
    file, and the old file is deleted (but kept as a deleted file as per usual
    delete file/is accessable via the info tab)
    """
    from Sycamore.action.Files import get_filelist
    old_page_files = get_filelist(request, oldpagename)
    new_page_files = get_filelist(request, newpagename)
    for filename in old_page_files:
        is_image = wikiutil.isImage(filename)
        request.cursor.execute(
            """SELECT file, uploaded_time, uploaded_by, uploaded_by_ip,
                      attached_to_pagename_propercased from files
                      where name=%(filename)s and
                            attached_to_pagename=%(oldpagename)s and
                            wiki_id=%(wiki_id)s""", {
                'filename': filename,
                'oldpagename': oldpagename.lower(),
                'wiki_id': request.config.wiki_id
            })
        result = request.cursor.fetchone()

        if result:
            old_page_file_dict = {
                'filename': filename,
                'uploaded_time': result[1],
                'uploaded_by': result[2],
                'attached_to_pagename_propercased': result[4],
                'oldpagename': oldpagename.lower(),
                'uploaded_by_ip': result[3],
                'newpagename': newpagename.lower(),
                'newpagename_propercased': Page(newpagename,
                                                request).proper_name(),
                'timenow': time.time(),
                'userid': request.user.id,
                'userip': request.remote_addr,
                'wiki_id': request.config.wiki_id
            }
            if is_image:
                request.cursor.execute(
                    """SELECT xsize, ysize from imageInfo
                       where name=%(filename)s and
                             attached_to_pagename=%(oldpagename)s and
                             wiki_id=%(wiki_id)s""", {
                        'filename': filename,
                        'oldpagename': oldpagename.lower(),
                        'wiki_id': request.config.wiki_id
                    })
                result = request.cursor.fetchone()
                if result:
                    old_page_file_dict['xsize'] = result[0]
                    old_page_file_dict['ysize'] = result[1]

            if filename not in new_page_files:
                request.cursor.execute("""INSERT into files
                       (name, file, uploaded_time, uploaded_by, uploaded_by_ip,
                        attached_to_pagename, attached_to_pagename_propercased,
                        wiki_id)
                       values (%(filename)s,
                               (select file from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(oldpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               %(uploaded_time)s, %(uploaded_by)s,
                               %(uploaded_by_ip)s, %(newpagename)s,
                               %(newpagename_propercased)s, %(wiki_id)s
                              )""",
                                       old_page_file_dict,
                                       isWrite=True)
                if is_image:
                    if old_page_file_dict.has_key('xsize'):
                        request.cursor.execute("""INSERT into imageInfo
                               (name, attached_to_pagename, xsize, ysize,
                                wiki_id)
                               values (%(filename)s, %(newpagename)s,
                                       %(xsize)s, %(ysize)s, %(wiki_id)s) """,
                                               old_page_file_dict,
                                               isWrite=True)

            else:
                request.cursor.execute("""INSERT into oldFiles
                       (name, file, uploaded_time, uploaded_by, uploaded_by_ip,
                        attached_to_pagename, attached_to_pagename_propercased,
                        deleted_by, deleted_by_ip, deleted_time, wiki_id)
                       values (%(filename)s,
                               (SELECT file from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               (SELECT uploaded_time from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               (SELECT uploaded_by from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               (SELECT uploaded_by_ip from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               %(newpagename)s, %(newpagename_propercased)s,
                               %(userid)s, %(userip)s, %(timenow)s,
                               %(wiki_id)s)""",
                                       old_page_file_dict,
                                       isWrite=True)

                # clear out cached version of image
                if config.memcache:
                    request.mc.delete("files:%s,%s" %
                                      (wikiutil.mc_quote(filename),
                                       wikiutil.mc_quote(newpagename.lower())))

                if is_image:
                    request.cursor.execute("""INSERT into oldImageInfo
                           (name, attached_to_pagename, xsize, ysize,
                            uploaded_time, wiki_id)
                           values
                           (%(filename)s, %(newpagename)s,
                            (SELECT xsize from imageInfo
                             where name=%(filename)s and
                                   attached_to_pagename=%(newpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            (SELECT ysize from imageInfo
                             where name=%(filename)s and
                                   attached_to_pagename=%(newpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            (SELECT uploaded_time from files
                             where name=%(filename)s and
                                   attached_to_pagename=%(newpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            %(wiki_id)s)""",
                                           old_page_file_dict,
                                           isWrite=True)
                    request.cursor.execute("""DELETE from thumbnails
                           where name=%(filename)s and
                                 attached_to_pagename=%(newpagename)s and
                                 wiki_id=%(wiki_id)s""",
                                           old_page_file_dict,
                                           isWrite=True)

                request.cursor.execute(
                    """SELECT name from files
                       where name=%(filename)s and
                             attached_to_pagename=%(newpagename)s and
                             wiki_id=%(wiki_id)s""", old_page_file_dict)
                result = request.cursor.fetchone()
                if result:
                    request.cursor.execute("""UPDATE files set
                           file=(select file from files
                                 where name=%(filename)s and
                                       attached_to_pagename=%(oldpagename)s and
                                       wiki_id=%(wiki_id)s
                                ),
                           uploaded_time=%(timenow)s, uploaded_by=%(userid)s,
                           uploaded_by_ip=%(userip)s
                           where name=%(filename)s and
                                 attached_to_pagename=%(newpagename)s and
                                 wiki_id=%(wiki_id)s""",
                                           old_page_file_dict,
                                           isWrite=True)
                    if is_image and old_page_file_dict.has_key('xsize'):
                        request.cursor.execute("""UPDATE imageInfo set
                               xsize=%(xsize)s, ysize=%(ysize)s
                               where name=%(filename)s and
                                     attached_to_pagename=%(newpagename)s and
                                     wiki_id=%(wiki_id)s""",
                                               old_page_file_dict,
                                               isWrite=True)
                else:
                    request.cursor.execute("""INSERT into files
                           (name, file, uploaded_time, uploaded_by,
                            uploaded_by_ip, xsize, ysize, attached_to_pagename,
                            attached_to_pagename_propercased, wiki_id)
                           values
                           (%(filename)s,
                            (select file from files
                             where name=%(filename)s and
                                   attached_to_pagename=%(oldpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            %(uploaded_time)s, %(uploaded_by)s,
                            %(uploaded_by_ip)s, %(xsize)s, %(ysize)s,
                            %(newpagename)s, %(newpagename_propercased)s,
                            %(wiki_id)s)""",
                                           old_page_file_dict,
                                           isWrite=True)
                    if is_image and old_page_file_dict.has_key('xsize'):
                        request.cursor.execute("""INSERT into imageInfo
                               (name, attached_to_pagename, xsize, ysize,
                                wiki_id) values
                               (%(filename)s, %(newpagename)s, %(xsize)s,
                                %(ysize)s, %(wiki_id)s)""",
                                               old_page_file_dict,
                                               isWrite=True)
Exemplo n.º 5
0
def copy_files(oldpagename, newpagename, request):
    """
    copies files from oldpagename to newpagename.
    keeps the files on oldpagename for manual deletion.
    if there is an file on the page newpagename that has the same name as a
    file on oldpagename, then the file from newpagename superseeds the old
    file, and the old file is deleted (but kept as a deleted file as per usual
    delete file/is accessable via the info tab)
    """
    from Sycamore.action.Files import get_filelist
    old_page_files = get_filelist(request, oldpagename)
    new_page_files = get_filelist(request, newpagename)
    for filename in old_page_files:
        is_image = wikiutil.isImage(filename)
        request.cursor.execute(
            """SELECT file, uploaded_time, uploaded_by, uploaded_by_ip,
                      attached_to_pagename_propercased from files
                      where name=%(filename)s and
                            attached_to_pagename=%(oldpagename)s and
                            wiki_id=%(wiki_id)s""",
            {'filename':filename, 'oldpagename':oldpagename.lower(),
             'wiki_id':request.config.wiki_id})
        result = request.cursor.fetchone()

        if result: 
            old_page_file_dict = {
                'filename': filename,
                'uploaded_time': result[1],
                'uploaded_by': result[2],
                'attached_to_pagename_propercased': result[4],
                'oldpagename': oldpagename.lower(),
                'uploaded_by_ip': result[3],
                'newpagename': newpagename.lower(),
                'newpagename_propercased': Page(newpagename,
                                                request).proper_name(),
                'timenow': time.time(),
                'userid': request.user.id,
                'userip': request.remote_addr,
                'wiki_id': request.config.wiki_id
            }
            if is_image:
                request.cursor.execute(
                    """SELECT xsize, ysize from imageInfo
                       where name=%(filename)s and
                             attached_to_pagename=%(oldpagename)s and
                             wiki_id=%(wiki_id)s""",
                    {'filename': filename, 'oldpagename': oldpagename.lower(),
                     'wiki_id': request.config.wiki_id})
                result = request.cursor.fetchone()
                if result:
                    old_page_file_dict['xsize'] = result[0]
                    old_page_file_dict['ysize'] = result[1]
              
            if filename not in new_page_files:
                request.cursor.execute(
                    """INSERT into files
                       (name, file, uploaded_time, uploaded_by, uploaded_by_ip,
                        attached_to_pagename, attached_to_pagename_propercased,
                        wiki_id)
                       values (%(filename)s,
                               (select file from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(oldpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               %(uploaded_time)s, %(uploaded_by)s,
                               %(uploaded_by_ip)s, %(newpagename)s,
                               %(newpagename_propercased)s, %(wiki_id)s
                              )""",
                    old_page_file_dict, isWrite=True)
                if is_image:
                    if old_page_file_dict.has_key('xsize'):
                         request.cursor.execute(
                            """INSERT into imageInfo
                               (name, attached_to_pagename, xsize, ysize,
                                wiki_id)
                               values (%(filename)s, %(newpagename)s,
                                       %(xsize)s, %(ysize)s, %(wiki_id)s) """,
                            old_page_file_dict, isWrite=True)

            else:
                request.cursor.execute(
                    """INSERT into oldFiles
                       (name, file, uploaded_time, uploaded_by, uploaded_by_ip,
                        attached_to_pagename, attached_to_pagename_propercased,
                        deleted_by, deleted_by_ip, deleted_time, wiki_id)
                       values (%(filename)s,
                               (SELECT file from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               (SELECT uploaded_time from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               (SELECT uploaded_by from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               (SELECT uploaded_by_ip from files
                                where name=%(filename)s and
                                      attached_to_pagename=%(newpagename)s and
                                      wiki_id=%(wiki_id)s
                               ),
                               %(newpagename)s, %(newpagename_propercased)s,
                               %(userid)s, %(userip)s, %(timenow)s,
                               %(wiki_id)s)""",
                    old_page_file_dict, isWrite=True)

                # clear out cached version of image
                if config.memcache:
                    request.mc.delete("files:%s,%s" %
                                      (wikiutil.mc_quote(filename),
                                       wikiutil.mc_quote(newpagename.lower())))

                if is_image:
                    request.cursor.execute(
                        """INSERT into oldImageInfo
                           (name, attached_to_pagename, xsize, ysize,
                            uploaded_time, wiki_id)
                           values
                           (%(filename)s, %(newpagename)s,
                            (SELECT xsize from imageInfo
                             where name=%(filename)s and
                                   attached_to_pagename=%(newpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            (SELECT ysize from imageInfo
                             where name=%(filename)s and
                                   attached_to_pagename=%(newpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            (SELECT uploaded_time from files
                             where name=%(filename)s and
                                   attached_to_pagename=%(newpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            %(wiki_id)s)""",
                        old_page_file_dict, isWrite=True)
                    request.cursor.execute(
                        """DELETE from thumbnails
                           where name=%(filename)s and
                                 attached_to_pagename=%(newpagename)s and
                                 wiki_id=%(wiki_id)s""",
                        old_page_file_dict, isWrite=True)

                request.cursor.execute(
                    """SELECT name from files
                       where name=%(filename)s and
                             attached_to_pagename=%(newpagename)s and
                             wiki_id=%(wiki_id)s""", old_page_file_dict)
                result = request.cursor.fetchone()
                if result:
                    request.cursor.execute(
                        """UPDATE files set
                           file=(select file from files
                                 where name=%(filename)s and
                                       attached_to_pagename=%(oldpagename)s and
                                       wiki_id=%(wiki_id)s
                                ),
                           uploaded_time=%(timenow)s, uploaded_by=%(userid)s,
                           uploaded_by_ip=%(userip)s
                           where name=%(filename)s and
                                 attached_to_pagename=%(newpagename)s and
                                 wiki_id=%(wiki_id)s""",
                        old_page_file_dict, isWrite=True)
                    if is_image and old_page_file_dict.has_key('xsize'):
                        request.cursor.execute(
                            """UPDATE imageInfo set
                               xsize=%(xsize)s, ysize=%(ysize)s
                               where name=%(filename)s and
                                     attached_to_pagename=%(newpagename)s and
                                     wiki_id=%(wiki_id)s""",
                            old_page_file_dict, isWrite=True)
                else:
                    request.cursor.execute(
                        """INSERT into files
                           (name, file, uploaded_time, uploaded_by,
                            uploaded_by_ip, xsize, ysize, attached_to_pagename,
                            attached_to_pagename_propercased, wiki_id)
                           values
                           (%(filename)s,
                            (select file from files
                             where name=%(filename)s and
                                   attached_to_pagename=%(oldpagename)s and
                                   wiki_id=%(wiki_id)s
                            ),
                            %(uploaded_time)s, %(uploaded_by)s,
                            %(uploaded_by_ip)s, %(xsize)s, %(ysize)s,
                            %(newpagename)s, %(newpagename_propercased)s,
                            %(wiki_id)s)""", old_page_file_dict, isWrite=True)
                    if is_image and old_page_file_dict.has_key('xsize'):
                        request.cursor.execute(
                            """INSERT into imageInfo
                               (name, attached_to_pagename, xsize, ysize,
                                wiki_id) values
                               (%(filename)s, %(newpagename)s, %(xsize)s,
                                %(ysize)s, %(wiki_id)s)""",
                            old_page_file_dict, isWrite=True)
Exemplo n.º 6
0
    def render(self):
        _ = self.request.getText

        if self.type.find('/REVERT') != -1:
            # check if it's in version format (default)
            if self.comment[0] == 'v':
                given_comment = ''
                given_comment_start = self.comment.find('c')
                if given_comment_start and given_comment_start != -1:
                    given_comment = self.comment[given_comment_start+1:]
                    version = self.comment[1:given_comment_start]
                else:
                    version = self.comment[1:]
                if given_comment:
                    self.comment = (
                        "Revert to version %(version)s (%(given_comment)s)."
                        % {'version': version, 'given_comment': given_comment})
                else:     
                    self.comment = "Revert to version %s." % version
            else:
                datestamp = self.request.user.getFormattedDateTime(
                    float(self.comment))
                self.comment = (
                    "Revert to version dated %(datestamp)s." %
                    {'datestamp': datestamp})
        elif self.type == 'ATTNEW':
            if isImage(self.comment):
                file_type="image"
            else:
                file_type = "file"
            if self.pagename:
                if self.page:
                    link_loc = (
                        farm.getWikiURL(self.page.wiki_name, self.request) +
                        quoteWikiname(self.pagename) +
                        '?action=Files&do=view&target=' +
                        urllib.quote(self.comment.encode(config.charset)))
                else:
                    link_loc = (
                        self.request.getScriptname() + '/' +
                        quoteWikiname(self.pagename) +
                        '?action=Files&do=view&target=' +
                        urllib.quote(self.comment.encode(config.charset)))
                self.comment = 'Upload of %s <a href="%s">%s</a>.' % (
                    file_type, link_loc, self.comment)
            else:
              self.comment = "Upload of %s '%s'." % (file_type, self.comment)
        elif self.type == 'ATTDEL':
            if isImage(self.comment):
                file_type="Image"
            else:
                file_type = "File"
            if self.pagename: 
                if self.page:
                    link_loc = (
                        farm.getWikiURL(self.page.wiki_name, self.request) +
                        quoteWikiname(self.pagename) +
                        '?action=Files&do=view&target=' +
                        urllib.quote(self.comment.encode(config.charset)))
                else:
                    link_loc = (
                        self.request.getScriptname() + '/' +
                        quoteWikiname(self.pagename) +
                        '?action=Files&do=view&target=' +
                        urllib.quote(self.comment.encode(config.charset)))
                self.comment = '%s <a href="%s">%s</a> deleted.' % (
                    file_type, link_loc, self.comment)
            else: 
              self.comment = "%s '%s' deleted." % (file_type, self.comment)
        elif self.type == 'DELETE':
            if self.comment: 
                self.comment = "Page deleted (%s)" % self.comment
            else: 
                self.comment = "Page deleted (no comment)"
        elif self.type == 'NEWEVENT':
            self.comment = "Event '%s' posted." % self.comment
        elif self.type == 'SAVEMAP':
            self.comment = "Map location(s) modified"

        return _(self.comment)