changeset 2728:59b3d8b8971f

remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 13 Aug 2007 03:04:22 +0200
parents cc9590a900c2
children 012d5ec31f92
files MoinMoin/_tests/test_wikiutil.py MoinMoin/action/AttachFile.py MoinMoin/action/MyPages.py MoinMoin/auth/interwiki.py MoinMoin/converter/text_html_text_moin_wiki.py MoinMoin/formatter/__init__.py MoinMoin/formatter/text_docbook.py MoinMoin/formatter/text_html.py MoinMoin/macro/ImageLink.py MoinMoin/mail/mailimport.py MoinMoin/parser/text_creole.py MoinMoin/parser/text_moin_wiki.py MoinMoin/parser/text_rst.py MoinMoin/request/__init__.py MoinMoin/script/migration/_conv160_wiki.py MoinMoin/theme/__init__.py MoinMoin/wikisync.py MoinMoin/wikiutil.py
diffstat 18 files changed, 85 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Mon Aug 13 03:04:22 2007 +0200
@@ -66,21 +66,6 @@
             assert wikiutil.clean_input(instr) == outstr
 
 
-class TestNameQuoting:
-    tests = [(u"", u'""'), # empty
-             (u"test", u'"test"'), # nothing special
-             (u"Sarah O'Connor", u"\"Sarah O'Connor\""),
-             (u'Just "something" quoted', u'"Just ""something"" quoted"'),
-            ]
-    def testQuoteName(self):
-        for name, qname in self.tests:
-            assert wikiutil.quoteName(name) == qname
-
-    def testUnquoteName(self):
-        for name, qname in self.tests:
-            assert wikiutil.unquoteName(qname) == name
-
-
 class TestInterWiki:
     def testSplitWiki(self):
         tests = [('SomePage', ('Self', 'SomePage', '')),
--- a/MoinMoin/action/AttachFile.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/action/AttachFile.py	Mon Aug 13 03:04:22 2007 +0200
@@ -315,9 +315,7 @@
 
             base, ext = os.path.splitext(file)
             get_url = getAttachUrl(pagename, file, request, escaped=1)
-            qfname = wikiutil.escape(file)
-            if ' ' in qfname:
-                qfname = wikiutil.quoteName(qfname)
+            escaped_fname = wikiutil.escape(file)
             parmdict = {'baseurl': baseurl, 'urlpagename': urlpagename, 'action': action,
                         'urlfile': urlfile, 'label_del': label_del,
                         'label_move': label_move,
@@ -326,7 +324,7 @@
                         'label_unzip': label_unzip,
                         'label_install': label_install,
                         'get_url': get_url, 'label_get': label_get,
-                        'file': qfname,
+                        'file': escaped_fname,
                         'fsize': fsize,
                         'fmtime': fmtime,
                         'pagename': pagename}
@@ -359,7 +357,7 @@
             parmdict['move_link'] = move_link
             html += ('<li>[%(del_link)s%(move_link)s'
                 '<a href="%(get_url)s">%(label_get)s</a>&nbsp;| %(viewlink)s]'
-                ' (%(fmtime)s, %(fsize)s KB) attachment:%(file)s</li>') % parmdict
+                ' (%(fmtime)s, %(fsize)s KB) [[attachment:%(file)s]]</li>') % parmdict
         html += "</ul>"
     else:
         if showheader:
--- a/MoinMoin/action/MyPages.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/action/MyPages.py	Mon Aug 13 03:04:22 2007 +0200
@@ -24,7 +24,7 @@
     userhomewiki = request.cfg.user_homewiki
     if userhomewiki != 'Self' and userhomewiki != request.cfg.interwikiname:
         interwiki = wikiutil.getInterwikiHomePage(request, username=username)
-        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(request, '%s:"%s"' % interwiki)
+        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(request, *interwiki)
         wikiurl = wikiutil.mapURL(request, wikiurl)
         homepageurl = wikiutil.join_wiki(wikiurl, wikitail)
         request.http_redirect('%s?action=MyPages' % homepageurl)
--- a/MoinMoin/auth/interwiki.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/auth/interwiki.py	Mon Aug 13 03:04:22 2007 +0200
@@ -30,8 +30,8 @@
             return ContinueLogin(user_obj)
 
         if verbose: request.log("interwiki auth: trying to auth %r" % username)
