def testJoinWiki(self):
     tests = [
         (('http://example.org/', u'SomePage', '', ''),
          'http://example.org/SomePage'),
         (('', u'SomePage', '', ''), 'SomePage'),
         (('http://example.org/?page=$PAGE&action=show', u'SomePage', '',
           ''), 'http://example.org/?page=SomePage&action=show'),
         (('http://example.org/', u'Aktuelle\xc4nderungen', '', ''),
          'http://example.org/Aktuelle%C3%84nderungen'),
         (('http://example.org/$PAGE/show', u'Aktuelle\xc4nderungen', '',
           ''), 'http://example.org/Aktuelle%C3%84nderungen/show'),
         (('http://example.org/', u'SomeItemID', 'itemid', u'ns1'),
          'http://example.org/ns1/@itemid/SomeItemID'),
         (('http://example.org/?page=$PAGE&action=show&namespace=$NAMESPACE',
           u'SomePage', '', u'ns1'),
          'http://example.org/?page=SomePage&action=show&namespace=ns1'),
         (('http://example.org/', u'Aktuelle\xc4nderungen', '', u'ns1\xc4'),
          'http://example.org/ns1%C3%84/Aktuelle%C3%84nderungen'),
         (('http://example.org/$NAMESPACE/$PAGE/show',
           u'Aktuelle\xc4nderungen', '', u'ns\xc41'),
          'http://example.org/ns%C3%841/Aktuelle%C3%84nderungen/show'),
         (('http://example.org/@$FIELD/$PAGE/show',
           u'Aktuelle\xc4nderungen', u'itemid', u''),
          'http://example.org/@itemid/Aktuelle%C3%84nderungen/show'),
     ]
     for (baseurl, pagename, field, namespace), url in tests:
         assert join_wiki(baseurl, pagename, field, namespace) == url
Example #2
0
 def testJoinWiki(self):
     tests = [(('http://example.org/', u'SomePage'), 'http://example.org/SomePage'),
              (('http://example.org/?page=$PAGE&action=show', u'SomePage'), 'http://example.org/?page=SomePage&action=show'),
              (('http://example.org/', u'Aktuelle\xc4nderungen'), 'http://example.org/Aktuelle%C3%84nderungen'),
              (('http://example.org/$PAGE/show', u'Aktuelle\xc4nderungen'), 'http://example.org/Aktuelle%C3%84nderungen/show'),
             ]
     for (baseurl, pagename), url in tests:
         assert join_wiki(baseurl, pagename) == url
Example #3
0
def get_editor_info(rev, external=False):
    from MoinMoin.items import USERID, ADDRESS, HOSTNAME
    addr = rev.get(ADDRESS)
    hostname = rev.get(HOSTNAME)
    text = _('anonymous')  # link text
    title = ''  # link title
    css = 'editor'  # link/span css class
    name = None  # author name
    uri = None  # author homepage uri
    email = None  # pure email address of author
    if app.cfg.show_hosts and addr:
        # only tell ip / hostname if show_hosts is True
        if hostname:
            text = hostname[:15]  # 15 = len(ipaddr)
            name = title = '%s[%s]' % (hostname, addr)
            css = 'editor host'
        else:
            name = text = addr
            title = '[%s]' % (addr, )
            css = 'editor ip'

    userid = rev.get(USERID)
    if userid:
        u = user.User(userid)
        name = u.name
        text = name
        aliasname = u.aliasname
        if not aliasname:
            aliasname = name
        if title:
            # we already have some address info
            title = "%s @ %s" % (aliasname, title)
        else:
            title = aliasname
        if u.mailto_author and u.email:
            email = u.email
            css = 'editor mail'
        else:
            homewiki = app.cfg.user_homewiki
            if homewiki in ('Self', app.cfg.interwikiname):
                homewiki = u'Self'
                css = 'editor homepage local'
                uri = url_for('frontend.show_item', item_name=name, _external=external)
            else:
                css = 'editor homepage interwiki'
                wt, wu, tail, err = resolve_interwiki(homewiki, name)
                uri = join_wiki(wu, tail)

    result = dict(name=name, text=text, css=css, title=title)
    if uri:
        result['uri'] = uri
    if email:
        result['email'] = email
    return result
Example #4
0
 def testJoinWiki(self):
     tests = [
         (('http://example.org/', u'SomePage'),
          'http://example.org/SomePage'),
         (('http://example.org/?page=$PAGE&action=show', u'SomePage'),
          'http://example.org/?page=SomePage&action=show'),
         (('http://example.org/', u'Aktuelle\xc4nderungen'),
          'http://example.org/Aktuelle%C3%84nderungen'),
         (('http://example.org/$PAGE/show', u'Aktuelle\xc4nderungen'),
          'http://example.org/Aktuelle%C3%84nderungen/show'),
     ]
     for (baseurl, pagename), url in tests:
         assert join_wiki(baseurl, pagename) == url
