Example #1
0
def setImageSize(pagename, image_name, request):
    """
    Sets the image size in the db.
    We only need this if the image's size isn't set yet.
    """
    # has side-effect we want :p
    Files.getCaptionsHTML(pagename, image_name, request) 
Example #2
0
    def css_url(self, basename, theme = None):
        """
        generate the css url

        @param basename: the css media type (base filename w/o .css)
        @param theme: theme name
        @rtype: string
        @return: the css url
        """
        # we assume that we've already initialized theme_files_last_modified
        if not self.request.config.theme_files_last_modified.has_key(
            basename + '.css'):
            wikiutil.init_theme_files_last_modified(self.request)
        if self.request.config.theme_files_last_modified.has_key(
            basename + '.css'):
            last_modified = self.request.config.theme_files_last_modified[
                basename + '.css']
            if self.request.isSSL():
                return self.request.getQualifiedURL(
                    uri=Files.getAttachUrl("%s/%s" % (
                                config.wiki_settings_page,
                                config.wiki_settings_page_css),
                            '%s.css' % basename, self.request,
                             ts=last_modified),
                    )
            else:
                return Files.getAttachUrl("%s/%s" %
                        (config.wiki_settings_page,
                         config.wiki_settings_page_css),
                    '%s.css' % basename, self.request, ts=last_modified)
        else:
            if self.request.isSSL():
                return self.request.getQualifiedURL(
                    uri=Files.getAttachUrl("%s/%s" %
                            (config.wiki_settings_page,
                             config.wiki_settings_page_css),
                        '%s.css' % basename, self.request),
                    )
            else:
                return Files.getAttachUrl("%s/%s" %
                        (config.wiki_settings_page,
                         config.wiki_settings_page_css),
                    '%s.css' % basename, self.request)
Example #3
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)
Example #4
0
def execute(macro, args, formatter=None):
    if not formatter:
        formatter = macro.formatter
    action = 'Files'
    pagename = formatter.page.page_name
    baseurl = macro.request.getScriptname()
    urlpagename = wikiutil.quoteWikiname(formatter.page.proper_name())

    if not args:
        return formatter.rawHTML('<b>Please supply at least a file name, '
                                 'e.g. [[File(filename.txt)]], where '
                                 'filename.txt is a file that\'s been '
                                 'uploaded to this page.</b>')
    filename = args

    macro.request.cursor.execute("""SELECT name
                                    FROM files
                                    WHERE name=%(filename)s and
                                          attached_to_pagename=%(pagename)s and
                                          wiki_id=%(wiki_id)s""",
                                 {'filename':filename,
                                  'pagename':pagename.lower(),
                                  'wiki_id':macro.request.config.wiki_id})
    result = macro.request.cursor.fetchone()
    file_exists = result

    urlfile = urllib.quote(filename)
    if not file_exists:
        #lets make a link telling them they can upload the file
        linktext = 'Upload new file "%s"' % (filename)
        return wikiutil.attach_link_tag(
            macro.request,
            '%s?action=Files&amp;rename=%s%s#uploadFileArea' % (
                wikiutil.quoteWikiname(formatter.page.proper_name()),
                urlfile,
                ''),
            linktext)

    urlfile = urllib.quote(filename)
    html = ('<span class="fileLink"><img src="%(icon)s"/>'
            '<a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;'
                     'do=view&target=%(urlfile)s">'
                '%(file)s'
            '</a></span>' %
            {'icon':Files.get_icon(filename, macro.request), 'baseurl':baseurl,
             'urlpagename':urlpagename, 'urlfile':urlfile, 'file':filename,
             'action':action})
    return html
Example #5
0
def revert_file_to_version(filename, pagename, version_date, wiki_name,
                           request, keep_deleted_state=False):
    request.switch_wiki(wiki_name)
    Files.restore_file(filename, version_date, pagename, request,
                       permanent=True, showrc=False,
                       keep_deleted_state=keep_deleted_state)
Example #6
0
def delete_file(filename, pagename, wiki_name, request):
    request.switch_wiki(wiki_name)
    Files.del_file(filename, pagename, request, permanent=True)
Example #7
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