-        username = username.replace(' ', ':', 1) # XXX Hack because ':' is not allowed in name field
-        wikitag, wikiurl, name, err = wikiutil.resolve_wiki(request, username)
+        wikiname, username = username.split(' ', 1) # XXX Hack because ':' is not allowed in name field
+        wikitag, wikiurl, name, err = wikiutil.resolve_interwiki(request, wikiname, username)
 
         if verbose: request.log("interwiki auth: resolve wiki returned: %r %r %r %r" % (wikitag, wikiurl, name, err))
         if err or wikitag not in self.trusted_wikis:
--- a/MoinMoin/converter/text_html_text_moin_wiki.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/converter/text_html_text_moin_wiki.py	Mon Aug 13 03:04:22 2007 +0200
@@ -1101,8 +1101,8 @@
 
             # interwiki link
             if class_ == "interwiki":
-                wikitag, wikiurl, wikitail, err = wikiutil.resolve_wiki(
-                    self.request, title + ":")
+                wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(
+                    self.request, title, "")
                 if not err and href.startswith(wikiurl):
                     pagename, qpagename = pagename_from_url(href[len(wikiurl):].lstrip('/'))
                     interwikiname = "%s:%s" % (wikitag, qpagename)
--- a/MoinMoin/formatter/__init__.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/formatter/__init__.py	Mon Aug 13 03:04:22 2007 +0200
@@ -99,7 +99,7 @@
             IMPORTANT: on and off must be called with same parameters, see
                        also the text_html formatter.
         """
-        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:"%s"' % (interwiki, pagename))
+        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'] = wikitail.split('#', 1)
--- a/MoinMoin/formatter/text_docbook.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/formatter/text_docbook.py	Mon Aug 13 03:04:22 2007 +0200
@@ -367,7 +367,7 @@
         if not on:
             return self.url(on, kw)
 
-        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:"%s"' % (interwiki, pagename))
+        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename)
         wikiurl = wikiutil.mapURL(self.request, wikiurl)
         href = wikiutil.join_wiki(wikiurl, wikitail)
 
--- a/MoinMoin/formatter/text_html.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/formatter/text_html.py	Mon Aug 13 03:04:22 2007 +0200
@@ -481,8 +481,7 @@
         """
         @keyword title: override using the interwiki wikiname as title
         """
-        quoted = '%s:%s' % (interwiki, wikiutil.quoteName(pagename))
-        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, quoted)
+        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:
--- a/MoinMoin/macro/ImageLink.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/macro/ImageLink.py	Mon Aug 13 03:04:22 2007 +0200
@@ -216,7 +216,8 @@
         if ":" in target:
             if target.startswith('wiki:'):
                 target = target[5:]
-            wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki(request, target)
+            wikiname, pagename = wikiutil.split_interwiki(target)
+            wikitag, wikiurl, wikitail, error = wikiutil.resolve_interwiki(request, wikiname, pagename)
             url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
             return "%s%s%s" % (formatter.url(1, url),
                                formatter.image(**kw),
--- a/MoinMoin/mail/mailimport.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/mail/mailimport.py	Mon Aug 13 03:04:22 2007 +0200
@@ -253,7 +253,7 @@
                 break
 
     # build an attachment link table for the page with the e-mail
-    attachment_links = [""] + [u'''[attachment:%s %s]''' % (wikiutil.quoteName("%s/%s" % (pagename, att)), att) for att in attachments]
+    attachment_links = [""] + [u'''[[attachment:%s|%s]]''' % ("%s/%s" % (pagename, att), att) for att in attachments]
 
     # assemble old page content and new mail body together
     old_content = Page(request, pagename).get_raw_body()
@@ -299,7 +299,7 @@
         from_col = email_to_markup(request, msg['from_addr'])
         to_col = ' '.join([email_to_markup(request, (realname, mailaddr))
                            for realname, mailaddr in msg['target_addrs'] if not mailaddr in wiki_addrs])
-        subj_col = '[%s %s]' % (wikiutil.quoteName(pagename), msg['subject'])
+        subj_col = '[[%s|%s]]' % (pagename, msg['subject'])
         date_col = msg['date']
         attach_col = " ".join(attachment_links)
         new_line = u'|| <<DateTime(%s)>> || %s || %s || %s || %s ||' % (date_col, from_col, to_col, subj_col, attach_col)
--- a/MoinMoin/parser/text_creole.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/parser/text_creole.py	Mon Aug 13 03:04:22 2007 +0200
@@ -614,9 +614,9 @@
         ])
 
     def interwiki_link_emit(self, node):
-        word = node.content
+        wiki, page = wikiutil.split_interwiki(node.content)
         wikitag, wikiurl, wikitail, wikitag_bad = \
-            wikiutil.resolve_wiki(self.request, word)
+            wikiutil.resolve_interwiki(self.request, wiki, page)
         href = wikiutil.join_wiki(wikiurl, wikitail)
         return ''.join([
             self.formatter.interwikilink(1, wikitag, wikitail),
--- a/MoinMoin/parser/text_moin_wiki.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Mon Aug 13 03:04:22 2007 +0200
@@ -520,7 +520,7 @@
         wiki = groups.get('interwiki_wiki')
         page = groups.get('interwiki_page')
 
-        wikitag_bad = wikiutil.resolve_wiki(self.request, word)[3]
+        wikitag_bad = wikiutil.resolve_interwiki(self.request, wiki, page)[3]
         if wikitag_bad:
             return self.formatter.text(word)
         else:
@@ -692,8 +692,7 @@
             elif m.group('inter_wiki'):
                 wiki_name = m.group('inter_wiki')
                 page_name = m.group('inter_page')
-                word = '%s:%s' % (wiki_name, page_name)
-                wikitag_bad = wikiutil.resolve_wiki(self.request, word)[3]
+                wikitag_bad = wikiutil.resolve_interwiki(self.request, wiki_name, page_name)[3]
                 if not desc:
                     desc = self.formatter.text(page_name)
                 return (self.formatter.interwikilink(1, wiki_name, page_name) +
--- a/MoinMoin/parser/text_rst.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/parser/text_rst.py	Mon Aug 13 03:04:22 2007 +0200
@@ -358,7 +358,8 @@
                 if not [i for i in node.children if i.__class__ == docutils.nodes.image]:
                     node['classes'].append(prefix)
             elif prefix == 'wiki':
-                wikitag, wikiurl, wikitail, err = wikiutil.resolve_wiki(self.request, link)
+                wiki_name, page_name = wikiutil.split_interwiki(link)
+                wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(self.request, wiki_name, page_name)
                 wikiurl = wikiutil.mapURL(self.request, wikiurl)
                 node['refuri'] = wikiutil.join_wiki(wikiurl, wikitail)
                 # Only add additional class information if the reference does
--- a/MoinMoin/request/__init__.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/request/__init__.py	Mon Aug 13 03:04:22 2007 +0200
@@ -1206,11 +1206,13 @@
                 pagetrail = self.user.getTrail()
                 if pagetrail:
                     # Redirect to last page visited
-                    if ":" in pagetrail[-1]:
-                        wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki(self, pagetrail[-1])
+                    last_visited = pagetrail[-1]
+                    wikiname, pagename = wikiutik.split_interwiki(last_visited)
+                    if wikiname != 'Self':
+                        wikitag, wikiurl, wikitail, error = wikiutil.resolve_interwiki(self, wikiname, pagename)
                         url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
                     else:
-                        url = Page(self, pagetrail[-1]).url(self, relative=False)
+                        url = Page(self, pagename).url(self, relative=False)
                 else:
                     # Or to localized FrontPage
                     url = wikiutil.getFrontPage(self).url(self, relative=False)
--- a/MoinMoin/script/migration/_conv160_wiki.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Mon Aug 13 03:04:22 2007 +0200
@@ -120,14 +120,6 @@
         return word
 
     # LINKS ------------------------------------------------------------------
-    def _intelli_quote(self, name):
-        quote_triggers = u''' "'()[]''' # u''' "\'}]|:,.()?!''' # see also wiki parser
-        quote_it = [True for c in quote_triggers if c in name]
-        if quote_it:
-            return wikiutil.quoteName(name)
-        else:
-            return name
-
     def _replace_target(self, target):
         target_and_anchor = target.split('#', 1)
         if len(target_and_anchor) > 1:
@@ -162,7 +154,6 @@
             name = fname
         else:
             name = "%s/%s" % (pagename, fname)
-        name = self._intelli_quote(name)
         if text:
             text = ' ' + text
         return "%s:%s%s" % (scheme, name, text)
@@ -177,7 +168,6 @@
             if wikiname == 'Self':
                 return '["%s"]' % pagename # optimize special case
             else:
-                pagename = self._intelli_quote(pagename)
                 return "%s:%s" % (wikiname, pagename)
 
     def _url_repl(self, word):
@@ -189,7 +179,6 @@
             if wikiname == 'Self':
                 return '["%s"]' % pagename # optimize special case
             else:
-                pagename = self._intelli_quote(pagename)
                 return "%s:%s:%s" % (scheme, wikiname, pagename)
 
         if scheme in self.attachment_schemas:
@@ -213,12 +202,10 @@
             # split on closing quote
             target, linktext = word[1:].split(first_char, 1)
             target = self._replace_target(target)
-            target = wikiutil.quoteName(target)
         else: # not quoted
             # split on whitespace
             target, linktext = word.split(None, 1)
             target = self._replace_target(target)
-            target = self._intelli_quote(target)
         linktext = linktext.strip()
         if linktext:
             linktext = ' ' + linktext
@@ -236,7 +223,6 @@
             if link.strip() == text.strip():
                 text = ''
             link = self._replace_target(link)
-            link = wikiutil.quoteName(link)
             if text:
                 text = ' ' + text
             return '[%s%s]' % (link, text) # use freelink with text
@@ -251,7 +237,6 @@
                         text = ' %s' % text
                     return '["%s"%s]' % (pagename, text)
                 else:
-                    pagename = self._intelli_quote(pagename)
                     if text:
                         text = ' %s' % text
                     return "[%s:%s:%s%s]" % (scheme, wikiname, pagename, text)
--- a/MoinMoin/theme/__init__.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/theme/__init__.py	Mon Aug 13 03:04:22 2007 +0200
@@ -298,7 +298,7 @@
         """ Split navibar links into pagename, link to page
 
         Admin or user might want to use shorter navibar items by using
