comparison MoinMoin/formatter/text_html.py @ 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 cb22f4c4a0fd
children 4d95fa3b074d af211e2f132c
comparison
equal deleted inserted replaced
4471:5ea38c7fa252 4476:f8e4e84525e8
650 css = 'nonexistent' 650 css = 'nonexistent'
651 target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True) 651 target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True)
652 return self.url(1, target, css=css, title=title) + img + self.url(0) 652 return self.url(1, target, css=css, title=title) + img + self.url(0)
653 653
654 def attachment_drawing(self, url, text, **kw): 654 def attachment_drawing(self, url, text, **kw):
655 # XXX text arg is unused!
655 _ = self.request.getText 656 _ = self.request.getText
656 pagename, filename = AttachFile.absoluteName(url, self.page.page_name) 657 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
657 fname = wikiutil.taintfilename(filename) 658 fname = wikiutil.taintfilename(filename)
658 drawing = fname 659 drawing = fname
659 fname = fname + u".png" 660 fname = fname + u".png"
668 fname, filename = gfname, gfilename 669 fname, filename = gfname, gfilename
669 670
670 # check whether attachment exists, possibly point to upload form 671 # check whether attachment exists, possibly point to upload form
671 drawing_url = AttachFile.getAttachUrl(pagename, fname, self.request, drawing=drawing, upload=True) 672 drawing_url = AttachFile.getAttachUrl(pagename, fname, self.request, drawing=drawing, upload=True)
672 if not exists: 673 if not exists:
673 linktext = _('Create new drawing "%(filename)s (opens in new window)"') 674 title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': fname}
674 return (self.url(1, drawing_url) + 675 img = self.icon('attachimg') # TODO: we need a new "drawimg" in similar grey style and size
675 self.text(linktext % {'filename': fname}) + 676 css = 'nonexistent'
676 self.url(0)) 677 return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
678
679 title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)}
680 kw['src'] = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
681 kw['css'] = 'drawing'
677 682
678 mappath = AttachFile.getFilename(self.request, pagename, drawing + u'.map') 683 mappath = AttachFile.getFilename(self.request, pagename, drawing + u'.map')
679 684 try:
680 # check for map file 685 map = file(mappath, 'r').read()
681 if os.path.exists(mappath): 686 except (IOError, OSError):
687 map = ''
688 if map:
682 # we have a image map. inline it and add a map ref to the img tag 689 # we have a image map. inline it and add a map ref to the img tag
683 try: 690 mapid = 'ImageMapOf' + drawing
684 map = file(mappath, 'r').read() 691 map = map.replace('%MAPNAME%', mapid)
685 except IOError: 692 # add alt and title tags to areas
686 pass 693 map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
687 except OSError: 694 map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, title, title))
688 pass 695 # unxml, because 4.01 concrete will not validate />
689 else: 696 map = map.replace('/>', '>')
690 mapid = 'ImageMapOf' + drawing 697 title = _('Clickable drawing: %(filename)s') % {'filename': self.text(fname)}
691 # replace MAPNAME 698 if 'title' not in kw:
692 map = map.replace('%MAPNAME%', mapid) 699 kw['title'] = title
693 # add alt and title tags to areas 700 if 'alt' not in kw:
694 map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map) 701 kw['alt'] = kw['title']
695 # add in edit links plus alt and title attributes 702 kw['usemap'] = '#'+mapid
696 alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)} 703 return map + self.image(**kw)
697 map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, alt, title)) 704 else:
698 # unxml, because 4.01 concrete will not validate /> 705 if 'title' not in kw:
699 map = map.replace('/>', '>') 706 kw['title'] = title
700 alt = title = _('Clickable drawing: %(filename)s') % {'filename': self.text(fname)} 707 if 'alt' not in kw:
701 src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1) 708 kw['alt'] = kw['title']
702 return (map + self.image(alt=alt, title=title, src=src, usemap='#'+mapid, css="drawing")) 709 return self.url(1, drawing_url) + self.image(**kw) + self.url(0)
703 else:
704 alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)}
705 src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
706 return (self.url(1, drawing_url) +
707 self.image(alt=alt, title=title, src=src, css="drawing") +
708 self.url(0))
709 710
710 711
711 # Text ############################################################## 712 # Text ##############################################################
712 713
713 def _text(self, text): 714 def _text(self, text):