changeset 2603:c61c10e3fcde

1.6 converter: improve content conversion, more tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 05 Aug 2007 00:05:34 +0200
parents b601db2e4d34
children 27f06531a91b
files MoinMoin/script/migration/_conv160_wiki.py MoinMoin/script/migration/_tests/test_conv160_wiki.py
diffstat 2 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/_conv160_wiki.py	Sat Aug 04 21:28:22 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Sun Aug 05 00:05:34 2007 +0200
@@ -78,7 +78,6 @@
     _heading_repl = return_word
     _email_repl = return_word
     _macro_repl = return_word
-    _interwiki_repl = return_word
     _word_repl = return_word
     _indent_repl = return_word
     _li_none_repl = return_word
@@ -125,12 +124,14 @@
         # TODO: maybe support [wiki:Page http://wherever/image.png] ?
         scheme, rest = target_and_text.split(':', 1)
         wikiname, pagename, text = wikiutil.split_wiki(rest)
-        if not text:
-            text = pagename
         #self.request.log("interwiki: split_wiki -> %s.%s.%s" % (wikiname,pagename,text))
 
         if wikiname.lower() == 'self': # [wiki:Self:LocalPage text] or [:LocalPage:text]
-            return '[%s %s]' % (wikiutil.quoteName(pagename), text) # ["LocalPage" text]
+            pagename = self._replace(('PAGE', pagename))
+            if not text:
+                return '[%s]' % wikiutil.quoteName(pagename) # ["LocalPage"]
+            else:
+                return '[%s %s]' % (wikiutil.quoteName(pagename), text) # ["LocalPage" text]
 
         # check for image URL, and possibly return IMG tag
         if not kw.get('pretty_url', 0) and wikiutil.isPicture(pagename):
@@ -166,12 +167,17 @@
             text = ' ' + text
         return "%s:%s%s" % (scheme, qname, text)
 
+    def _interwiki_repl(self, word):
+        """Handle InterWiki links."""
+        # XXX if we have access to the cfg, we can limit this to really existings interwiki identifiers
+        return self.interwiki("wiki:" + word)
+
     def _url_repl(self, word):
         """Handle literal URLs including inline images."""
         scheme = word.split(":", 1)[0]
 
         if scheme == "wiki":
-            return word # self.interwiki(word)
+            return self.interwiki(word)
 
         if scheme in self.attachment_schemas:
             return self.attachment(word)
@@ -225,8 +231,22 @@
                     text = ' ' + text
                 return '[%s%s]' % (link, text) # use freelink with text
 
-        return '[%s]' % word
+        scheme_and_rest = word.split(":", 1)
+        if len(scheme_and_rest) == 2: # scheme given
+            scheme, rest = scheme_and_rest
+            if scheme == "wiki":
+                return self.interwiki(word, pretty_url=1)
+            if scheme in self.attachment_schemas:
+                return self.attachment(word, pretty_url=1)
 
+        words = word.split(None, 1)
+        if len(words) == 1:
+            link, text = words[0], ''
+        else:
+            link, text = words
+        if text:
+            text = ' ' + text
+        return '[%s%s]' % (link, text)
 
     # SCANNING ---------------------------------------------------------------
     def scan(self, scan_re, line):
--- a/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Sat Aug 04 21:28:22 2007 +0200
+++ b/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Sun Aug 05 00:05:34 2007 +0200
@@ -24,15 +24,22 @@
         ('some_text', {}, 'some_text'),
         ('["some_text"]', {}, '["some_text"]'),
         ('some_page', rename_some_page, 'some_page'), # not a link
+
         # page rename changes result
         ('["some_page"]', rename_some_page, '["some page"]'),
         ('[:some_page]', rename_some_page, '["some page"]'),
         ('[:some_page:]', rename_some_page, '["some page"]'),
         ('[:some_page:some text]', rename_some_page, '["some page" some text]'),
+        ('Self:some_page', rename_some_page, '["some page"]'),
+        ('wiki:Self:some_page', rename_some_page, '["some page"]'),
+        ('[wiki:Self:some_page]', rename_some_page, '["some page"]'),
+        ('[wiki:Self:some_page some text]', rename_some_page, '["some page" some text]'),
+
         # other markup changes we do
         ('[:other page]', {}, '["other page"]'),
         ('[:other page:]', {}, '["other page"]'),
         ('[:other page:other text]', {}, '["other page" other text]'),
+        # FAILS ('Self:CamelCase', {}, 'CamelCase'),
 
         # "nothing changed" checks
         ('attachment:OtherPage/with_underscore', rename_some_file, 'attachment:OtherPage/with_underscore'),