-        the [page title] or [url title] syntax. In this case, we don't
+        the [[page|title]] or [[url|title]] syntax. In this case, we don't
         use localization, and the links goes to page or to the url, not
         the localized version of page.
 
@@ -307,7 +307,7 @@
             * WikiName:PageName
             * wiki:WikiName:PageName
             * url
-            * all targets as seen above with title: [target title]
+            * all targets as seen above with title: [[target|title]]
 
         @param text: the text used in config or user preferences
         @rtype: tuple
@@ -317,16 +317,17 @@
         fmt = request.formatter
         title = None
 
-        # Handle [pagename title] or [url title] formats
-        if text.startswith('[') and text.endswith(']'):
-            text = text[1:-1].strip()
+        # Handle [[pagename|title]] or [[url|title]] formats
+        if text.startswith('[[') and text.endswith(']]'):
+            text = text[2:-2]
             try:
-                pagename, title = text.split(' ', 1)
-                title = title.lstrip()
+                pagename, title = text.split('|', 1)
+                pagename = pagename.strip()
+                title = title.strip()
                 localize = 0
             except (ValueError, TypeError):
                 # Just use the text as is.
-                pagename = text
+                pagename = text.strip()
         else:
             pagename = text
 
@@ -344,9 +345,9 @@
 
         # try handling interwiki links
         try:
