changeset 2740:63ae36c70930

1.6 converter: less magic, better tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 21 Aug 2007 14:11:31 +0200
parents 9fd4a16a08cc
children 3aae97249905
files MoinMoin/script/migration/_conv160_wiki.py MoinMoin/script/migration/_tests/test_conv160_wiki.py
diffstat 2 files changed, 20 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/_conv160_wiki.py	Tue Aug 21 13:32:39 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Tue Aug 21 14:11:31 2007 +0200
@@ -235,11 +235,6 @@
         # check for image URL, and possibly return IMG tag
         # (images are always inlined, just like for other URLs)
         if wikiutil.isPicture(name):
-            if not text:
-                text = name.split('/')[-1]
-                text = ''.join(text.split('.')[:-1])
-                text = wikiutil.url_unquote(text) # maybe someone has used %20 for blanks
-                text = '|' + text
             return "{{attachment:%s%s}}" % (name, text)
 
         # inline the attachment
@@ -258,10 +253,7 @@
             return '%s' % self.attachment([word])
 
         if wikiutil.isPicture(word): # magic will go away in 1.6!
-            name = word.split('/')[-1]
-            name = ''.join(name.split('.')[:-1])
-            name = wikiutil.url_unquote(name) # maybe someone has used %20 for blanks
-            return '{{%s|%s}}' % (word, name) # new markup for inline images
+            return '{{%s}}' % word # new markup for inline images
         else:
             return word
 
@@ -306,7 +298,11 @@
             #        text = '|' + text
             #    return "[[%s:%s%s]]" % (wikiname, pagename, text)
         if scheme in self.attachment_schemas:
-            return '%s' % self.attachment(words)
+            m = self.attachment(words)
+            if m.startswith('{{') and m.endswith('}}'):
+                # with url_bracket markup, 1.5.8 parser does not embed, but link!
+                m = '[[%s]]' % m[2:-2]
+            return m
 
         target, desc = (words + ['', ''])[:2]
         if wikiutil.isPicture(desc) and re.match(self.url_rule, desc):
--- a/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Tue Aug 21 13:32:39 2007 +0200
+++ b/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Tue Aug 21 14:11:31 2007 +0200
@@ -40,10 +40,14 @@
             # FAILING tests:
             #('[wiki:/OtherPage]', rename_some_page, '[[/OtherPage]]'),
             #('[wiki:/OtherPage other page]', rename_some_page, '[wiki:/OtherPage other page]'),
-            #('[attachment:My%20Attachment.jpg:it works]', {}, '[[attachment:My Attachment.jpg|it works]]'),
             #('[wiki:LinuxWiki: LinuxWiki.de]', {}, '[wiki:LinuxWiki: LinuxWiki.de]'),
+
+            # does not work in 1.5.8, no need to convert:
             #('[:MeatBall:CleanLinking meatball-wiki: clean linking]', {}, '[:MeatBall:CleanLinking meatball-wiki: clean linking]'),
 
+            # does not work in 1.5.8, no need to convert:
+            #('[attachment:some_page.txt attachment:some_page.png]', rename_some_page, '[[attachment:some_page.txt|{{attachment:some_page.png}}]]'),
+
             # ambiguity!!! can be resolved with some interwiki map lookup
             # and transformed to wiki:MoinMoin:FrontPage if MoinMoin is in
             # interwiki map, but no page MoinMoin exists.
@@ -64,9 +68,12 @@
             ('http://some_server/some_page', rename_some_page, 'http://some_server/some_page'), # external link
             ('[http://some_server/some_page]', rename_some_page, '[[http://some_server/some_page]]'), # external link
             ('[#some_page]', rename_some_page, '[[#some_page]]'), # link to anchor that has same name
-            ('[attachment:some_page.png]', rename_some_page, '{{attachment:some_page.png|some_page}}'), # att, not page
-            ('[attachment:some_page.png test picture]', rename_some_page, '{{attachment:some_page.png|test picture}}'), # att, not page
-            #('[attachment:some_page.txt attachment:some_page.png]', rename_some_page, '[[attachment:some_page.txt|{{attachment:some_page.png}}]]'),
+            ('[attachment:some_page.png]', rename_some_page, '[[attachment:some_page.png]]'), # att, not page
+            ('[attachment:some_page.png test picture]', rename_some_page, '[[attachment:some_page.png|test picture]]'), # att, not page
+            # url unquote stuff (%20 was popular for space)
+            ('attachment:My%20Attachment.jpg', {}, '{{attachment:My Attachment.jpg}}'), # embed!
+            ('[attachment:My%20Attachment.jpg]', {}, '[[attachment:My Attachment.jpg]]'), # link!
+            ('[attachment:My%20Attachment.jpg it works]', {}, '[[attachment:My Attachment.jpg|it works]]'),
 
             # page rename changes result
             ('["some_page"]', rename_some_page, '[[some page]]'),
@@ -100,9 +107,9 @@
             ('attachment:OtherPage/keep%20blank', rename_some_file, '[[attachment:OtherPage/keep blank]]'),
 
             # embed images
-            ('http://server/image.png', {}, '{{http://server/image.png|image}}'),
-            ('attachment:image.gif', {}, '{{attachment:image.gif|image}}'),
-            ('inline:image.jpg', {}, '{{attachment:image.jpg|image}}'), # inline is now implied by {{...}}
+            ('http://server/image.png', {}, '{{http://server/image.png}}'),
+            ('attachment:image.gif', {}, '{{attachment:image.gif}}'),
+            ('inline:image.jpg', {}, '{{attachment:image.jpg}}'), # inline is now implied by {{...}}
             ('drawing:image', {}, '{{drawing:image}}'),
 
             # macros