changeset 4476:f8e4e84525e8

streamline attachment_drawing formatter behaviour Make it behave more similar to attachment_image: - show grey clip image when there is no drawing - support transclusion params (like height, width, ...) Fix creole parser's usage (use given description as alt text).
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Jan 2009 23:23:54 +0100
parents 5ea38c7fa252
children 4d95fa3b074d 3f0bc26f3d5a
files MoinMoin/formatter/text_html.py MoinMoin/parser/text_creole.py MoinMoin/parser/text_moin_wiki.py
diffstat 3 files changed, 42 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_html.py	Mon Dec 29 17:07:15 2008 +0100
+++ b/MoinMoin/formatter/text_html.py	Mon Jan 05 23:23:54 2009 +0100
@@ -652,6 +652,7 @@
             return self.url(1, target, css=css, title=title) + img + self.url(0)
 
     def attachment_drawing(self, url, text, **kw):
+        # XXX text arg is unused!
         _ = self.request.getText
         pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
         fname = wikiutil.taintfilename(filename)
@@ -670,42 +671,42 @@
         # check whether attachment exists, possibly point to upload form
         drawing_url = AttachFile.getAttachUrl(pagename, fname, self.request, drawing=drawing, upload=True)
         if not exists:
-            linktext = _('Create new drawing "%(filename)s (opens in new window)"')
-            return (self.url(1, drawing_url) +
-                    self.text(linktext % {'filename': fname}) +
-                    self.url(0))
+            title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': fname}
+            img = self.icon('attachimg')  # TODO: we need a new "drawimg" in similar grey style and size
+            css = 'nonexistent'
+            return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
+
+        title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)}
+        kw['src'] = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
+        kw['css'] = 'drawing'
 
         mappath = AttachFile.getFilename(self.request, pagename, drawing + u'.map')
-
-        # check for map file
-        if os.path.exists(mappath):
+        try:
+            map = file(mappath, 'r').read()
+        except (IOError, OSError):
+            map = ''
+        if map:
             # we have a image map. inline it and add a map ref to the img tag
-            try:
-                map = file(mappath, 'r').read()
-            except IOError:
-                pass
-            except OSError:
-                pass
-            else:
-                mapid = 'ImageMapOf' + drawing
-                # replace MAPNAME
-                map = map.replace('%MAPNAME%', mapid)
-                # add alt and title tags to areas
-                map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
-                # add in edit links plus alt and title attributes
-                alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)}
-                map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, alt, title))
-                # unxml, because 4.01 concrete will not validate />
-                map = map.replace('/>', '>')
-                alt = title = _('Clickable drawing: %(filename)s') % {'filename': self.text(fname)}
-                src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
-                return (map + self.image(alt=alt, title=title, src=src, usemap='#'+mapid, css="drawing"))
+            mapid = 'ImageMapOf' + drawing
+            map = map.replace('%MAPNAME%', mapid)
+            # add alt and title tags to areas
+            map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
+            map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, title, title))
+            # unxml, because 4.01 concrete will not validate />
+            map = map.replace('/>', '>')
+            title = _('Clickable drawing: %(filename)s') % {'filename': self.text(fname)}
+            if 'title' not in kw:
+                kw['title'] = title
+            if 'alt' not in kw:
+                kw['alt'] = kw['title']
+            kw['usemap'] = '#'+mapid
+            return map + self.image(**kw)
         else:
-            alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)}
-            src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
-            return (self.url(1, drawing_url) +
-                    self.image(alt=alt, title=title, src=src, css="drawing") +
-                    self.url(0))
+            if 'title' not in kw:
+                kw['title'] = title
+            if 'alt' not in kw:
+                kw['alt'] = kw['title']
+            return self.url(1, drawing_url) + self.image(**kw) + self.url(0)
 
 
     # Text ##############################################################
--- a/MoinMoin/parser/text_creole.py	Mon Dec 29 17:07:15 2008 +0100
+++ b/MoinMoin/parser/text_creole.py	Mon Jan 05 23:23:54 2009 +0100
@@ -351,7 +351,7 @@
                     return self.formatter.attachment_image(
                         url, alt=text, html_class='image')
                 elif scheme == 'drawing':
-                    return self.formatter.attachment_drawing(url, text)
+                    return self.formatter.attachment_drawing(url, text, alt=text)
                 else:
                     pass
             elif m.group('inter_wiki'):
--- a/MoinMoin/parser/text_moin_wiki.py	Mon Dec 29 17:07:15 2008 +0100
+++ b/MoinMoin/parser/text_moin_wiki.py	Mon Jan 05 23:23:54 2009 +0100
@@ -769,7 +769,14 @@
                             return m.execute('EmbedObject', u'target=%s' % url)
                 elif scheme == 'drawing':
                     desc = self._transclude_description(desc, url)
-                    return self.formatter.attachment_drawing(url, desc)
+                    if desc:
+                        tag_attrs= {'alt': desc, 'title': desc, }
+                    else:
+                        tag_attrs = {}
+                    tag_attrs, query_args = self._get_params(params,
+                                                             tag_attrs=tag_attrs,
+                                                             acceptable_attrs=acceptable_attrs_img)
+                    return self.formatter.attachment_drawing(url, desc, **tag_attrs)
 
             elif m.group('page_name'):
                 # experimental client side transclusion