#
# Copyright 1999, 2000 Martin Pool <mbp@humbug.org.au>
# Copyright 2002 Gerardo Poggiali
-# Copyright 2007 Bernardo Innocenti <bernie@codewiz.org>
+# Copyright 2007, 2008 Bernardo 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
# Regular expression defining a WikiWord
# (but this definition is also assumed in other places)
-file_re = re.compile(r"^\b([A-Za-z0-9_\.\-]+)\b$")
-word_re = re.compile(r"^\b([A-Z][a-z]+){2,}\b$")
+file_re = re.compile(r"^\b([A-Za-z0-9_\.\-/]+)\b$")
+word_re = re.compile(r"^\b((([A-Z][a-z]+){2,}/)*([A-Z][a-z]+){2,})\b$")
img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg)$", re.IGNORECASE)
url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$")
except:
return addr
+def relative_url(path, privileged=False):
+ if not (url_re.match(path) or path.startswith('/')):
+ if privileged:
+ url = privileged_path()
+ else:
+ url = script_name()
+ path = url + '/' + path
+ return path
+
# Formatting stuff --------------------------------------------------
def emit_header(type="text/html"):
if not name:
print ' <meta name="robots" content="noindex,nofollow" />'
for css in css_url:
- print ' <link rel="stylesheet" type="text/css" href="%s" />' % css
+ print ' <link rel="stylesheet" type="text/css" href="%s" />' % relative_url(css)
print '</head>'
# Body
if name:
print ' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink')
if privileged_url is not None:
- print ' | ' + link_tag('?edit=' + name, 'Edit Page', 'navlink', authentication=True)
+ print ' | ' + link_tag('?edit=' + name, 'Edit Page', 'navlink', privileged=True)
else:
print ' | <i>Immutable Page</i>'
print '<hr /></div>'
-def link_tag(params, text=None, ss_class=None, authentication=False):
+def link_tag(params, text=None, ss_class=None, privileged=False):
if text is None:
text = params # default
classattr = ''
# Prevent crawlers from following links potentially added by spammers or to generated pages
if ss_class == 'external' or ss_class == 'navlink':
classattr += 'rel="nofollow" '
- if authentication:
- path = privileged_path()
- else:
- path = script_name()
- return '<a %shref="%s/%s">%s</a>' % (classattr, path, params, text)
+ return '<a %shref="%s">%s</a>' % (classattr, relative_url(params, privileged=privileged), text)
# Search ---------------------------------------------------
def __init__(self, raw):
self.raw = raw
self.h_level = 0
- self.in_pre = self.in_table = self.in_tt = self.in_em = self.in_b = False
+ self.in_pre = self.in_table = False
self.in_header = True
self.list_indents = []
self.tr_cnt = self.h_cnt = 0
+ self.styles = {
+ #wiki html enabled?
+ "//": ["em", False],
+ "''": ["em", False],
+ "**": ["b", False],
+ "'''": ["b", False],
+ "##": ["tt", False],
+ "``": ["tt", False],
+ "__": ["u", False],
+ "^^": ["sup", False],
+ ",,": ["sub", False]
+ }
def _b_repl(self, word):
- self.in_b = not self.in_b
- return ['</strong>', '<strong>'][self.in_b]
-
- def _em_repl(self, word):
- self.in_em = not self.in_em
- return ['</em>', '<em>'][self.in_em]
-
- def _tt_repl(self, word):
- self.in_tt = not self.in_tt
- return ['</tt>', '<tt>'][self.in_tt]
+ style = self.styles[word]
+ style[1] = not style[1]
+ return ['</','<'][style[1]] + style[0] + '>'
def _tit_repl(self, word):
if self.h_level:
return Page(word).link_to()
def _img_repl(self, word):
- path = script_name() + '/' + word;
+ path = relative_url(word)
return '<a href="%s"><img border="0" src="%s" /></a>' % (path, path)
def _url_repl(self, word):
return '<a href="%s" rel="nofollow" class="external">%s</a>' % (word, word)
def _hurl_repl(self, word):
- m = re.compile("\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\]").match(word)
+ m = re.compile("\[\[([^ \t\n\r\f\v\|]+)(?:\s*\|\s*([^\]]+)|)\]\]").match(word)
name = m.group(1)
descr = m.group(2) or name
if macro:
return apply(macro, (name, descr))
elif img_re.match(name):
- return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (name, name, descr)
+ # 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, descr, descr)
else:
if img_re.match(descr):
descr = '<img border="0" src="' + descr + '" />'
scan_re = re.compile(
r"(?:"
# Formatting
- + r"(?P<b>\*\*|''')"
- + r"|(?P<em>//|'')"
- + r"|(?P<tt>##|``)"
+ + r"(?P<b>\*\*|'''|//|''|##|``|__|\^\^|,,)"
+ r"|(?P<tit>\={2,6})"
+ r"|(?P<br>\\\\)"
+ r"|(?P<rule>^-{3,})"
# Links
+ r"|(?P<img>\b[a-zA-Z0-9_-]+\.(png|gif|jpg|jpeg|bmp))"
+ r"|(?P<word>\b(?:[A-Z][a-z]+){2,}\b)"
- + r"|(?P<hurl>\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\])"
+ + r"|(?P<hurl>\[\[([^ \t\n\r\f\v\|]+)(?:\s*\|\s*([^\]]+)|)\]\])"
+ r"|(?P<url>(http|https|ftp|mailto)\:[^\s'\"]+\S)"
+ r"|(?P<email>[-\w._+]+\@[\w.-]+)"
+ ' for ' + cgi.escape(remote_user())
+ ' from ' + cgi.escape(get_hostname(remote_host()))
+ '</b></p>')
- print '<div class="editor"><form method="post" action="%s/%s">' % (script_name(), self.page_name)
+ print '<div class="editor"><form method="post" action="%s">' % relative_url(self.page_name)
print '<input type="hidden" name="savepage" value="%s">' % (self.page_name)
print """<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100">%s</textarea>""" % (preview or self.get_raw_body())
print """