Example #1
0
def actionlink(request, action, title, comment=''):
    page = request.page
    params = '%s?action=%s' % (page.page_name, action)
    if action == 'RenamePage':
        params += '&subpages_checked=1'
    link = wikiutil.link_tag(request, params, title)
    return u''.join([u'<li>', link, comment, u'</li>'])
Example #2
0
 def logo(self):
     logo = u''
     if self.cfg.logo_string:
         pagename = wikiutil.getFrontPage(self.request).page_name
         pagename = wikiutil.quoteWikinameURL(pagename)
         logo = wikiutil.link_tag(self.request, pagename, self.cfg.logo_string, css_class="logo")
     return logo
Example #3
0
    def logo(self):
        """ Assemble logo with link to front page

        Changed: * we don't need a div wrapper for the textlogo
                 * append text "FrontPage" to the logo string
        
        @rtype: unicode
        @return: logo html
        """
        _ = self.request.getText
        html = u''
        if self.cfg.logo_string:
            page = wikiutil.getFrontPage(self.request)
            logo_string = self.cfg.logo_string
            logo_append = '<span class="screenreader_info"> %s</span>' % _('FrontPage', formatted=False) 
            logo_string = logo_string + logo_append
            # Try..except for backwards compatibility of Moin versions only
            try:
                logo = page.link_to_raw(self.request, logo_string)
            except:
                pagename = wikiutil.getFrontPage(self.request).page_name
                pagename = wikiutil.quoteWikinameURL(pagename)
                logo = wikiutil.link_tag(self.request, pagename, logo_string)
            html = u'%s' % logo
        return html
Example #4
0
def execute(macro, args):
    _ = macro.request.getText
    request = macro.request
    
    # do not show system admin to users not in superuser list
    if not request.user.isSuperUser():
        return ''

    result = []
    _MENU = {
        'attachments': (("File attachment browser"), do_admin_browser),
        'users': (("User account browser"), do_user_browser),
    }
    choice = request.form.get('sysadm', [None])[0]

    # create menu
    menuitems = [(label, id) for id, (label, handler) in _MENU.items()]
    menuitems.sort()
    for label, id in menuitems:
        if id == choice:
            result.append(macro.formatter.strong(1))
            result.append(macro.formatter.text(label))
            result.append(macro.formatter.strong(0))
        else:
            result.append(wikiutil.link_tag(request, "%s?sysadm=%s" % (macro.formatter.page.page_name, id), label))
        result.append('<br>')
    result.append('<br>')

    # add chosen content
    if _MENU.has_key(choice):
        result.append(_MENU[choice][1](request))

    return macro.formatter.rawHTML(''.join(result))
Example #5
0
def execute(self, args):
  #TODO - check that template is valid

  result = wikiutil.link_tag(self.request, "%s?action=edit&template=%s" % (
                        wikiutil.quoteWikinameURL(self.formatter.page.page_name),
                        wikiutil.quoteWikinameURL(args)), args)
  return result
Example #6
0
    def edittext_link(self, d, **keywords):
        """
        Assemble EditText link (or indication that page cannot be edited)
        
        @param d: parameter dictionary
        @rtype: string
        @return: edittext link html
        """
        _ = self.request.getText
        page = d["page"]
        if keywords.get("editable", 1):

            # Add edit link
            editable = self.request.user.may.write(d["page_name"]) and page.isWritable()
            if editable:
                title = _("EditText", formatted=False)
                edit = wikiutil.link_tag(self.request, d["q_page_name"] + "?action=edit", title)
            else:
                edit = _("Immutable page")

            # Add last edit info
            info = page.lastEditInfo()
            if info:
                if info.get("editor"):
                    info = _("last edited %(time)s by %(editor)s") % info
                else:
                    info = _("last modified %(time)s") % info
                return "<p>%s (%s)</p>" % (edit, info)
        return ""
