493
488
wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename)
494
489
wikiurl = wikiutil.mapURL(self.request, wikiurl)
495
490
if wikitag == 'Self': # for own wiki, do simple links
492
wikitail, kw['anchor'] = rsplit(wikitail, '#', 1)
496
493
wikitail = wikiutil.url_unquote(wikitail)
497
494
try: # XXX this is the only place where we access self.page - do we need it? Crashes silently on actions!
498
495
pagename = wikiutil.AbsPageName(self.page.page_name, wikitail)
626
619
fname = wikiutil.taintfilename(filename)
627
620
if AttachFile.exists(self.request, pagename, fname):
628
621
target = AttachFile.getAttachUrl(pagename, fname, self.request, do=querystr['do'])
629
if not 'title' in kw:
630
kw['title'] = "attachment:%s" % url
631
kw['css'] = 'attachment'
622
title = "attachment:%s" % url
633
target = AttachFile.getAttachUrl(pagename, fname, self.request, do='upload_form')
634
kw['title'] = _('Upload new attachment "%(filename)s"') % {'filename': fname}
635
kw['css'] = 'attachment nonexistent'
636
return self.url(on, target, **kw)
625
target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True)
626
title = _('Upload new attachment "%(filename)s"') % {'filename': fname}
627
css = 'attachment nonexistent'
628
return self.url(on, target, css=css, title=title)
638
630
return self.url(on)
656
648
title = _('Upload new attachment "%(filename)s"') % {'filename': fname}
657
649
img = self.icon('attachimg')
658
650
css = 'nonexistent'
659
target = AttachFile.getAttachUrl(pagename, fname, self.request, do='upload_form')
651
target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True)
660
652
return self.url(1, target, css=css, title=title) + img + self.url(0)
662
654
def attachment_drawing(self, url, text, **kw):
663
# ToDo try to move this to a better place e.g. __init__
665
drawing_action = AttachFile.get_action(self.request, url, do='modify')
666
assert drawing_action is not None
667
attachment_drawing = wikiutil.importPlugin(self.request.cfg, 'action',
668
drawing_action, 'attachment_drawing')
669
return attachment_drawing(self, url, text, **kw)
670
except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError, AssertionError):
655
_ = self.request.getText
656
pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
657
fname = wikiutil.taintfilename(filename)
659
fname = fname + u".png"
660
filename = filename + u".png"
661
# fallback for old gif drawings (1.1 -> 1.2)
662
exists = AttachFile.exists(self.request, pagename, fname)
664
gfname = fname[:-4] + u".gif"
665
gfilename = filename[:-4] + u".gif"
666
exists = AttachFile.exists(self.request, pagename, gfname)
668
fname, filename = gfname, gfilename
670
# check whether attachment exists, possibly point to upload form
671
drawing_url = AttachFile.getAttachUrl(pagename, fname, self.request, drawing=drawing, upload=True)
673
linktext = _('Create new drawing "%(filename)s (opens in new window)"')
674
return (self.url(1, drawing_url) +
675
self.text(linktext % {'filename': fname}) +
678
mappath = AttachFile.getFilename(self.request, pagename, drawing + u'.map')
681
if os.path.exists(mappath):
682
# we have a image map. inline it and add a map ref to the img tag
684
map = file(mappath, 'r').read()
690
mapid = 'ImageMapOf' + drawing
692
map = map.replace('%MAPNAME%', mapid)
693
# add alt and title tags to areas
694
map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
695
# add in edit links plus alt and title attributes
696
alt = title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)}
697
map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, alt, title))
698
# unxml, because 4.01 concrete will not validate />
699
map = map.replace('/>', '>')
700
alt = title = _('Clickable drawing: %(filename)s') % {'filename': self.text(fname)}
701
src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
702
return (map + self.image(alt=alt, title=title, src=src, usemap='#'+mapid, css="drawing"))
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") +
673
711
# Text ##############################################################
825
863
function addnumber(did, nstart, nstep) {
826
864
var c = document.getElementById(did), l = c.firstChild, n = 1;
827
if (!isnumbered(c)) {
828
866
if (typeof nstart == 'undefined') nstart = 1;
829
867
if (typeof nstep == 'undefined') nstep = 1;
831
869
while (l != null) {
832
870
if (l.tagName == 'SPAN') {
833
871
var s = document.createElement('SPAN');
834
var a = document.createElement('A');
835
s.className = 'LineNumber';
836
a.appendChild(document.createTextNode(nformat(n,4,'')));
837
a.href = '#' + did + '_' + n;
839
s.appendChild(document.createTextNode(' '));
872
s.className = 'LineNumber'
873
s.appendChild(document.createTextNode(nformat(n,4,' ')));
841
if (l.childNodes.length) {
842
l.insertBefore(s, l.firstChild);
875
if (l.childNodes.length)
876
l.insertBefore(s, l.firstChild)
848
880
l = l.nextSibling;
853
884
function remnumber(did) {
854
885
var c = document.getElementById(did), l = c.firstChild;
856
887
while (l != null) {
857
888
if (l.tagName == 'SPAN' && l.firstChild.className == 'LineNumber') l.removeChild(l.firstChild);
858
889
l = l.nextSibling;
863
893
function togglenumber(did, nstart, nstep) {
898
926
self._in_code_area = 1
899
927
self._in_code_line = 0
900
928
# id in here no longer used
901
self._code_area_state = [None, show, start, step, start, ci]
904
attr = {'class': 'codemsg'}
905
res.append(self._open('div', attr={'class': 'codemsg'}))
907
res.append(self._close('div'))
929
self._code_area_state = [None, show, start, step, start]
909
931
# Open the code div - using left to right always!
910
932
attr = {'class': 'codearea', 'lang': 'en', 'dir': 'ltr'}