comparison 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
comparison
equal deleted inserted replaced
5060:dfc2277289fe 5061:4d90b17cb7b1
651 css = 'nonexistent' 651 css = 'nonexistent'
652 target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True) 652 target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True)
653 return self.url(1, target, css=css, title=title) + img + self.url(0) 653 return self.url(1, target, css=css, title=title) + img + self.url(0)
654 654
655 def attachment_drawing(self, url, text, **kw): 655 def attachment_drawing(self, url, text, **kw):
656 # XXX text arg is unused! 656 # ToDo try to move this to a better place e.g. __init__
657 _ = self.request.getText
658 pagename, drawing = AttachFile.absoluteName(url, self.page.page_name)
659 containername = wikiutil.taintfilename(drawing) + ".tdraw"
660
661 drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request, drawing=drawing, upload=True)
662 ci = AttachFile.ContainerItem(self.request, pagename, containername)
663 if not ci.exists():
664 title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': drawing}
665 img = self.icon('attachimg') # TODO: we need a new "drawimg" in similar grey style and size
666 css = 'nonexistent'
667 return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
668
669 title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(drawing)}
670 kw['src'] = src = ci.member_url(drawing + u'.png')
671 kw['css'] = 'drawing'
672
673 try: 657 try:
674 mapfile = ci.get(drawing + u'.map') 658 attachment_drawing = wikiutil.importPlugin(self.request.cfg, 'action',
675 map = mapfile.read() 659 self.request.cfg.drawing_action, 'attachment_drawing')
676 mapfile.close() 660 return attachment_drawing(self, url, text, **kw)
677 except (KeyError, IOError, OSError): 661 except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
678 map = '' 662 return url
679 if map:
680 # we have a image map. inline it and add a map ref to the img tag
681 mapid = 'ImageMapOf' + drawing
682 map = map.replace('%MAPNAME%', mapid)
683 # add alt and title tags to areas
684 map = re.sub(r'href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
685 map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, title, title))
686 # unxml, because 4.01 concrete will not validate />
687 map = map.replace('/>', '>')
688 title = _('Clickable drawing: %(filename)s') % {'filename': self.text(drawing)}
689 if 'title' not in kw:
690 kw['title'] = title
691 if 'alt' not in kw:
692 kw['alt'] = kw['title']
693 kw['usemap'] = '#'+mapid
694 return map + self.image(**kw)
695 else:
696 if 'title' not in kw:
697 kw['title'] = title
698 if 'alt' not in kw:
699 kw['alt'] = kw['title']
700 return self.url(1, drawing_url) + self.image(**kw) + self.url(0)
701
702 663
703 # Text ############################################################## 664 # Text ##############################################################
704 665
705 def _text(self, text): 666 def _text(self, text):
706 text = wikiutil.escape(text) 667 text = wikiutil.escape(text)