Example #7
0
    def renderInText(self):
        """ Render macro in text context

        The parser should decide what to do if this macro is placed in a
        paragraph context.
        """
        _ = self.request.getText

        # Default to show page instead of an error message (too lazy to
        # do an error message now).
        action = self.args.get('action', 'show')
        
        # Use translated text or action name
        text = self.args.get('text', action)
        text = _(text, formatted=False)        

        # Escape user input
        action = wikiutil.escape(action, 1)
        text = wikiutil.escape(text, 1)

        # Create link
        formatter = self.macro.formatter
        page = wikiutil.quoteWikinameURL(formatter.page.page_name)
        url = '%s?action=%s' % (page, action)
        link = wikiutil.link_tag(self.request, url, text=text,
                                 formatter=formatter)
        return link
Example #8
0
 def editorLink(self, page):
     """ Return a link to the editor 
     
     If the user can't edit, return a disabled edit link.
     
     If the user want to show both editors, it will display "Edit
     (Text)", otherwise as "Edit".
     """
     #if not (page.isWritable() and
     #        self.request.user.may.write(page.page_name)):
     #    return self.disabledEdit()
     
     _ = self.request.getText
     params = (wikiutil.quoteWikinameURL(page.page_name) +
               '?action=edit&amp;editor=')
     
     guiworks = self.guiworks(page)
     if self.showBothEditLinks() and guiworks:
         text = _('Edit (Text)', formatted=False)
         params = params + 'text'
         attrs = {'name': "texteditlink"}
     else:
         text = _('Edit', formatted=False)
         if guiworks:
             # 'textonly' will be upgraded dynamically to 'guipossible' by JS
             params = params + 'textonly'
             attrs = {'name': "editlink"}
         else:
             params = params + 'text'
             attrs = {'name': "texteditlink"}
     
     return wikiutil.link_tag(self.request, params, text, **attrs)
Example #9
0
    def make_iconlink(self, which, d):
        """
        Make a link with an icon

        @param which: icon id (dictionary key)
        @param d: parameter dictionary
        @rtype: string
        @return: html link tag
        """
        page_name, querystr, title, icon = self.button_table[which]
        d['title'] = title % d
        d['i18ntitle'] = self.request.getText(d['title'], formatted=False)
        img_src = self.make_icon(icon, d)
        attrs = {'rel': 'nofollow', 'title': d['i18ntitle'], }
        if page_name:
            page = Page(self.request, page_name % d)
        else:
            page = d['page']
        if self.is_moin_1_5:  # Moin 1.5.x
            url = wikiutil.quoteWikinameURL(page.page_name)
            querystr = wikiutil.makeQueryString(querystr)
            if querystr:
                url = '%s?%s' % (url, querystr)
            html = wikiutil.link_tag(self.request, url, img_src, title="%(i18ntitle)s" % d)
        else:  # Moin 1.6
            rev = d['rev']
            if rev and which in ['raw', 'print', ]:
                querystr['rev'] = str(rev)
            html = page.link_to_raw(self.request, text=img_src, querystr=querystr, **attrs)
        return html
Example #10
0
    def availableactions(self, d):
        """
        assemble HTML code for the available actions
        
        @param d: parameter dictionary
        @rtype: string
        @return: available actions html
        """
        request = self.request
        _ = request.getText
        html = ""
        available = request.getAvailableActions(d["page"])
        if available:
            available = available.keys()
            available.sort()
            html = []
            for action in available:
                # Always add spaces: AttachFile -> Attach File
                # XXX TODO do not make a page object just for split_title
                title = Page(request, action).split_title(request, force=1)
                # Use translated version if available
                title = _(title, formatted=False)
                params = "%s?action=%s" % (d["q_page_name"], action)
                link = wikiutil.link_tag(request, params, title)
                html.append(link)

            html = u"<p>%s %s</p>\n" % (_("Or try one of these actions:"), u", ".join(html))
        return html
Example #11
0
 def revert_link(self, page):
     try:
         rev = self.request.rev
     except AttributeError:
         return u''
     if not (rev and page.isWritable() and self.request.user.may.revert(page.page_name)):
         return u''
     params = '%s?action=revert&rev=%d' % (wikiutil.quoteWikinameURL(page.page_name), rev)
     return wikiutil.link_tag(self.request, params, self._('Revert'), css_class="revert")