Example #5
0
    def testJoinWiki(self):
        tests = [(('http://example.org/', u'SomePage', '', ''), 'http://example.org/SomePage'),
                 (('', u'SomePage', '', ''), 'SomePage'),
                 (('http://example.org/?page=$PAGE&action=show', u'SomePage', '', ''), 'http://example.org/?page=SomePage&action=show'),
                 (('http://example.org/', u'Aktuelle\xc4nderungen', '', ''), 'http://example.org/Aktuelle%C3%84nderungen'),
                 (('http://example.org/$PAGE/show', u'Aktuelle\xc4nderungen', '', ''), 'http://example.org/Aktuelle%C3%84nderungen/show'),

                 (('http://example.org/', u'SomeItemID', 'itemid', u'ns1'), 'http://example.org/ns1/@itemid/SomeItemID'),
                 (('http://example.org/?page=$PAGE&action=show&namespace=$NAMESPACE', u'SomePage', '', u'ns1'), 'http://example.org/?page=SomePage&action=show&namespace=ns1'),
                 (('http://example.org/', u'Aktuelle\xc4nderungen', '', u'ns1\xc4'), 'http://example.org/ns1%C3%84/Aktuelle%C3%84nderungen'),
                 (('http://example.org/$NAMESPACE/$PAGE/show', u'Aktuelle\xc4nderungen', '', u'ns\xc41'), 'http://example.org/ns%C3%841/Aktuelle%C3%84nderungen/show'),
                 (('http://example.org/@$FIELD/$PAGE/show', u'Aktuelle\xc4nderungen', u'itemid', u''), 'http://example.org/@itemid/Aktuelle%C3%84nderungen/show'),
                ]
        for (baseurl, pagename, field, namespace), url in tests:
            assert join_wiki(baseurl, pagename, field, namespace) == url
Example #6
0
    def macro(self):
        iwlist = app.cfg.interwiki_map.items()
        iwlist.sort()

        iw_list = moin_page.list()
        for tag, url in iwlist:
            href = join_wiki(url, 'RecentChanges')
            link = moin_page.a(attrib={xlink.href: href}, children=[tag])
            label = moin_page.code(children=[link])
            iw_item_label = moin_page.list_item_label(children=[label])
            if '$PAGE' not in url:
                link = moin_page.a(attrib={xlink.href: url}, children=[url])
            else:
                link = url
            body = moin_page.code(children=[link])
            iw_item_body = moin_page.list_item_body(children=[body])
            iw_item = moin_page.list_item(children=[iw_item_label, iw_item_body])
            iw_list.append(iw_item)
        return iw_list
Example #7
0
    def path_breadcrumbs(self):
        """
        Assemble the path breadcrumbs (a.k.a.: trail)

        @rtype: list
        @return: path breadcrumbs items in tuple (wiki_name, item_name, url, exists, err)
        """
        user = self.user
        breadcrumbs = []
        trail = user.getTrail()
        for interwiki_item_name in trail:
            wiki_name, item_name = split_interwiki(interwiki_item_name)
            wiki_name, wiki_base_url, item_name, err = resolve_interwiki(wiki_name, item_name)
            href = join_wiki(wiki_base_url, item_name)
            if wiki_name in [self.cfg.interwikiname, 'Self', ]:
                exists = self.storage.has_item(item_name)
                wiki_name = ''  # means "this wiki" for the theme code
            else:
                exists = True  # we can't detect existance of remote items
            breadcrumbs.append((wiki_name, item_name, href, exists, err))
        return breadcrumbs
Example #8
0
    def userhome(self):
        """
        Assemble arguments used to build user homepage link

        @rtype: tuple
        @return: arguments of user homepage link in tuple (wiki_href, aliasname, title, exists)
        """
        user = self.user
        name = user.name
        aliasname = user.aliasname
        if not aliasname:
            aliasname = name

        wikiname, itemname = getInterwikiHome(name)
        title = "%s @ %s" % (aliasname, wikiname)
        # link to (interwiki) user homepage
        if wikiname == "Self":
            exists = self.storage.has_item(itemname)
        else:
            # We cannot check if wiki pages exists in remote wikis
            exists = True
        wiki_name, wiki_base_url, item_name, err = resolve_interwiki(wikiname, itemname)
        wiki_href = join_wiki(wiki_base_url, item_name)
        return wiki_href, aliasname, title, exists
Example #9
0
    def split_navilink(self, text, localize=1):
        """
        Split navibar links into pagename, link to page

        Admin or user might want to use shorter navibar items by using
        the [[page|title]] or [[url|title]] syntax. In this case, we don't
        use localization, and the links goes to page or to the url, not
        the localized version of page.

        Supported syntax:
            * PageName
            * WikiName:PageName
            * wiki:WikiName:PageName
            * url
            * all targets as seen above with title: [[target|title]]

        @param text: the text used in config or user preferences
        @rtype: tuple
        @return: pagename or url, link to page or url
        """
        title = None
        wiki_local = ''  # means local wiki

        # Handle [[pagename|title]] or [[url|title]] formats
        if text.startswith('[[') and text.endswith(']]'):
            text = text[2:-2]
            try:
                target, title = text.split('|', 1)
                target = target.strip()
                title = title.strip()
                localize = 0
            except (ValueError, TypeError):
                # Just use the text as is.
                target = text.strip()
        else:
            target = text

        if wikiutil.is_URL(target):
            if not title:
                title = target
            return target, title, wiki_local

        # remove wiki: url prefix
        if target.startswith("wiki:"):
            target = target[5:]

        # try handling interwiki links
        wiki_name, item_name = split_interwiki(target)
        wiki_name, wiki_base_url, item_name, err = resolve_interwiki(wiki_name, item_name)
        href = join_wiki(wiki_base_url, item_name)
        if wiki_name not in [self.cfg.interwikiname, 'Self', ]:
            if not title:
                title = item_name
            return href, title, wiki_name

        # Handle regular pagename like "FrontPage"
        item_name = wikiutil.normalize_pagename(item_name, self.cfg)

        # Use localized pages for the current user
        if localize:
            item_name = self.translated_item_name(item_name)

        if not title:
            title = item_name
        href = url_for('frontend.show_item', item_name=item_name)
        return href, title, wiki_local