示例#1
0
 def inline_link_repl(self, stack, link, link_url=None, link_item=None, link_text=None,
                      link_interwiki_site=None, link_interwiki_item=None):
     """Handle all kinds of links."""
     if link_interwiki_site:
         if is_known_wiki(link_interwiki_site):
             link = Iri(scheme='wiki',
                        authority=link_interwiki_site,
                        path='/' + link_interwiki_item)
             element = moin_page.a(attrib={xlink.href: link})
             stack.push(element)
             if link_text:
                 self.parse_inline(link_text, stack, self.inlinedesc_re)
             else:
                 stack.top_append(link_interwiki_item)
             stack.pop()
             return
         else:
             # assume local language uses ":" inside of words, set link_item and continue
             link_item = '{0}:{1}'.format(link_interwiki_site, link_interwiki_item)
     if link_item is not None:
         att = 'attachment:'  # moin 1.9 needed this for an attached file
         if link_item.startswith(att):
             link_item = '/' + link_item[len(att):]  # now we have a subitem
         target = unicode(Iri(scheme='wiki.local', path=link_item))
         text = link_item
     else:
         target = link_url
         text = link_url
     element = moin_page.a(attrib={xlink.href: target})
     stack.push(element)
     if link_text:
         self.parse_inline(link_text, stack, self.inlinedesc_re)
     else:
         stack.top_append(text)
     stack.pop()
示例#2
0
 def handle_wiki_links(self, elem, input):
     wiki_name = 'Self'
     if input.authority and input.authority.host:
         wn = unicode(input.authority.host)
         if is_known_wiki(wn):
             # interwiki link
             elem.set(moin_page.class_, 'moin-interwiki')
             wiki_name = wn
     item_name = unicode(input.path[1:])
     endpoint, rev, query = self._get_do_rev(input.query)
     url = url_for_item(item_name, wiki_name=wiki_name, rev=rev, endpoint=endpoint)
     link = Iri(url, query=query, fragment=input.fragment)
     elem.set(self._tag_xlink_href, link)
示例#3
0
 def inline_link_repl(self, stack, link, link_url=None, link_item=None,
                      link_text=None, link_args=None,
                      link_interwiki_site=None, link_interwiki_item=None):
     """Handle all kinds of links."""
     if link_interwiki_site:
         if is_known_wiki(link_interwiki_site):
             link = Iri(scheme='wiki',
                        authority=link_interwiki_site,
                        path='/' + link_interwiki_item)
             element = moin_page.a(attrib={xlink.href: link})
             stack.push(element)
             if link_text:
                 self.parse_inline(link_text, stack, self.inlinedesc_re)
             else:
                 stack.top_append(link_interwiki_item)
             stack.pop()
             return
         else:
             # assume local language uses ":" inside of words, set link_item and continue
             link_item = '{0}:{1}'.format(link_interwiki_site, link_interwiki_item)
     if link_args:
         link_args = parse_arguments(link_args)  # XXX needs different parsing
         query = url_encode(link_args.keyword, charset=CHARSET, encode_keys=True)
     else:
         query = None
     if link_item is not None:
         att = 'attachment:'  # moin 1.9 needed this for an attached file
         if link_item.startswith(att):
             link_item = '/' + link_item[len(att):]  # now we have a subitem
         if '#' in link_item:
             path, fragment = link_item.rsplit('#', 1)
             if link_item.startswith('#') and '/+convert/' in request.url:
                 # avoid traceback in link.py when converting moinwiki item to ReST | HTML | Docbook
                 path = request.url.split('+convert/')[-1]
         else:
             path, fragment = link_item, None
         target = Iri(scheme='wiki.local', path=path, query=query, fragment=fragment)
         text = link_item
     else:
         target = Iri(link_url)
         text = link_url
     element = moin_page.a(attrib={xlink.href: target})
     stack.push(element)
     if link_text:
         self.parse_inline(link_text, stack, self.inlinedesc_re)
     else:
         stack.top_append(text)
     stack.pop()