def execute(self, args):
    #TODO - check that template is valid

    result = wikiutil.link_tag(
        self.request,
        "%s?action=edit&template=%s" % (wikiutil.quoteWikinameURL(
            self.formatter.page.page_name), wikiutil.quoteWikinameURL(args)),
        args)
    return result
 def visit(self, request, name, depth):
     """ Visit a page, i.e. create a link.
     """
     if not name: return
     self.append('&nbsp;' * (5*depth))
     self.append('&nbsp;' + wikiutil.link_tag(request, '%s?action=%s' %
         (wikiutil.quoteWikinameURL(name), __name__.split('.')[-1]), name))
     self.append("&nbsp;<small>[")
     self.append(Page(request, name).link_to(request, 'view'))
     self.append("</small>]<br>")
Example #14
0
 def _add_refresh(self, formatter, cache, arena, key):
     _ = self._
     refresh = wikiutil.link_tag(
         formatter.request,
         wikiutil.quoteWikinameURL(formatter.page.page_name) + "?action=refresh&arena=%s&key=%s" % (arena, key),
         _("RefreshCache")
     ) + ' ' + _('for this page (cached %(date)s)') % {
         'date': formatter.request.user.getFormattedDateTime(cache.mtime()),
     } + '<br>'
     self.request.add2footer('RefreshCache', refresh)
Example #15
0
 def more_link(self, d, **keywords):
     _ = self.request.getText
     page = d['page']
     if not self.shouldShowEditbar(page):
         return u''
     params = (wikiutil.quoteWikinameURL(page.page_name) +
               '?action=allactions')
     text = _('Other', formatted=False)
     attrs = {'id': "otherlink"}
     return wikiutil.link_tag(self.request, params, text, **attrs)
Example #16
0
def actionlink(request, action, title, comment=''):
    page = request.page
    _ = request.getText
    # Always add spaces: AttachFile -> Attach File 
    # XXX TODO do not make a page object just for split_title
    title = Page(request, title).split_title(request) #, force=1)
    # Use translated version if available
    title = _(title, formatted=False)
    params = '%s?action=%s' % (page.page_name, action)
    link = wikiutil.link_tag(request, params, _(title))
    return u''.join([ u'<li>', link, comment, u'</li>' ])
Example #17
0
def actionlink(request, action, title, comment=''):
    page = request.page
    _ = request.getText
    # Always add spaces: AttachFile -> Attach File
    # XXX TODO do not make a page object just for split_title
    title = Page(request, title).split_title(request)  #, force=1)
    # Use translated version if available
    title = _(title, formatted=False)
    params = '%s?action=%s' % (page.page_name, action)
    link = wikiutil.link_tag(request, params, _(title))
    return u''.join([u'<li>', link, comment, u'</li>'])
Example #18
0
def execute(macro, args):
    _ = macro.request.getText

    # do not show system admin to not admin users
    if not macro.request.user.may.admin(macro.formatter.page.page_name):
        return ''

    result = []
    _MENU = {
        'attachments': (("File attachment browser"), do_admin_browser),
        'users': (("User account browser"), do_user_browser),
    }
    choice = macro.request.form.get('sysadm', [None])[0]

    # TODO: unfinished!
    if 0:
        result = wikiutil.link_tag(macro.request,
            "?action=export", _("Download XML export of this wiki"))
        if pysupport.isImportable('gzip'):
            result += " [%s]" % wikiutil.link_tag(macro.request,
            "?action=export&compression=gzip", "gzip")

    # create menu
    menuitems = [(label, id) for id, (label, handler) in _MENU.items()]
    menuitems.sort()
    for label, id in menuitems:
        if id == choice:
            result.append(macro.formatter.strong(1))
            result.append(macro.formatter.text(label))
            result.append(macro.formatter.strong(0))
        else:
            result.append(wikiutil.link_tag(macro.request,
                "%s?sysadm=%s" % (macro.formatter.page.page_name, id), label))
        result.append('<br>')
    result.append('<br>')

    # add chosen content
    if _MENU.has_key(choice):
        result.append(_MENU[choice][1](macro.request))

    return macro.formatter.rawHTML(''.join(result))
