changeset 257:eea3a94a4061

refactored calling convention of converters, add rev=n qs argument for Iris (fixes #21) Now converters get fed either with the revision (for binary items) or the markup lines (for text items). Converters getting revisions (rev=... in qs) now create links to specific revnos. Cleaned up some code in the link converter and enabled it to create links to specific revisions.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 25 Jun 2011 16:07:50 +0200
parents 02888ad76719
children f6ca659f4a4f
files MoinMoin/converter/audio_video_in.py MoinMoin/converter/everything.py MoinMoin/converter/image_in.py MoinMoin/converter/link.py MoinMoin/converter/nonexistent_in.py MoinMoin/items/__init__.py
diffstat 6 files changed, 38 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/audio_video_in.py	Sat Jun 25 12:18:05 2011 +0200
+++ b/MoinMoin/converter/audio_video_in.py	Sat Jun 25 16:07:50 2011 +0200
@@ -26,11 +26,11 @@
     def __init__(self, input_type):
         self.input_type = input_type
 
-    def __call__(self, content):
-        item_name = content # we just give the name of the item in the content
+    def __call__(self, rev):
+        item_name = rev.item.name
         attrib = {
             moin_page.type_: unicode(self.input_type),
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get'),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%d' % rev.revno),
         }
         return moin_page.object_(attrib=attrib, children=[u'Your Browser does not support HTML5 audio/video element.', ])
 
--- a/MoinMoin/converter/everything.py	Sat Jun 25 12:18:05 2011 +0200
+++ b/MoinMoin/converter/everything.py	Sat Jun 25 16:07:50 2011 +0200
@@ -21,10 +21,10 @@
     def _factory(cls, input, output, **kw):
         return cls()
 
-    def __call__(self, content):
-        item_name = content # we just give the name of the item in the content
+    def __call__(self, rev):
+        item_name = rev.item.name
         attrib = {
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get'),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%d' % rev.revno),
         }
         return moin_page.a(attrib=attrib, children=["Download %s." % item_name])
 
--- a/MoinMoin/converter/image_in.py	Sat Jun 25 12:18:05 2011 +0200
+++ b/MoinMoin/converter/image_in.py	Sat Jun 25 16:07:50 2011 +0200
@@ -24,11 +24,11 @@
     def __init__(self, input_type):
         self.input_type = input_type
 
-    def __call__(self, content):
-        item_name = content # we just give the name of the item in the content
+    def __call__(self, rev):
+        item_name = rev.item.name
         attrib = {
             moin_page.type_: unicode(self.input_type),
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get'),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%d' % rev.revno),
         }
         return moin_page.object_(attrib=attrib, children=[item_name, ])
 
--- a/MoinMoin/converter/link.py	Sat Jun 25 12:18:05 2011 +0200
+++ b/MoinMoin/converter/link.py	Sat Jun 25 16:07:50 2011 +0200
@@ -105,14 +105,15 @@
         if links == 'extern':
             return cls(url_root=url_root)
 
-    def _get_do(self, query):
+    def _get_do_rev(self, query):
         """
-        get 'do' value from query string and remove do=value from querystring
+        get 'do' and 'rev' values from query string and remove them from querystring
 
         Note: we can't use url_decode/url_encode from e.g. werkzeug because
               url_encode quotes the qs values (and Iri code will quote them again)
         """
         do = None
+        revno = None
         separator = '&'
         result = []
         if query:
@@ -126,15 +127,20 @@
                 if k == 'do':
                     do = v
                     continue # we remove do=xxx from qs
+                if k == 'rev':
+                    revno = v
+                    continue # we remove rev=n from qs
                 result.append(u'%s=%s' % (k, v))
         if result:
             query = separator.join(result)
         else:
             query = None
-        return do, query
+        if revno is not None:
+            revno = int(revno)
+        return do, revno, query
 
     def handle_wiki_links(self, elem, input):
-        do, query = self._get_do(input.query)
+        do, revno, query = self._get_do_rev(input.query)
         link = Iri(query=query, fragment=input.fragment)
 
         if input.authority and input.authority.host:
@@ -156,16 +162,18 @@
 
         if not input.authority or err:
             # local wiki link
+            path = input.path[1:]
+            if revno is not None:
+                path = IriPath('%d/' % revno) + path
             if do is not None:
-                link.path = IriPath('+' + do + '/') + input.path[1:]
-            else:
-                link.path = input.path[1:]
+                path = IriPath('+%s/' % do) + path
+            link.path = path
             base = self.url_root
 
         elem.set(self._tag_xlink_href, base + link)
 
     def handle_wikilocal_links(self, elem, input, page):
-        do, query = self._get_do(input.query)
+        do, revno, query = self._get_do_rev(input.query)
         link = Iri(query=query, fragment=input.fragment)
 
         if input.path:
@@ -177,10 +185,11 @@
         else:
             path = page.path[1:]
 
+        if revno is not None:
+            path = IriPath('%d/' % revno) + path
         if do is not None:
-            link.path = IriPath('+' + do + '/') + path
-        else:
-            link.path = path
+            path = IriPath('+%s/') + path
+        link.path = path
         output = self.url_root + link
 
         elem.set(self._tag_xlink_href, output)
--- a/MoinMoin/converter/nonexistent_in.py	Sat Jun 25 12:18:05 2011 +0200
+++ b/MoinMoin/converter/nonexistent_in.py	Sat Jun 25 16:07:50 2011 +0200
@@ -22,8 +22,8 @@
     def _factory(cls, input, output, **kw):
         return cls()
 
-    def __call__(self, content):
-        item_name = content # we just give the name of the item in the content
+    def __call__(self, rev):
+        item_name = rev.item.name
         attrib = {
             xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=modify'),
         }
--- a/MoinMoin/items/__init__.py	Sat Jun 25 12:18:05 2011 +0200
+++ b/MoinMoin/items/__init__.py	Sat Jun 25 16:07:50 2011 +0200
@@ -219,7 +219,7 @@
         return ''
 
     def feed_input_conv(self):
-        return self.name
+        return self.rev
 
     def internal_representation(self, converters=['smiley']):
         """
@@ -859,8 +859,9 @@
 
 
 class ApplicationXTar(TarMixin, Application):
-    def feed_input_conv(self):
-        return self.rev
+    """
+    Tar items
+    """
 
 item_registry.register(ApplicationXTar._factory, Type('application/x-tar'))
 item_registry.register(ApplicationXTar._factory, Type('application/x-gtar'))
@@ -894,8 +895,9 @@
 
 
 class ApplicationZip(ZipMixin, Application):
-    def feed_input_conv(self):
-        return self.rev
+    """
+    Zip items
+    """
 
 item_registry.register(ApplicationZip._factory, Type('application/zip'))