changeset 4477:4d95fa3b074d

merged moin/1.8
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Jan 2009 23:56:02 +0100
parents 28fcb65ebec8 (current diff) f8e4e84525e8 (diff)
children 910474dded06
files MoinMoin/formatter/text_html.py MoinMoin/parser/text_moin_wiki.py
diffstat 3 files changed, 36 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_html.py	Sat Jan 03 19:29:26 2009 +0100
+++ b/MoinMoin/formatter/text_html.py	Mon Jan 05 23:56:02 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, drawing = AttachFile.absoluteName(url, self.page.page_name)
         containername = wikiutil.taintfilename(drawing) + ".tdraw"
@@ -659,34 +660,43 @@
         drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request, drawing=drawing, upload=True)
         ci = AttachFile.ContainerItem(self.request, pagename, containername)
         if not ci.exists():
-            return (self.url(1, drawing_url) +
-                    self.text(_('Create new drawing "%(filename)s (opens in new window)"') % {'filename': drawing}) +
-                    self.url(0))
+            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)
 
-        src = ci.member_url(drawing + u'.png')
+        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'
+
         mapfile = ci.get(drawing + u'.map')
-        map = mapfile.read()
-        mapfile.close()
-
+        try:
+            map = mapfile.read()
+            mapfile.close()
+        except (IOError, OSError):
+            map = ''
         if map:
             # we have a image map. inline it and add a map ref to the img tag
             mapid = 'ImageMapOf' + drawing
-            # replace MAPNAME
             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)
-            # add in edit links plus alt and title attributes
-            alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(drawing)}
-            map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, alt, title))
+            map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, title, title))
             # unxml, because 4.01 concrete will not validate />
             map = map.replace('/>', '>')
-            alt = title = _('Clickable drawing: %(filename)s') % {'filename': self.text(drawing)}
-            return (map + self.image(alt=alt, title=title, src=src, usemap='#'+mapid, css="drawing"))
+            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:
-            alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(drawing)}
-            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	Sat Jan 03 19:29:26 2009 +0100
+++ b/MoinMoin/parser/text_creole.py	Mon Jan 05 23:56:02 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	Sat Jan 03 19:29:26 2009 +0100
+++ b/MoinMoin/parser/text_moin_wiki.py	Mon Jan 05 23:56:02 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