changeset 22:a47550d21d2d

quicklinks: avoid dupes, dont render as interwiki if wiki == self imported from: moin--main--1.5--patch-23
author Thomas Waldmann <tw@waldmann-edv.de>
date Sat, 24 Sep 2005 14:35:31 +0000
parents 5109effab437
children aee8b13fbb0b
files MoinMoin/theme/__init__.py MoinMoin/user.py
diffstat 2 files changed, 28 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/theme/__init__.py	Sat Sep 24 13:11:37 2005 +0000
+++ b/MoinMoin/theme/__init__.py	Sat Sep 24 14:35:31 2005 +0000
@@ -260,11 +260,15 @@
         # try handling interwiki links
         try:
             interwiki, page = pagename.split(':', 1)
-            return (pagename,
-                    self.request.formatter.interwikilink(True, interwiki, page) +
-                    page +
-                    self.request.formatter.interwikilink(False)
-                    )
+            thiswiki = request.cfg.interwikiname
+            if interwiki == thiswiki:
+                pagename = page
+            else:
+                return (pagename,
+                        self.request.formatter.interwikilink(True, interwiki, page) +
+                        page +
+                        self.request.formatter.interwikilink(False)
+                        )
         
         except ValueError:
             pass
@@ -332,7 +336,7 @@
         # Add user links to wiki links, eliminating duplicates.
         userlinks = request.user.getQuickLinks()
         for text in userlinks:
-            # Split text without localization, user know what she wants
+            # Split text without localization, user knows what he wants
             pagename, link = self.splitNavilink(text, localize=0)
             if not pagename in found:
                 cls = 'userlink'
--- a/MoinMoin/user.py	Sat Sep 24 13:11:37 2005 +0000
+++ b/MoinMoin/user.py	Sat Sep 24 14:35:31 2005 +0000
@@ -668,27 +668,29 @@
         @param remove: unsubscribe pagename if set
         @type remove: bool
         @rtype: bool
-        @return: true, if page was NEWLY quicklinked.
+        @return: True, if quicklinks were added/removed.
         """
+        changed = False
+        if self._cfg.interwikiname:
+            iwpagename = "%s:%s" % (self._cfg.interwikiname, pagename)
+        else:
+            iwpagename = None
         if remove:
             if pagename in self.quicklinks:
                 self.quicklinks.remove(pagename)
-                return 1
-            
-        # check for our own interwiki name
-        if self._cfg.interwikiname:
-            pagename = "%s:%s" % (self._cfg.interwikiname, pagename)
-
-        if remove and (pagename in self.quicklinks):
-            self.quicklinks.remove(pagename)
-            return 1
-    
+                changed = True
+            if iwpagename in self.quicklinks:
+                self.quicklinks.remove(iwpagename)
+                changed = True
         else:
-            # add the interwiki name!
-            if pagename not in self.quicklinks:
-                self.quicklinks.append(pagename)
-                return 1
-        return 0
+            # add the interwiki name and remove non-interwiki name, if present!
+            if pagename in self.quicklinks:
+                self.quicklinks.remove(pagename)
+                changed = True
+            if iwpagename not in self.quicklinks:
+                self.quicklinks.append(iwpagename)
+                changed = True
+        return changed
 
     def subscribePage(self, pagename, remove=False):
         """ Subscribe or unsubscribe to a wiki page.