-            interwiki, page = pagename.split(':', 1)
+            interwiki, page = wikiutil.split_interwiki(pagename)
             thiswiki = request.cfg.interwikiname
-            if interwiki == thiswiki:
+            if interwiki == thiswiki or interwiki == 'Self':
                 pagename = page
             else:
                 if not title:
@@ -587,8 +588,8 @@
                 items = []
                 for pagename in trail:
                     try:
-                        interwiki, page = pagename.split(":", 1)
-                        if request.cfg.interwikiname != interwiki:
+                        interwiki, page = wikiutil.split_interwiki(pagename)
+                        if interwiki != request.cfg.interwikiname and interwiki != 'Self':
                             link = (self.request.formatter.interwikilink(True, interwiki, page) +
                                     self.shortenPagename(page) +
                                     self.request.formatter.interwikilink(False, interwiki, page))
--- a/MoinMoin/wikisync.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/wikisync.py	Mon Aug 13 03:04:22 2007 +0200
@@ -166,7 +166,7 @@
         self.verbose = verbose
         _ = self.request.getText
 
-        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:""' % (interwikiname, ))
+        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwikiname, '')
         self.wiki_url = wikiutil.mapURL(self.request, wikiurl)
         self.valid = not wikitag_bad
         self.xmlrpc_url = self.wiki_url + "?action=xmlrpc2"
