diff MoinMoin/themes/__init__.py @ 313:8fa4a76d71ff

cleanup interwiki code, new easier/more powerful functions removed crappy resolve_interwiki added is_known_wiki(wiki_name) - check if <wiki_name> is in the interwiki_map added is_local_wiki(wiki_name) - check if <wiki_name> is THIS wiki new powerful url_for_item(...) function, that is somehow similar to url_for, but also includes computing interwiki URLs. It either can compute standard interwiki URLs (for default item views of any remote wiki) or special interwiki URLs (for specific revs/endpoints for remote moin wikis, like in a farm). link converter refactored so it uses url_for_item()
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 05 Aug 2011 13:18:23 +0200
parents 1a1dab306214
children 4ee796d759bf
line wrap: on
line diff
--- a/MoinMoin/themes/__init__.py	Fri Aug 05 12:04:00 2011 +0200
+++ b/MoinMoin/themes/__init__.py	Fri Aug 05 13:18:23 2011 +0200
@@ -21,7 +21,7 @@
 from MoinMoin.i18n import _, L_, N_
 from MoinMoin import wikiutil, user
 from MoinMoin.config import USERID, ADDRESS, HOSTNAME
-from MoinMoin.util.interwiki import split_interwiki, resolve_interwiki, join_wiki, getInterwikiHome
+from MoinMoin.util.interwiki import split_interwiki, getInterwikiHome, is_local_wiki, is_known_wiki, url_for_item
 from MoinMoin.util.crypto import cache_key
 from MoinMoin.util.forms import make_generator
 
@@ -103,9 +103,9 @@
         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', ]:
+            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:
@@ -129,13 +129,12 @@
         wikiname, itemname = getInterwikiHome(name)
         title = "%s @ %s" % (aliasname, wikiname)
         # link to (interwiki) user homepage
-        if wikiname == "Self":
+        if is_local_wiki(wikiname):
             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)
+        wiki_href = url_for_item(itemname, wiki_name=wikiname)
         return wiki_href, aliasname, title, exists
 
     def split_navilink(self, text):
@@ -183,9 +182,8 @@
 
         # 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', ]:
+        href = url_for_item(item_name, wiki_name=wiki_name)
+        if not is_local_wiki(wiki_name):
             if not title:
                 title = item_name
             return href, title, wiki_name
@@ -219,7 +217,7 @@
 
         # Add sister pages (see http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide )
         for sistername, sisterurl in self.cfg.sistersites:
-            if sistername == self.cfg.interwikiname:  # it is THIS wiki
+            if is_local_wiki(sistername):
                 items.append(('sisterwiki current', sisterurl, sistername))
             else:
                 cid = cache_key(usage="SisterSites", sistername=sistername)
@@ -318,14 +316,11 @@
             css = 'editor mail'
         else:
             homewiki = app.cfg.user_homewiki
-            if homewiki in ('Self', app.cfg.interwikiname):
-                homewiki = u'Self'
+            if is_local_wiki(homewiki):
                 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)
+            uri = url_for_item(name, wiki_name=homewiki, _external=external)
 
     result = dict(name=name, text=text, css=css, title=title)
     if uri: