comparison MoinMoin/formatter/text_html.py @ 3054:d2e9afd64276

get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 20 Feb 2008 10:23:56 +0100
parents 3a6a25169f55
children 5cb80bd604b4
comparison
equal deleted inserted replaced
3053:067a87029064 3054:d2e9afd64276
479 479
480 def interwikilink(self, on, interwiki='', pagename='', **kw): 480 def interwikilink(self, on, interwiki='', pagename='', **kw):
481 """ 481 """
482 @keyword title: override using the interwiki wikiname as title 482 @keyword title: override using the interwiki wikiname as title
483 """ 483 """
484 querystr = kw.get('querystr', {})
484 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename) 485 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename)
485 wikiurl = wikiutil.mapURL(self.request, wikiurl) 486 wikiurl = wikiutil.mapURL(self.request, wikiurl)
486 if wikitag == 'Self': # for own wiki, do simple links 487 if wikitag == 'Self': # for own wiki, do simple links
487 if '#' in wikitail: 488 if '#' in wikitail:
488 wikitail, kw['anchor'] = rsplit(wikitail, '#', 1) 489 wikitail, kw['anchor'] = rsplit(wikitail, '#', 1)
493 pagename = wikitail 494 pagename = wikitail
494 return self.pagelink(on, pagename, **kw) 495 return self.pagelink(on, pagename, **kw)
495 else: # return InterWiki hyperlink 496 else: # return InterWiki hyperlink
496 if on: 497 if on:
497 href = wikiutil.join_wiki(wikiurl, wikitail) 498 href = wikiutil.join_wiki(wikiurl, wikitail)
499 if querystr:
500 href += '?%s' % wikiutil.makeQueryString(querystr)
498 if wikitag_bad: 501 if wikitag_bad:
499 html_class = 'badinterwiki' 502 html_class = 'badinterwiki'
500 else: 503 else:
501 html_class = 'interwiki' 504 html_class = 'interwiki'
502 title = kw.get('title', wikitag) 505 title = kw.get('title', wikitag)
607 @param on: 1/True=start link, 0/False=end link 610 @param on: 1/True=start link, 0/False=end link
608 @param url: filename.ext or PageName/filename.ext 611 @param url: filename.ext or PageName/filename.ext
609 """ 612 """
610 assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was 613 assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was
611 _ = self.request.getText 614 _ = self.request.getText
615 querystr = kw.get('querystr', {})
616 assert isinstance(querystr, dict) # new in 1.6, only support dicts
617 if 'do' not in querystr:
618 querystr['do'] = 'view'
612 if on: 619 if on:
613 pagename, filename = AttachFile.absoluteName(url, self.page.page_name) 620 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
614 #self.request.log("attachment_link: url %s pagename %s filename %s" % (url, pagename, filename)) 621 #self.request.log("attachment_link: url %s pagename %s filename %s" % (url, pagename, filename))
615 fname = wikiutil.taintfilename(filename) 622 fname = wikiutil.taintfilename(filename)
616 if AttachFile.exists(self.request, pagename, fname): 623 if AttachFile.exists(self.request, pagename, fname):
617 target = AttachFile.getAttachUrl(pagename, fname, self.request, do='view') 624 target = AttachFile.getAttachUrl(pagename, fname, self.request, do=querystr['do'])
618 title = "attachment:%s" % url 625 title = "attachment:%s" % url
619 css = 'attachment' 626 css = 'attachment'
620 else: 627 else:
621 target = AttachFile.getAttachUploadUrl(pagename, fname, self.request) 628 target = AttachFile.getAttachUploadUrl(pagename, fname, self.request)
622 title = _('Upload new attachment "%(filename)s"') % {'filename': wikiutil.escape(fname)} 629 title = _('Upload new attachment "%(filename)s"', formatted=False) % {'filename': wikiutil.escape(fname)}
623 css = 'attachment nonexistent' 630 css = 'attachment nonexistent'
624 return self.url(on, target, css=css, title=title) 631 return self.url(on, target, css=css, title=title)
625 else: 632 else:
626 return self.url(on) 633 return self.url(on)
627 634
628 def attachment_image(self, url, **kw): 635 def attachment_image(self, url, **kw):
629 _ = self.request.getText 636 _ = self.request.getText
630 pagename, filename = AttachFile.absoluteName(url, self.page.page_name) 637 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
631 fname = wikiutil.taintfilename(filename) 638 fname = wikiutil.taintfilename(filename)
632 if not AttachFile.exists(self.request, pagename, fname): 639 exists = AttachFile.exists(self.request, pagename, fname)
633 linktext = _('Upload new attachment "%(filename)s"') 640 if exists:
641 kw['css'] = 'attachment'
642 kw['src'] = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
643 title = _('Inlined image: %(url)s', formatted=False) % {'url': self.text(url)}
644 if not 'title' in kw:
645 kw['title'] = title
646 # alt is required for images:
647 if not 'alt' in kw:
648 kw['alt'] = kw['title']
649 return self.image(**kw)
650 else:
651 title = _('Upload new attachment "%(filename)s"', formatted=False) % {
652 'filename': wikiutil.escape(fname)}
653 img = self.icon('attachimg')
654 css = 'nonexistent'
634 return wikiutil.link_tag( 655 return wikiutil.link_tag(
635 self.request, 656 self.request,
636 ('%s?action=AttachFile&rename=%s' % 657 ('%s?action=AttachFile&rename=%s' %
637 (wikiutil.quoteWikinameURL(pagename), 658 (wikiutil.quoteWikinameURL(pagename),
638 wikiutil.url_quote_plus(fname))), 659 wikiutil.url_quote_plus(fname))),
639 linktext % {'filename': self.text(fname)}) 660 img,
640 if not 'title' in kw: 661 title=title,
641 kw['title'] = _('Inlined image: %(url)s') % {'url': self.text(url)} 662 css_class=css)
642 # alt is required for images:
643 if not 'alt' in kw:
644 kw['alt'] = kw['title']
645 return self.image(
646 title=kw['title'],
647 alt=kw['alt'],
648 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1),
649 css="attachment")
650 663
651 def attachment_drawing(self, url, text, **kw): 664 def attachment_drawing(self, url, text, **kw):
652 _ = self.request.getText 665 _ = self.request.getText
653 pagename, filename = AttachFile.absoluteName(url, self.page.page_name) 666 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
654 fname = wikiutil.taintfilename(filename) 667 fname = wikiutil.taintfilename(filename)
664 if exists: 677 if exists:
665 fname, filename = gfname, gfilename 678 fname, filename = gfname, gfilename
666 679
667 # check whether attachment exists, possibly point to upload form 680 # check whether attachment exists, possibly point to upload form
668 if not exists: 681 if not exists:
669 linktext = _('Create new drawing "%(filename)s (opens in new window)"') 682 linktext = _('Create new drawing "%(filename)s (opens in new window)"', formatted=False)
670 return wikiutil.link_tag( 683 return wikiutil.link_tag(
671 self.request, 684 self.request,
672 ('%s?action=AttachFile&rename=%s%s' % 685 ('%s?action=AttachFile&rename=%s%s' %
673 (wikiutil.quoteWikinameURL(pagename), 686 (wikiutil.quoteWikinameURL(pagename),
674 wikiutil.url_quote_plus(fname), 687 wikiutil.url_quote_plus(fname),
695 # replace MAPNAME 708 # replace MAPNAME
696 map = map.replace('%MAPNAME%', mapid) 709 map = map.replace('%MAPNAME%', mapid)
697 # add alt and title tags to areas 710 # add alt and title tags to areas
698 map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map) 711 map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
699 # add in edit links plus alt and title attributes 712 # add in edit links plus alt and title attributes
700 alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)} 713 alt = title = _('Edit drawing %(filename)s (opens in new window)', formatted=False) % {'filename': self.text(fname)}
701 map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (edit_link, alt, title)) 714 map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (edit_link, alt, title))
702 # unxml, because 4.01 concrete will not validate /> 715 # unxml, because 4.01 concrete will not validate />
703 map = map.replace('/>', '>') 716 map = map.replace('/>', '>')
704 alt = title = _('Clickable drawing: %(filename)s') % {'filename': self.text(fname)} 717 alt = title = _('Clickable drawing: %(filename)s', formatted=False) % {'filename': self.text(fname)}
705 return (map + self.image( 718 return (map + self.image(
706 alt=alt, 719 alt=alt,
707 title=title, 720 title=title,
708 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1), 721 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1),
709 usemap='#'+mapid, css="drawing")) 722 usemap='#'+mapid, css="drawing"))
710 else: 723 else:
711 alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)} 724 alt = title = _('Edit drawing %(filename)s (opens in new window)', formatted=False) % {'filename': self.text(fname)}
712 return wikiutil.link_tag(self.request, 725 return wikiutil.link_tag(self.request,
713 edit_link, 726 edit_link,
714 self.image(alt=alt, 727 self.image(alt=alt,
715 title=title, 728 title=title,
716 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1), css="drawing"), 729 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1), css="drawing"),