Example #19
0
 def attach_link(self, d, **keywords):
     _ = self.request.getText
     page = d['page']
     if not self.shouldShowEditbar(page):
         return u''
     if not (page.isWritable() and
             self.request.user.may.write(page.page_name)):
         return u''
     params = (wikiutil.quoteWikinameURL(page.page_name) +
               '?action=AttachFile')
     text = _('Attach', formatted=False)
     attrs = {'id': "attachlink"}
     return wikiutil.link_tag(self.request, params, text, **attrs)
Example #20
0
    def edit_link(self, d, **keywords):
        _ = self.request.getText
        page = d['page']
        text = _('Edit', formatted=False)
#        if not self.shouldShowEditbar(page):
#            return u''
        if not (page.isWritable() and
                self.request.user.may.write(page.page_name)):
            return u'<span id="editlink">%s</span>' % text
        params = (wikiutil.quoteWikinameURL(page.page_name) +
                  '?action=edit')
        attrs = {'id': "editlink"}
        return wikiutil.link_tag(self.request, params, text, **attrs)
Example #21
0
    def render(self):
        _ = self.request.getText

        pagename, attname = AttachFile.absoluteName(self.target, self.formatter.page.page_name)
        attachment_fname = AttachFile.getFilename(self.request, pagename, attname)

        if not os.path.exists(attachment_fname):
            linktext = _('Upload new attachment "%(filename)s"')
            return wikiutil.link_tag(self.request,
                ('%s?action=AttachFile&rename=%s' % (
                wikiutil.quoteWikinameURL(pagename),
                wikiutil.url_quote_plus(attname))),
                linktext % {'filename': attname})

        url = AttachFile.getAttachUrl(pagename, attname, self.request)
        mime_type, enc = mimetypes.guess_type(attname)

        if mime_type in ["application/x-shockwave-flash",
                         "application/x-dvi",
                         "application/postscript",
                         "application/pdf",
                         "application/ogg",
                         "application/vnd.visio",

                         "image/x-ms-bmp",
                         "image/svg+xml",
                         "image/tiff",
                         "image/x-photoshop",

                         "audio/mpeg",
                         "audio/midi",
                         "audio/x-wav",

                         "video/fli",
                         "video/mpeg",
                         "video/quicktime",
                         "video/x-msvideo",

                         "chemical/x-pdb",

                         "x-world/x-vrml",
                       ]:

            return self.embed(mime_type, url)

        else:
            msg = 'Not supported mimetype %(mimetype)s ' % {"mimetype": mime_type}
            return "%s%s%s" % (self.macro.formatter.sysmsg(1),
                       self.macro.formatter.text(msg),
                       self.macro.formatter.sysmsg(0))
Example #22
0
    def make_iconlink(self, which, d):
        """
        Make a link with an icon

        @param which: icon id (dictionary key)
        @param d: parameter dictionary
        @rtype: string
        @return: html link tag
        """
        page_params, title, icon = self.cfg.page_icons_table[which]
        d['title'] = title % d
        d['i18ntitle'] = self.request.getText(d['title'], formatted=False)
        img_src = self.make_icon(icon, d)
        return wikiutil.link_tag(self.request, page_params % d, img_src, title="%(i18ntitle)s" % d)
Example #23
0
 def interwiki(self, d):
     """ Assemble the interwiki name display, linking to page_front_page
     
     @param d: parameter dictionary
     @rtype: string
     @return: interwiki html
     """
     html = u''
     if self.request.cfg.show_interwiki:
         # Show our interwikiname or Self (and link to page_front_page)
         pagename = wikiutil.getFrontPage(self.request).page_name
         pagename = wikiutil.quoteWikinameURL(pagename)
         link = wikiutil.link_tag(self.request, pagename, self.request.cfg.interwikiname or 'Self')
         html = u'<div id="interwiki"><span>%s</span></div>' % link
     return html