示例#4
0
 def inline_link_repl(self,
                      stack,
                      link,
                      link_url=None,
                      link_item=None,
                      link_text=None,
                      link_interwiki_site=None,
                      link_interwiki_item=None):
     """Handle all kinds of links."""
     if link_interwiki_site:
         if is_known_wiki(link_interwiki_site):
             link = Iri(scheme='wiki',
                        authority=link_interwiki_site,
                        path='/' + link_interwiki_item)
             element = moin_page.a(attrib={xlink.href: link})
             stack.push(element)
             if link_text:
                 self.parse_inline(link_text, stack, self.inlinedesc_re)
             else:
                 stack.top_append(link_interwiki_item)
             stack.pop()
             return
         else:
             # assume local language uses ":" inside of words, set link_item and continue
             link_item = '{0}:{1}'.format(link_interwiki_site,
                                          link_interwiki_item)
     if link_item is not None:
         att = 'attachment:'  # moin 1.9 needed this for an attached file
         if link_item.startswith(att):
             link_item = '/' + link_item[len(att):]  # now we have a subitem
         # we have Anchor macro, so we support anchor links despite lack of docs in Creole spec
         if '#' in link_item:
             path, fragment = link_item.rsplit('#', 1)
         else:
             path, fragment = link_item, None
         target = Iri(scheme='wiki.local', path=path, fragment=fragment)
         text = link_item
     else:
         target = Iri(link_url)
         text = link_url
     element = moin_page.a(attrib={xlink.href: target})
     stack.push(element)
     if link_text:
         self.parse_inline(link_text, stack, self.inlinedesc_re)
     else:
         stack.top_append(text)
     stack.pop()
示例#5
0
 def inline_link_repl(self, stack, link, link_url=None, link_item=None,
                      link_text=None, link_args=None,
                      link_interwiki_site=None, link_interwiki_item=None):
     """Handle all kinds of links."""
     if link_interwiki_site:
         if is_known_wiki(link_interwiki_site):
             link = Iri(scheme='wiki',
                        authority=link_interwiki_site,
                        path='/' + link_interwiki_item)
             element = moin_page.a(attrib={xlink.href: link})
             stack.push(element)
             if link_text:
                 self.parse_inline(link_text, stack, self.inlinedesc_re)
             else:
                 stack.top_append(link_interwiki_item)
             stack.pop()
             return
         else:
             # assume local language uses ":" inside of words, set link_item and continue
             link_item = '{0}:{1}'.format(link_interwiki_site, link_interwiki_item)
     if link_args:
         link_args = parse_arguments(link_args)  # XXX needs different parsing
         query = url_encode(link_args.keyword, charset=CHARSET, encode_keys=True)
     else:
         query = None
     if link_item is not None:
         att = 'attachment:'  # moin 1.9 needed this for an attached file
         if link_item.startswith(att):
             link_item = '/' + link_item[len(att):]  # now we have a subitem
         if '#' in link_item:
             path, fragment = link_item.rsplit('#', 1)
         else:
             path, fragment = link_item, None
         target = Iri(scheme='wiki.local', path=path, query=query, fragment=fragment)
         text = link_item
     else:
         target = Iri(link_url)
         text = link_url
     element = moin_page.a(attrib={xlink.href: target})
     stack.push(element)
     if link_text:
         self.parse_inline(link_text, stack, self.inlinedesc_re)
     else:
         stack.top_append(text)
     stack.pop()
示例#6
0
    def inline_freelink_repl(self,
                             stack,
                             freelink,
                             freelink_bang=None,
                             freelink_interwiki_page=None,
                             freelink_interwiki_ref=None,
                             freelink_page=None,
                             freelink_email=None):
        if freelink_bang:
            stack.top_append(freelink)
            return

        attrib = {}

        if freelink_page:
            page = freelink_page.encode('utf-8')
            if '#' in page:
                path, fragment = page.rsplit('#', 1)
            else:
                path, fragment = page, None
            link = Iri(scheme='wiki.local', path=path, fragment=fragment)
            text = freelink_page

        elif freelink_email:
            link = 'mailto:' + freelink_email
            text = freelink_email

        else:
            if not is_known_wiki(freelink_interwiki_ref):
                stack.top_append(freelink)
                return

            link = Iri(scheme='wiki',
                       authority=freelink_interwiki_ref,
                       path='/' + freelink_interwiki_page)
            text = freelink_interwiki_page

        attrib[xlink.href] = link

        element = moin_page.a(attrib, children=[text])
        stack.top_append(element)
