changeset 2524:ce1881bd1b69

Fixes resizing markup for transclusions for moinwiki markup
author sharky93 <rishabhr123@gmail.com>
date Sun, 30 Jun 2013 02:57:05 +0530
parents 03efbc0de719
children 943fb98cd6f9
files MoinMoin/converter/_args_wiki.py MoinMoin/converter/html_out.py MoinMoin/converter/image_in.py MoinMoin/converter/include.py MoinMoin/converter/moinwiki_in.py MoinMoin/items/content.py
diffstat 6 files changed, 43 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/_args_wiki.py	Fri Jun 21 02:27:51 2013 +0530
+++ b/MoinMoin/converter/_args_wiki.py	Sun Jun 30 02:57:05 2013 +0530
@@ -15,7 +15,7 @@
 # see parse() docstring for example
 _parse_rules = r'''
 (?:
-    ([-\w]+)
+    ([-&\w]+)
     =
 )?
 (?:
--- a/MoinMoin/converter/html_out.py	Fri Jun 21 02:27:51 2013 +0530
+++ b/MoinMoin/converter/html_out.py	Sun Jun 30 02:57:05 2013 +0530
@@ -352,6 +352,10 @@
         # TODO: maybe IE8 would display transcluded external pages if we could do <object... type="text/html" ...>
         href = elem.get(xlink.href, None)
         attrib = {}
+        whitelist = ['width', 'height']
+        for key in elem.attrib:
+            if key.name in whitelist:
+                attrib[key] = elem.attrib[key]
         mimetype = Type(_type=elem.get(moin_page.type_, CONTENTTYPE_NONEXISTENT))
         # Get the object type
         obj_type = self.eval_object_type(mimetype, href)
--- a/MoinMoin/converter/image_in.py	Fri Jun 21 02:27:51 2013 +0530
+++ b/MoinMoin/converter/image_in.py	Sun Jun 30 02:57:05 2013 +0530
@@ -11,7 +11,10 @@
 from emeraldtree import ElementTree as ET
 
 from MoinMoin.util.iri import Iri
-from MoinMoin.util.tree import moin_page, xlink
+from MoinMoin.util.tree import moin_page, xlink, xinclude, html
+from werkzeug import url_encode, url_decode
+
+from MoinMoin.constants.contenttypes import CHARSET
 
 
 class Converter(object):
@@ -27,11 +30,21 @@
 
     def __call__(self, rev, contenttype=None, arguments=None):
         item_name = rev.item.name
-        attrib = {
+        query_keys = {'do':'get', 'rev':rev.revid}
+        attrib = {}
+        if arguments:
+            query = arguments.keyword.get(xinclude.href).query
+            query_keys.update(url_decode(query))
+            attrib = arguments.keyword
+
+        query = url_encode(query_keys, charset=CHARSET, encode_keys=True)
+
+        attrib.update({
             moin_page.type_: unicode(self.input_type),
             xlink.href: Iri(scheme='wiki', authority='', path='/' + item_name,
-                            query='do=get&rev={0}'.format(rev.revid)),
-        }
+                            query=query),
+        })
+        
         obj = moin_page.object_(attrib=attrib, children=[item_name, ])
         body = moin_page.body(children=(obj, ))
         return moin_page.page(children=(body, ))
--- a/MoinMoin/converter/include.py	Fri Jun 21 02:27:51 2013 +0530
+++ b/MoinMoin/converter/include.py	Sun Jun 30 02:57:05 2013 +0530
@@ -105,6 +105,8 @@
 
 from MoinMoin.converter.html_out import mark_item_as_transclusion, Attributes
 
+from ._args import Arguments
+
 # elements generated by moin wiki markup that cannot have block children
 NO_BLOCK_CHILDREN = [
     'p',
@@ -337,7 +339,7 @@
                         elem_h = ET.Element(self.tag_h, attrib, children=(elem_a, ))
                         included_elements.append(elem_h)
 
-                    page_doc = page.content.internal_representation()
+                    page_doc = page.content.internal_representation(attributes=Arguments(keyword=elem.attrib))
                     # page_doc.tag = self.tag_div # XXX why did we have this?
 
                     self.recurse(page_doc, page_href)
--- a/MoinMoin/converter/moinwiki_in.py	Fri Jun 21 02:27:51 2013 +0530
+++ b/MoinMoin/converter/moinwiki_in.py	Sun Jun 30 02:57:05 2013 +0530
@@ -21,7 +21,7 @@
 from MoinMoin.constants.contenttypes import CHARSET
 from MoinMoin.constants.misc import URI_SCHEMES
 from MoinMoin.util.iri import Iri
-from MoinMoin.util.tree import moin_page, xlink, xinclude
+from MoinMoin.util.tree import moin_page, xlink, xinclude, html
 from MoinMoin.util.interwiki import is_known_wiki
 from MoinMoin.i18n import _
 
@@ -832,22 +832,34 @@
             args = parse_arguments(object_args).keyword  # XXX needs different parsing
         else:
             args = {}
+            
+        query_keys = {}
+        attrib = {}
+        whitelist = ['width', 'height']
+        for attr, value in args.iteritems():
+            if attr.startswith('&'):
+                query_keys[attr[1:]] = value
+            elif attr in whitelist:
+                attrib[html(attr)] = value
+
         if object_item is not None:
-            query = url_encode(args, charset=CHARSET, encode_keys=True)
+            query = url_encode(query_keys, charset=CHARSET, encode_keys=True)
             att = 'attachment:'  # moin 1.9 needed this for an attached file
             if object_item.startswith(att):
                 object_item = '/' + object_item[len(att):]  # now we have a subitem
             target = Iri(scheme='wiki.local', path=object_item, query=query, fragment=None)
             text = object_item
 
-            attrib = {xinclude.href: target}
+            attrib[xinclude.href] = target
+
             element = xinclude.include(attrib=attrib)
             stack.top_append(element)
         else:
             target = Iri(object_url)
             text = object_url
 
-            attrib = {xlink.href: target}
+            attrib[xlink.href] = target
+
             if object_text is not None:
                 attrib[moin_page.alt] = object_text
 
--- a/MoinMoin/items/content.py	Fri Jun 21 02:27:51 2013 +0530
+++ b/MoinMoin/items/content.py	Sun Jun 30 02:57:05 2013 +0530
@@ -177,7 +177,7 @@
     data = property(fget=get_data)
 
     @timed('conv_in_dom')
-    def internal_representation(self, converters=['smiley']):
+    def internal_representation(self, converters=['smiley'], attributes=None):
         """
         Return the internal representation of a document using a DOM Tree
         """
@@ -203,7 +203,7 @@
 
             # We can process the conversion
             links = Iri(scheme='wiki', authority='', path='/' + self.name)
-            doc = input_conv(self.rev, self.contenttype)
+            doc = input_conv(self.rev, self.contenttype, arguments=attributes)
             # XXX is the following assuming that the top element of the doc tree
             # is a moin_page.page element? if yes, this is the wrong place to do that
             # as not every doc will have that element (e.g. for images, we just get