Example #24
0
 def quicklinkLink(self, page):
     """ Return add/remove quicklink link
     
     @rtype: unicode
     @return: link to add or remove a quicklink
     """
     if not self.request.user.valid:
         return ''
     
     _ = self.request.getText
     if self.request.user.isQuickLinkedTo([page.page_name]):
         text = _("Remove Link", formatted=False)
     else:
         text = _("Add Link", formatted=False)
     params = wikiutil.quoteWikinameURL(page.page_name) + '?action=quicklink'
     return wikiutil.link_tag(self.request, params, text)
Example #25
0
def linkToPage(request, page, text, query_string=None):

    """
    Using 'request', return a link to 'page' with the given link 'text' and
    optional 'query_string'.
    """

    text = wikiutil.escape(text)

    if isMoin15():
        url = wikiutil.quoteWikinameURL(page.page_name)
        if query_string is not None:
            url = "%s?%s" % (url, query_string)
        return wikiutil.link_tag(request, url, text, getattr(page, "formatter", None))
    else:
        return page.link_to_raw(request, text, query_string)
Example #26
0
 def subscribeLink(self, page):
     """ Return subscribe/unsubscribe link to valid users
     
     @rtype: unicode
     @return: subscribe or unsubscribe link
     """
     if not (self.cfg.mail_enabled and self.request.user.valid):
         return ''
     
     _ = self.request.getText
     if self.request.user.isSubscribedTo([page.page_name]):
         text = _("Unsubscribe", formatted=False)
     else:
         text = _("Subscribe", formatted=False)
     params = wikiutil.quoteWikinameURL(page.page_name) + '?action=subscribe'
     return wikiutil.link_tag(self.request, params, text)
Example #27
0
    def recentchanges_header(self, d):
        """
        Assemble the recentchanges header (intro + open table)

        @param d: parameter dictionary
        @rtype: string
        @return: recentchanges header html
        """
        _ = self.request.getText

        # Should use user interface language and direction
        html = '<div class="recentchanges"%s>\n' % self.ui_lang_attr()
        html += '<div>\n'
        #page = d['page']
        #if self.shouldUseRSS(page):
        #    link = [
        #        u'<div class="rcrss">',
        #        self.request.formatter.url(1, self.rsshref(page)),
        #        self.request.formatter.rawHTML(self.make_icon("rss")),
        #        self.request.formatter.url(0),
        #        u'</div>',
        #        ]
        #    html += ''.join(link)
        html += '<p>'
        # Add day selector
        if d['rc_days']:
            days = []
            for day in d['rc_days']:
                if day == d['rc_max_days']:
                    days.append('<strong>%d</strong>' % day)
                else:
                    days.append(
                        wikiutil.link_tag(self.request,
                            '%s?max_days=%d' % (d['q_page_name'], day),
                            str(day),
                            self.request.formatter, rel='nofollow'))
            days = ' | '.join(days)
            html += (_("Show %s days.") % (days, ))

        if d['rc_update_bookmark']:
            html += " %(rc_update_bookmark)s %(rc_curr_bookmark)s" % d

        html += '</p>\n</div>\n'

        html += '<ul>\n'
        return html
Example #28
0
    def logo(self):
        """ Assemble logo with link to front page

        The logo contain an image and or text or any html markup the
        admin inserted in the config file. Everything it enclosed inside
        a div with id="logo".
        
        @rtype: unicode
        @return: logo html
        """
        html = u''
        if self.cfg.logo_string:
            pagename = wikiutil.getFrontPage(self.request).page_name
            pagename = wikiutil.quoteWikinameURL(pagename)
            logo = wikiutil.link_tag(self.request, pagename, self.cfg.logo_string)
            html = u'''<div id="logo">%s</div>''' % logo
        return html
