diff MoinMoin/formatter/text_html.py @ 5061:4d90b17cb7b1

formatter.text_html: moved attachment_drawing to the twikidraw action. Each drawing_action can have its own attachment_drawing method.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 30 Aug 2009 17:53:04 +0200
parents de10b1613647
children ff588e9e24d6
line wrap: on
line diff
--- a/MoinMoin/formatter/text_html.py	Sun Aug 30 14:19:11 2009 +0200
+++ b/MoinMoin/formatter/text_html.py	Sun Aug 30 17:53:04 2009 +0200
@@ -653,52 +653,13 @@
             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, drawing = AttachFile.absoluteName(url, self.page.page_name)
-        containername = wikiutil.taintfilename(drawing) + ".tdraw"
-
-        drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request, drawing=drawing, upload=True)
-        ci = AttachFile.ContainerItem(self.request, pagename, containername)
-        if not ci.exists():
-            title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': drawing}
-            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(drawing)}
-        kw['src'] = src = ci.member_url(drawing + u'.png')
-        kw['css'] = 'drawing'
-
+        # ToDo try to move this to a better place e.g. __init__
         try:
-            mapfile = ci.get(drawing + u'.map')
-            map = mapfile.read()
-            mapfile.close()
-        except (KeyError, IOError, OSError):
-            map = ''
-        if map:
-            # we have a image map. inline it and add a map ref to the img tag
-            mapid = 'ImageMapOf' + drawing
-            map = map.replace('%MAPNAME%', mapid)
-            # add alt and title tags to areas
-            map = re.sub(r'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(drawing)}
-            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:
-            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)
-
+            attachment_drawing = wikiutil.importPlugin(self.request.cfg, 'action',
+                                              self.request.cfg.drawing_action, 'attachment_drawing')
+            return attachment_drawing(self, url, text, **kw)
+        except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
+            return url
 
     # Text ##############################################################