" % (hits, searched))
def handle_raw(pagename):
+ if not file_re.match(pagename):
+ send_httperror("403 Forbidden", pagename)
+ return
+
Page(pagename).send_raw()
def handle_edit(pagename):
+ if not file_re.match(pagename):
+ send_httperror("403 Forbidden", pagename)
+ return
+
pg = Page(pagename)
if 'save' in form:
if form['file'].value:
- pg.save(form['file'].file.read())
+ pg.save(form['file'].file.read(), form['changelog'].value)
else:
- pg.save(form['savetext'].value.replace('\r\n', '\n'))
+ pg.save(form['savetext'].value.replace('\r\n', '\n'), form['changelog'].value)
pg.format()
elif 'cancel' in form:
pg.msg_text = 'Editing canceled'
@@ -261,24 +278,27 @@ def handle_edit(pagename):
pg.send_editor(text)
def make_index_key():
- links = map(lambda ch: '%s' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz')
+ links = ['%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
return '
'+ ' | '.join(links) + '
'
def page_list(dir = None, re = word_re):
- return filter(re.match, os.listdir(dir or data_dir))
+ return sorted(filter(re.match, os.listdir(dir or data_dir)))
def send_footer(name, mod_string=None):
if globals().get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
- print '')
class WikiFormatter:
"""Object that turns Wiki markup into HTML.
@@ -346,11 +366,15 @@ class WikiFormatter:
argv = [name]
if m.group(2):
argv.extend(m.group(2).split('|'))
- argv = map(str.strip, argv)
+ argv = list(map(str.strip, argv))
macro = globals().get('_macro_' + name)
if not macro:
- execfile("macros/" + name + ".py", globals())
+ try:
+ exec(open("macros/" + name + ".py").read(), globals())
+ except IOError as er:
+ if er.errno == errno.ENOENT:
+ pass
macro = globals().get('_macro_' + name)
if macro:
return macro(argv)
@@ -360,12 +384,11 @@ class WikiFormatter:
def _hurl_repl(self, word):
m = link_re.match(word)
name = m.group(1)
- if m.group(2) is None:
+ descr = m.group(2)
+ if descr is None:
descr = name
elif img_re.match(m.group(2)):
descr = ''
- else:
- descr = m.group(2)
return link_tag(name, descr, 'wikilink')
@@ -470,14 +493,14 @@ class WikiFormatter:
return res
def replace(self, match):
- for type, hit in match.groupdict().items():
+ for type, hit in list(match.groupdict().items()):
if hit:
return getattr(self, '_' + type + '_repl')(hit)
else:
- raise "Can't handle match " + `match`
+ raise "Can't handle match " + repr(match)
def print_html(self):
- print '
'
+ print('
')
# For each line, we scan through looking for magic
# strings, outputting verbatim any intervening text
@@ -496,7 +519,7 @@ class WikiFormatter:
+ r"|(?P\[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])"
# Inline HTML
- + r"|(?P<(/|)(br|hr|div|form|iframe|input|span))"
+ + r"|(?P<(/|)(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])[^>]*>)"
+ r"|(?P[<>&])"
# Auto links (LEGACY)
@@ -524,7 +547,7 @@ class WikiFormatter:
indent_re = re.compile(r"^\s*")
tr_re = re.compile(r"^\s*\|\|")
eol_re = re.compile(r"\r?\n")
- for self.line in eol_re.split(self.raw.expandtabs()):
+ for self.line in eol_re.split(str(self.raw).expandtabs()):
# Skip ACLs
if self.in_header:
if self.line.startswith('#'):
@@ -532,23 +555,23 @@ class WikiFormatter:
self.in_header = False
if self.in_pre:
- print re.sub(pre_re, self.replace, self.line)
+ print(re.sub(pre_re, self.replace, self.line))
else:
if self.in_table and not tr_re.match(self.line):
self.in_table = False
- print '