#
# Copyright 1999, 2000 Martin Pool <mbp@humbug.org.au>
# Copyright 2002 Gerardo Poggiali
-# Copyright 2007, 2008 Bernie Innocenti <bernie@codewiz.org>
+# Copyright 2007, 2008, 2009 Bernie Innocenti <bernie@codewiz.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# Navbar
print '<div class="nav">'
+ print link_tag('FrontPage', relative_url(site_icon or 'Home'), 'navlink')
if name:
print ' <b>' + link_tag('?fullsearch=' + name, text, 'navlink') + '</b> '
else:
print ' <b>' + text + '</b> '
- print ' | ' + link_tag('FrontPage', 'Home', 'navlink')
print ' | ' + link_tag('FindPage', 'Find Page', 'navlink')
if 'history_url' in globals():
print ' | <a href="' + relative_url(history_url) + '" class="navlink">Recent Changes</a>'
user = remote_user()
if user != 'AnonymousCoward':
- print ' | <span class="login"><i>logged in as <b>' + cgi.escape(user) + '</b></i></span>'
+ print ' | <span class="login"><i><b>' + link_tag('User/' + user, user) + '</b></i></span>'
print '<hr /></div>'
return '<a %shref="%s">%s</a>' % (classattr, relative_url(params, privileged=privileged), text)
+def link_inline(name, descr=None, args=''):
+ if not descr: descr = name
+ if video_re.match(name):
+ return '<video src="%s">Your browser does not support the HTML5 video tag</video>' % name
+ else:
+ return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (name, name + args, descr)
+
# Search ---------------------------------------------------
def handle_fullsearch(needle):
"__": ["u", False],
"^^": ["sup", False],
",,": ["sub", False],
- "''": ["em", False], # OBSOLETE
- "'''": ["b", False], # OBSOLETE
- "``": ["tt", False], # OBSOLETE
+ "''": ["em", False], # LEGACY
+ "'''": ["b", False], # LEGACY
+ "``": ["tt", False], # LEGACY
}
def _b_repl(self, word):
m = link_re.match(word)
return link_tag(m.group(1), m.group(2))
- def _url_repl(self, word):
- return link_tag(word)
-
- def _word_repl(self, word):
- return link_tag(word)
-
def _inl_repl(self, word):
m = link_re.match(word)
name = relative_url(m.group(1))
args = '?' + '&'.join(argv)
# The "extthumb" nonsense works around a limitation of the HTML block model
- return '<div class="extthumb"><div class="thumb"><a href="%s"><img border="0" src="%s" alt="%s" /></a><div class="caption">%s</div></div></div>' \
- % (name, name + args, descr, descr)
- elif video_re.match(name):
- return '<video src="%s">Your browser does not support the HTML5 video tag</video>' % name
+ return '<div class="extthumb"><div class="thumb">' \
+ + link_inline(name, descr, args) \
+ + '<div class="caption">' + descr + '</div></div></div>'
else:
- return '<a href="%s"><img border="0" src="%s" /></a>' % (name, name)
-
- def _img_repl(self, word):
- return self._inl_repl('{{' + word + '}}')
-
- def _email_repl(self, word):
- return '<a href="mailto:%s">%s</a>' % (word, word)
+ return link_inline(name, name)
def _html_repl(self, word):
self.in_html += 1
'<': '<',
'>': '>'}[s]
+ def _img_repl(self, word): # LEGACY
+ return self._inl_repl('{{' + word + '}}')
+
+ def _word_repl(self, word): # LEGACY
+ if self.in_html: return word # pass through
+ return link_tag(word)
+
+ def _url_repl(self, word): # LEGACY
+ if self.in_html: return word # pass through
+ return link_tag(word)
+
+ def _email_repl(self, word): # LEGACY
+ if self.in_html: return word # pass through
+ return '<a href="mailto:%s">%s</a>' % (word, word)
+
def _li_repl(self, match):
if self.in_li:
return '</li><li>'
print "</div>"
send_footer()
- def send_raw(self, mimetype='text/plain'):
- if self.can_read():
- body = self.get_raw_body()
- emit_header(mimetype)
- print body
- else:
+ def send_raw(self, mimetype='text/plain', args=[]):
+ if not self.can_read():
send_title(None, msg_text='Read access denied by ACLs', msg_type='notice')
+ return
- def send_image(self, mimetype, args=[]):
if 'maxwidth' in args:
import subprocess
emit_header(mimetype)
subprocess.check_call(['gm', 'convert', self._filename(),
'-scale', args['maxwidth'].value + ' >', '-'])
else:
- self.send_raw(mimetype)
+ body = self.get_raw_body()
+ emit_header(mimetype)
+ print body
def _write_file(self, data):
tmp_filename = self._tmp_filename()
else:
query = query_string()
if file_re.match(query):
- if word_re.match(query):
- Page(query).format()
+ # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
+ from mimetypes import MimeTypes
+ mimetype, encoding = MimeTypes().guess_type(query)
+ if mimetype:
+ Page(query).send_raw(mimetype=mimetype, args=form)
else:
- from mimetypes import MimeTypes
- mimetype, encoding = MimeTypes().guess_type(query)
- if mimetype:
- if mimetype.startswith('image/'):
- Page(query).send_image(mimetype=mimetype, args=form)
- else:
- Page(query).send_raw(mimetype=mimetype)
- else:
- Page(query).format()
+ Page(query).format()
else:
send_httperror("403 Forbidden", query)