示例#7
0
    def path_breadcrumbs(self):
        """
        Assemble the path breadcrumbs (a.k.a.: trail)

        :rtype: list
        :returns: path breadcrumbs items in tuple (wiki_name, item_name, url, exists, err)
        """
        user = self.user
        breadcrumbs = []
        trail = user.get_trail()
        for interwiki_item_name in trail:
            wiki_name, item_name = split_interwiki(interwiki_item_name)
            err = not is_known_wiki(wiki_name)
            href = url_for_item(item_name, wiki_name=wiki_name)
            if is_local_wiki(wiki_name):
                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
示例#8
0
    def path_breadcrumbs(self):
        """
        Assemble the path breadcrumbs (a.k.a.: trail)

        :rtype: list
        :returns: path breadcrumbs items in tuple (wiki_name, item_name, url, exists, err)
        """
        user = self.user
        breadcrumbs = []
        trail = user.get_trail()
        for interwiki_item_name in trail:
            wiki_name, namespace, field, item_name = split_interwiki(interwiki_item_name)
            fqname = CompositeName(namespace, field, item_name)
            err = not is_known_wiki(wiki_name)
            href = url_for_item(wiki_name=wiki_name, **fqname.split)
            if is_local_wiki(wiki_name):
                exists = bool(self.storage.get_item(**fqname.query))
                wiki_name = ""  # means "this wiki" for the theme code
            else:
                exists = True  # we can't detect existance of remote items
            if item_name:
                breadcrumbs.append((wiki_name, fqname, href, exists, err))
        return breadcrumbs
示例#9
0
    def path_breadcrumbs(self):
        """
        Assemble the path breadcrumbs (a.k.a.: trail)

        :rtype: list
        :returns: path breadcrumbs items in tuple (wiki_name, item_name, url, exists, err)
        """
        user = self.user
        breadcrumbs = []
        trail = user.get_trail()
        for interwiki_item_name in trail:
            wiki_name, namespace, field, item_name = split_interwiki(interwiki_item_name)
            fqname = CompositeName(namespace, field, item_name)
            err = not is_known_wiki(wiki_name)
            href = url_for_item(wiki_name=wiki_name, **fqname.split)
            if is_local_wiki(wiki_name):
                exists = bool(self.storage.get_item(**fqname.query))
                wiki_name = ''  # means "this wiki" for the theme code
            else:
                exists = True  # we can't detect existance of remote items
            if item_name:
                breadcrumbs.append((wiki_name, fqname, href, exists, err))
        return breadcrumbs
示例#10
0
    def inline_freelink_repl(self, stack, freelink, freelink_bang=None,
                             freelink_interwiki_page=None, freelink_interwiki_ref=None,
                             freelink_page=None, freelink_email=None):
        if freelink_bang:
            stack.top_append(freelink)
            return

        attrib = {}

        if freelink_page:
            page = freelink_page.encode('utf-8')
            if '#' in page:
                path, fragment = page.rsplit('#', 1)
            else:
                path, fragment = page, None
            link = Iri(scheme='wiki.local', path=path, fragment=fragment)
            text = freelink_page

        elif freelink_email:
            link = 'mailto:' + freelink_email
            text = freelink_email

        else:
            if not is_known_wiki(freelink_interwiki_ref):
                stack.top_append(freelink)
                return

            link = Iri(scheme='wiki',
                       authority=freelink_interwiki_ref,
                       path='/' + freelink_interwiki_page)
            text = freelink_interwiki_page

        attrib[xlink.href] = link

        element = moin_page.a(attrib, children=[text])
        stack.top_append(element)