Commits

Thomas Waldmann committed eea3a94

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.

  • Participants
  • Parent commits 02888ad

Comments (0)

Files changed (6)

File MoinMoin/converter/audio_video_in.py

     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.', ])
 

File MoinMoin/converter/everything.py

     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])
 

File MoinMoin/converter/image_in.py

     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, ])
 

File MoinMoin/converter/link.py

         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:
                 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:
 
         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:
         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)

File MoinMoin/converter/nonexistent_in.py

     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'),
         }

File MoinMoin/items/__init__.py

         return ''
 
     def feed_input_conv(self):
-        return self.name
+        return self.rev
 
     def internal_representation(self, converters=['smiley']):
         """
 
 
 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'))
 
 
 class ApplicationZip(ZipMixin, Application):
-    def feed_input_conv(self):
-        return self.rev
+    """
+    Zip items
+    """
 
 item_registry.register(ApplicationZip._factory, Type('application/zip'))