changeset 4495:fecec62aa2a7

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 18 Jan 2009 12:54:54 +0100
parents af211e2f132c (diff) 8f8ba97409da (current diff)
children c76d50dac855
files
diffstat 6 files changed, 41 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/__init__.py	Fri Jan 16 13:44:33 2009 +0100
+++ b/MoinMoin/formatter/__init__.py	Sun Jan 18 12:54:54 2009 +0100
@@ -14,7 +14,6 @@
 
 from MoinMoin.util import pysupport
 from MoinMoin import wikiutil
-from MoinMoin.support.python_compatibility import rsplit
 
 modules = pysupport.getPackageModules(__file__)
 
@@ -106,9 +105,6 @@
         """
         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename)
         if wikitag == 'Self' or wikitag == self.request.cfg.interwikiname:
-            if '#' in wikitail:
-                wikitail, kw['anchor'] = rsplit(wikitail, '#', 1)
-                wikitail = wikiutil.url_unquote(wikitail)
             return self.pagelink(on, wikitail, **kw)
         return ''
 
--- a/MoinMoin/formatter/text_html.py	Fri Jan 16 13:44:33 2009 +0100
+++ b/MoinMoin/formatter/text_html.py	Sun Jan 18 12:54:54 2009 +0100
@@ -14,7 +14,7 @@
 from MoinMoin import wikiutil, i18n
 from MoinMoin.Page import Page
 from MoinMoin.action import AttachFile
-from MoinMoin.support.python_compatibility import set, rsplit
+from MoinMoin.support.python_compatibility import set
 
 # insert IDs into output wherever they occur
 # warning: breaks toggle line numbers javascript
@@ -488,8 +488,6 @@
         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename)
         wikiurl = wikiutil.mapURL(self.request, wikiurl)
         if wikitag == 'Self': # for own wiki, do simple links
-            if '#' in wikitail:
-                wikitail, kw['anchor'] = rsplit(wikitail, '#', 1)
             wikitail = wikiutil.url_unquote(wikitail)
             try: # XXX this is the only place where we access self.page - do we need it? Crashes silently on actions!
                 pagename = wikiutil.AbsPageName(self.page.page_name, wikitail)
@@ -502,6 +500,9 @@
                 if querystr:
                     separator = ('?', '&')['?' in href]
                     href = '%s%s%s' % (href, separator, wikiutil.makeQueryString(querystr))
+                anchor = kw.get('anchor')
+                if anchor:
+                    href = '%s#%s' % (href, anchor)
                 if wikitag_bad:
                     html_class = 'badinterwiki'
                 else:
--- a/MoinMoin/parser/text_creole.py	Fri Jan 16 13:44:33 2009 +0100
+++ b/MoinMoin/parser/text_creole.py	Sun Jan 18 12:54:54 2009 +0100
@@ -25,7 +25,6 @@
 import StringIO
 from MoinMoin import config, wikiutil
 from MoinMoin.macro import Macro
-from MoinMoin.support.python_compatibility import rsplit # Needed for python 2.3
 from _creole import Parser as CreoleParser
 
 Dependencies = []
@@ -273,11 +272,7 @@
                 elif word.startswith(wikiutil.CHILD_PREFIX):
                     word = "%s/%s" % (self.formatter.page.page_name,
                         word[wikiutil.CHILD_PREFIX_LEN:])
-                # handle anchors
-                parts = rsplit(word, "#", 1)
-                anchor = ""
-                if len(parts) == 2:
-                    word, anchor = parts
+                word, anchor = wikiutil.split_anchor(word)
                 return ''.join([
                     self.formatter.pagelink(1, word, anchor=anchor),
                     self.emit_children(node) or self.formatter.text(target),
@@ -296,8 +291,9 @@
                 # interwiki link
                 wiki = m.group('inter_wiki')
                 page = m.group('inter_page')
+                page, anchor = wikiutil.split_anchor(page)
                 return ''.join([
-                    self.formatter.interwikilink(1, wiki, page),
+                    self.formatter.interwikilink(1, wiki, page, anchor=anchor),
                     self.emit_children(node) or self.formatter.text(page),
                     self.formatter.interwikilink(0),
                 ])
--- a/MoinMoin/parser/text_moin_wiki.py	Fri Jan 16 13:44:33 2009 +0100
+++ b/MoinMoin/parser/text_moin_wiki.py	Sun Jan 18 12:54:54 2009 +0100
@@ -15,7 +15,7 @@
 
 from MoinMoin import config, wikiutil, macro
 from MoinMoin.Page import Page
-from MoinMoin.support.python_compatibility import rsplit, set
+from MoinMoin.support.python_compatibility import set
 
 Dependencies = ['user'] # {{{#!wiki comment ... }}} has different output depending on the user's profile settings
 
@@ -600,7 +600,8 @@
             text = groups.get('interwiki')
             return self.formatter.text(text)
         else:
-            return (self.formatter.interwikilink(1, wiki, page) +
+            page, anchor = wikiutil.split_anchor(page)
+            return (self.formatter.interwikilink(1, wiki, page, anchor=anchor) +
                     self.formatter.text(page) +
                     self.formatter.interwikilink(0, wiki, page))
     _interwiki_wiki_repl = _interwiki_repl
@@ -623,11 +624,7 @@
         if abs_name == current_page:
             return self.formatter.text(word)
         else:
-            # handle anchors
-            try:
-                abs_name, anchor = rsplit(abs_name, "#", 1)
-            except ValueError:
-                anchor = ""
+            abs_name, anchor = wikiutil.split_anchor(abs_name)
             return (bang +
                     self.formatter.pagelink(1, abs_name, anchor=anchor) +
                     self.formatter.text(word) +
@@ -864,11 +861,7 @@
                 else:
                     err = True
                 if err: # not a interwiki link / not in interwiki map
-                    # handle anchors
-                    try:
-                        page_name, anchor = rsplit(page_name_and_anchor, "#", 1)
-                    except ValueError:
-                        page_name, anchor = page_name_and_anchor, ""
+                    page_name, anchor = wikiutil.split_anchor(page_name_and_anchor)
                     current_page = self.formatter.page.page_name
                     if not page_name:
                         page_name = current_page
@@ -881,10 +874,11 @@
                             self._link_description(desc, target, page_name_and_anchor) +
                             self.formatter.pagelink(0, abs_page_name))
                 else: # interwiki link
+                    page_name, anchor = wikiutil.split_anchor(page_name)
                     tag_attrs, query_args = self._get_params(params,
                                                              tag_attrs={},
                                                              acceptable_attrs=acceptable_attrs)
-                    return (self.formatter.interwikilink(1, wiki_name, page_name, querystr=query_args, **tag_attrs) +
+                    return (self.formatter.interwikilink(1, wiki_name, page_name, anchor=anchor, querystr=query_args, **tag_attrs) +
                             self._link_description(desc, target, page_name) +
                             self.formatter.interwikilink(0, wiki_name, page_name))
 
--- a/MoinMoin/parser/text_rst.py	Fri Jan 16 13:44:33 2009 +0100
+++ b/MoinMoin/parser/text_rst.py	Sun Jan 18 12:54:54 2009 +0100
@@ -20,7 +20,6 @@
 from MoinMoin.Page import Page
 from MoinMoin.action import AttachFile
 from MoinMoin import wikiutil
-from MoinMoin.support.python_compatibility import rsplit
 
 Dependencies = [] # this parser just depends on the raw text
 
@@ -400,10 +399,7 @@
                     node['classes'].append(prefix)
             else:
                 # Default case - make a link to a wiki page.
-                pagename = refuri
-                anchor = ''
-                if '#' in refuri:
-                    pagename, anchor = rsplit(refuri, '#', 1)
+                pagename, anchor = wikiutil.split_anchor(refuri)
                 page = Page(self.request, wikiutil.AbsPageName(self.formatter.page.page_name, pagename))
                 node['refuri'] = page.url(self.request, anchor=anchor)
                 if not page.exists():
--- a/MoinMoin/wikiutil.py	Fri Jan 16 13:44:33 2009 +0100
+++ b/MoinMoin/wikiutil.py	Sun Jan 18 12:54:54 2009 +0100
@@ -22,6 +22,7 @@
 
 from MoinMoin import config
 from MoinMoin.util import pysupport, lock
+from MoinMoin.support.python_compatibility import rsplit
 from inspect import getargspec, isfunction, isclass, ismethod
 
 
@@ -2425,6 +2426,31 @@
         return 'A%s' % res
     return res
 
+def split_anchor(pagename):
+    """
+    Split a pagename that (optionally) has an anchor into the real pagename
+    and the anchor part. If there is no anchor, it returns an empty string
+    for the anchor.
+
+    Note: if pagename contains a # (as part of the pagename, not as anchor),
+          you can use a trick to make it work nevertheless: just append a
+          # at the end:
+          "C##" returns ("C#", "")
+          "Problem #1#" returns ("Problem #1", "")
+
+    TODO: We shouldn't deal with composite pagename#anchor strings, but keep
+          it separate.
+          Current approach: [[pagename#anchor|label|attr=val,&qarg=qval]]
+          Future approach:  [[pagename|label|attr=val,&qarg=qval,#anchor]]
+          The future approach will avoid problems when there is a # in the
+          pagename part (and no anchor). Also, we need to append #anchor
+          at the END of the generated URL (AFTER the query string).
+    """
+    parts = rsplit(pagename, '#', 1)
+    if len(parts) == 2:
+        return parts
+    else:
+        return pagename, ""
 
 ########################################################################
 ### Tickets - used by RenamePage and DeletePage