Example #29
0
def getIndicator(request, pagename):
    """ Get an attachment indicator for a page (linked clip image) or
        an empty string if not attachments exist.
    """
    _ = request.getText
    attach_dir = getAttachDir(request, pagename)
    if not os.path.exists(attach_dir): return ''

    files = os.listdir(attach_dir)
    if not files: return ''

    attach_count = _('[%d attachments]') % len(files)
    attach_icon = request.theme.make_icon('attach', vars={ 'attach_count': attach_count })
    attach_link = wikiutil.link_tag(request,
        "%s?action=AttachFile" % wikiutil.quoteWikinameURL(pagename),
        attach_icon)

    return attach_link
Example #30
0
 def subscribeLink(self, page):
     """ Return subscribe/unsubscribe link to valid users
     
     @rtype: unicode
     @return: subscribe or unsubscribe link
     """
     _ = self.request.getText
     user = self.request.user
     if self.cfg.mail_smarthost and user.valid:
         # Email enabled and user valid, get current page status
         if user.isSubscribedTo([page.page_name]):
             title = _("Unsubscribe")
         else:
             title = _("Subscribe")
         quotedname = wikiutil.quoteWikinameURL(page.page_name)
         link = wikiutil.link_tag(self.request, quotedname + 
                                  '?action=subscribe', title)
         return link
     return ''
Example #31
0
    def recentchanges_header(self, d):
        """
        Assemble the recentchanges header (intro + open table)
        
        @param d: parameter dictionary
        @rtype: string
        @return: recentchanges header html
        """
        _ = self.request.getText
        
        # Should use user interface language and direction
        html = '<div class="recentchanges"%s>\n' % self.ui_lang_attr()
        html += '<div>\n'
        if self.shouldUseRSS():
            link = [
                u'<div class="rcrss">',
                u'<a href="%s">' % self.rsshref(),
                self.make_icon("rss"),
                u'</a>',
                u'</div>',
                ]
            html += ''.join(link)
        html += '<p>'
        if d['rc_update_bookmark']:
            html += "%(rc_update_bookmark)s %(rc_curr_bookmark)s<br>" % d

        # Add day selector
        if d['rc_days']:
            days = []
            for day in d['rc_days']:
                if day == d['rc_max_days']:
                    days.append('<strong>%d</strong>' % day)
                else:
                    days.append(
                        wikiutil.link_tag(self.request,
                            '%s?max_days=%d' % (d['q_page_name'], day),
                            str(day)))
            days = ' | '.join(days)
            html += (_("Show %s days.") % (days,))
        html += '</p>\n</div>\n'

        html += '<table>\n'
        return html
Example #32
0
    def make_iconlink(self, which, d):
        """
        Make a link with an icon

        @param which: icon id (dictionary key)
        @param d: parameter dictionary
        @rtype: string
        @return: html link tag
        """
        page_name, querystr, title, icon = self.button_table[which]
        d['title'] = title % d
        d['i18ntitle'] = self.request.getText(d['title'], formatted=False)
        img_src = self.make_icon(icon, d)
        attrs = {
            'rel': 'nofollow',
            'title': d['i18ntitle'],
        }
        if page_name:
            page = Page(self.request, page_name % d)
        else:
            page = d['page']
        if self.is_moin_1_5:  # Moin 1.5.x
            url = wikiutil.quoteWikinameURL(page.page_name)
            querystr = wikiutil.makeQueryString(querystr)
            if querystr:
                url = '%s?%s' % (url, querystr)
            html = wikiutil.link_tag(self.request,
                                     url,
                                     img_src,
                                     title="%(i18ntitle)s" % d)
        else:  # Moin 1.6
            rev = d['rev']
            if rev and which in [
                    'raw',
                    'print',
            ]:
                querystr['rev'] = str(rev)
            html = page.link_to_raw(self.request,
                                    text=img_src,
                                    querystr=querystr,
                                    **attrs)
        return html
    def wikirepl(self, match):
        url = match.group('url')

        if not url.startswith('attachment:'):
           return match.group()

        url = url[11:]

        attname=wikiutil.taintfilename(self.formatter.text(url))
        current_pagename=self.formatter.page.page_name
        attachment_path = os.path.join(AttachFile.getAttachDir(self.request,current_pagename), attname)
        if not os.path.exists(attachment_path):
            import urllib
            linktext = self.request.getText('Upload new attachment "%(filename)s"')
            return  wikiutil.link_tag(self.request,
                                      '%s?action=AttachFile&amp;rename=%s' %
                                      (current_pagename,
                                      urllib.quote_plus(attname)),
                                      linktext % {'filename': attname})

        return ( match.group('pre') +
            AttachFile.getAttachUrl(current_pagename,attname,self.request) +
            match.group('suf'))