--- a/MoinMoin/wikiutil.py	Mon Aug 13 01:06:37 2007 +0200
+++ b/MoinMoin/wikiutil.py	Mon Aug 13 03:04:22 2007 +0200
@@ -486,21 +486,9 @@
 
 # Quoting of wiki names, file names, etc. (in the wiki markup) -----------------------------------
 
-# don't ever change this
+# don't ever change this - DEPRECATED, only needed for 1.5 > 1.6 migration conversion
 QUOTE_CHARS = u'"'
 
-def quoteName(name):
-    """ put quotes around a given name """
-    return '"%s"' % name.replace('"', '""')
-
-def unquoteName(name):
-    """ if there are quotes around the name, strip them """
-    if not name:
-        return name
-    if '"' == name[0] == name[-1]:
-        return name[1:-1].replace('""', '"')
-    else:
-        return name
 
 #############################################################################
 ### InterWiki
@@ -600,6 +588,9 @@
 
     'attachment:"filename with blanks.txt" other title' -> "attachment", "filename with blanks.txt", "other title"
 
+    *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION ***
+    Use split_interwiki(), see below.
+
     @param wikiurl: the url to split
     @rtype: tuple
     @return: (wikiname, pagename, linktext)
@@ -638,9 +629,34 @@
     linktext = linktext.strip()
     return wikiname, pagename, linktext
 
+def split_interwiki(wikiurl):
+    """ Split a interwiki name, into wikiname and pagename, e.g:
+
+    'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage"
+    'FrontPage' -> "Self", "FrontPage"
+    'MoinMoin:Page with blanks' -> "MoinMoin", "Page with blanks"
+    'MoinMoin:' -> "MoinMoin", ""
+
+    can also be used for:
+
+    'attachment:filename with blanks.txt' -> "attachment", "filename with blanks.txt"
+
+    @param wikiurl: the url to split
+    @rtype: tuple
+    @return: (wikiname, pagename)
+    """
+    try:
+        wikiname, pagename = wikiurl.split(":", 1)
+    except ValueError:
+        wikiname, pagename = 'Self', wikiurl
+    return wikiname, pagename
+
 def resolve_wiki(request, wikiurl):
     """ Resolve an interwiki link.
 
+    *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION ***
+    Use resolve_interwiki(), see below.
+
     @param request: the request object
     @param wikiurl: the InterWiki:PageName link
     @rtype: tuple
@@ -653,6 +669,21 @@
     else:
         return (wikiname, request.getScriptname(), "/InterWiki", True)
 
+def resolve_interwiki(request, wikiname, pagename):
+    """ Resolve an interwiki reference (wikiname:pagename).
+
+    @param request: the request object
+    @param wikiname: interwiki wiki name
+    @param pagename: interwiki page name
+    @rtype: tuple
+    @return: (wikitag, wikiurl, wikitail, err)
+    """
+    _interwiki_list = load_wikimap(request)
+    if wikiname in _interwiki_list:
+        return (wikiname, _interwiki_list[wikiname], pagename, False)
+    else:
+        return (wikiname, request.getScriptname(), "/InterWiki", True)
+
 def join_wiki(wikiurl, wikitail):
     """
     Add a (url_quoted) page name to an interwiki url.
@@ -851,7 +882,7 @@
     if re.match(Parser.word_rule + "$", pagename):
         return pagename
     else:
-        return u'[[%s]]' % pagename # XXX use quoteName(pagename) later
+        return u'[[%s]]' % pagename
 
 #############################################################################
 ### mimetype support