changeset 450:ad338b37458c

move some interwiki related code from MoinMoin.user to MoinMoin.util.interwiki
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 21 Aug 2011 18:53:46 +0200
parents dfa71b20022c
children 0e1c8662871f 737903cbe58e f06e9d502d6c
files MoinMoin/user.py MoinMoin/util/interwiki.py
diffstat 2 files changed, 21 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/user.py	Sat Aug 20 13:00:55 2011 +0200
+++ b/MoinMoin/user.py	Sun Aug 21 18:53:46 2011 +0200
@@ -30,7 +30,7 @@
 
 from MoinMoin import config, wikiutil
 from MoinMoin.i18n import _, L_, N_
-from MoinMoin.util.interwiki import getInterwikiHome, is_local_wiki
+from MoinMoin.util.interwiki import getInterwikiHome, getInterwikiName, is_local_wiki
 from MoinMoin.util.crypto import crypt_password, upgrade_password, valid_password, \
                                  generate_token, valid_token
 
@@ -520,7 +520,7 @@
         # Create a new list with both names and interwiki names.
         pages = pagelist[:]
         if self._cfg.interwikiname:
-            pages += [self._interWikiName(pagename) for pagename in pagelist]
+            pages += [getInterwikiName(pagename) for pagename in pagelist]
         # Create text for regular expression search
         text = '\n'.join(pages)
 
@@ -550,7 +550,7 @@
         :returns: if page was subscribed
         """
         if self._cfg.interwikiname:
-            pagename = self._interWikiName(pagename)
+            pagename = getInterwikiName(pagename)
 
         if pagename not in self.subscribed_items:
             self.subscribed_items.append(pagename)
@@ -585,7 +585,7 @@
             self.subscribed_items.remove(pagename)
             changed = True
 
-        interWikiName = self._interWikiName(pagename)
+        interWikiName = getInterwikiName(pagename)
         if interWikiName and interWikiName in self.subscribed_items:
             self.subscribed_items.remove(interWikiName)
             changed = True
@@ -618,7 +618,7 @@
         for pagename in pagelist:
             if pagename in self.quicklinks:
                 return True
-            interWikiName = self._interWikiName(pagename)
+            interWikiName = getInterwikiName(pagename)
             if interWikiName and interWikiName in self.quicklinks:
                 return True
 
@@ -636,7 +636,7 @@
         :returns: if pagename was added
         """
         changed = False
-        interWikiName = self._interWikiName(pagename)
+        interWikiName = getInterwikiName(pagename)
         if interWikiName:
             if pagename in self.quicklinks:
                 self.quicklinks.remove(pagename)
@@ -664,7 +664,7 @@
         :returns: if pagename was removed
         """
         changed = False
-        interWikiName = self._interWikiName(pagename)
+        interWikiName = getInterwikiName(pagename)
         if interWikiName and interWikiName in self.quicklinks:
             self.quicklinks.remove(interWikiName)
             changed = True
@@ -676,17 +676,6 @@
             self.save()
         return changed
 
-    def _interWikiName(self, pagename):
-        """ Return the inter wiki name of a page name
-
-        :param pagename: page name
-        :type pagename: unicode
-        """
-        if not self._cfg.interwikiname:
-            return None
-
-        return "%s:%s" % (self._cfg.interwikiname, pagename)
-
     # -----------------------------------------------------------------
     # Trail
 
@@ -697,7 +686,7 @@
         """
         # Save interwiki links internally
         if self._cfg.interwikiname:
-            item_name = self._interWikiName(item_name)
+            item_name = getInterwikiName(item_name)
         trail_in_session = session.get('trail', [])
         trail = trail_in_session[:]
         trail = [i for i in trail if i != item_name] # avoid dupes
--- a/MoinMoin/util/interwiki.py	Sat Aug 20 13:00:55 2011 +0200
+++ b/MoinMoin/util/interwiki.py	Sun Aug 21 18:53:46 2011 +0200
@@ -122,6 +122,19 @@
         return wikiurl + wikitail
 
 
+def getInterwikiName(self, item_name):
+    """
+    Get the (fully qualified) interwiki name of a local item name.
+
+    :param item_ame: item name (unicode)
+    :rtype: unicode
+    :returns: wiki_name:item_name
+    """
+    wiki_name = app.cfg.interwikiname
+    if wiki_name:
+        return "%s:%s" % (wiki_name, item_name)
+
+
 def getInterwikiHome(username):
     """
     Get a user's homepage.