Example #34
0
def execute(macro, args):
    request = macro.request
    _ = request.getText
    formatter = macro.formatter

    kwAllowed = ['width', 'height', 'alt']
    pp, pp_count, kw, kw_count = explore_args(args, kwAllowed)

    if not pp_count or pp_count and not pp[0]:
        msg = 'Not enough arguments given to ImageLink macro! Try <<ImageLink(example.png, WikiName, width=200)>>.'
        return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg),
                           formatter.sysmsg(0))

    image = pp[0]
    if pp_count >= 2 and pp[1]:
        target = pp[1]
        if target.startswith('attachment:') or target.startswith('inline:'):
            if target.startswith('attachment:'):
                target = (target.split('attachment:'))[1]
                pagename, attname = AttachFile.absoluteName(
                    target, formatter.page.page_name)
                target = AttachFile.getAttachUrl(pagename, target, request)
            elif target.startswith('inline:'):
                target = (target.split('inline:'))[1]
                pagename, attname = AttachFile.absoluteName(
                    target, formatter.page.page_name)
                target = AttachFile.getAttachUrl(pagename,
                                                 target,
                                                 request,
                                                 do='view')

            if not AttachFile.exists(request, pagename, attname):
                linktext = _('Upload new attachment "%(filename)s"',
                             formatted=False)
                return wikiutil.link_tag(request,
                                         ('%s?action=AttachFile&rename=%s' %
                                          (wikiutil.quoteWikinameURL(pagename),
                                           wikiutil.url_quote_plus(attname))),
                                         linktext % {'filename': attname})

            kw['src'] = AttachFile.getAttachUrl(pagename, image, request)

    elif pp_count == 1:
        pagename, attname = AttachFile.absoluteName(image,
                                                    formatter.page.page_name)
        target = AttachFile.getAttachUrl(pagename, image, request)
    else:
        target = None

    if _is_URL(image):
        kw['src'] = image
    else:
        pagename, attname = AttachFile.absoluteName(image,
                                                    formatter.page.page_name)
        kw['src'] = AttachFile.getAttachUrl(pagename, attname, request)
        if not AttachFile.exists(request, pagename, attname):
            linktext = _('Upload new attachment "%(filename)s"',
                         formatted=False)
            return wikiutil.link_tag(request,
                                     ('%s?action=AttachFile&rename=%s' %
                                      (wikiutil.quoteWikinameURL(pagename),
                                       wikiutil.url_quote_plus(attname))),
                                     linktext % {'filename': attname})

    if 'alt' not in kw:
        if target is None or _is_URL(target):
            if _is_URL(image):
                # Get image name http://here.com/dir/image.png -> image.png
                kw['alt'] = wikiutil.taintfilename(
                    formatter.text(image.split('/')[-1]))
            else:
                kw['alt'] = attname
        else:
            kw['alt'] = target

    if target is None:
        target = kw['src']

    if pp_count == 1:
        return "%s%s%s" % (formatter.url(
            1, kw['src']), formatter.image(**kw), formatter.url(0))

    if _is_URL(
            target
    ) or 'action=AttachFile&do=get&target=' in target or 'action=AttachFile&do=view&target=' in target:
        return "%s%s%s" % (formatter.url(
            1, target), formatter.image(**kw), formatter.url(0))
    else:
        if ":" in target:
            if target.startswith('wiki:'):
                target = target[5:]
            wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki(
                request, target)
            url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
            return "%s%s%s" % (formatter.url(
                1, url), formatter.image(**kw), formatter.url(0))
        else:
            return "%s%s%s" % (formatter.pagelink(
                1, target), formatter.image(**kw), formatter.pagelink(0))