if name and writable and privileged_url is not None:
print(' <link rel="alternate" type="application/x-wiki" title="Edit this page" href="%s" />' \
- % (privileged_path() + '?edit=' + name))
+ % (privileged_path() + '?a=edit&q=' + name))
if history_url is not None:
print(' <link rel="alternate" type="application/rss+xml" title="RSS" href="%s" />' \
# Body
if name and writable and privileged_url is not None:
- print('<body ondblclick="location.href=\'' + privileged_path() + '?edit=' + name + '\'">')
+ print('<body ondblclick="location.href=\'' + privileged_path() + '?a=edit&q=' + name + '\'">')
else:
print('<body>')
print(' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink'))
if privileged_url is not None:
if writable:
- print(' | ' + link_tag('?edit=' + name, 'Edit', 'navlink', privileged=True))
+ print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', 'navlink', privileged=True))
else:
print(' | ' + link_tag(name, 'Login', 'navlink', privileged=True))
# Search ---------------------------------------------------
-def handle_fullsearch(needle):
- send_title(None, 'Full text search for "%s"' % (needle))
+def print_search_stats(hits, searched):
+ print("<p>%d hits out of %d pages searched.</p>" % (hits, searched))
+
+def handle_fullsearch(query, form):
+ needle = form['q'].value
+ send_title(None, 'Full text search for "' + needle + '"')
needle_re = re.compile(needle, re.IGNORECASE)
hits = []
print_search_stats(len(hits), len(all_pages))
-def handle_titlesearch(needle):
+def handle_titlesearch(query, form):
# TODO: check needle is legal -- but probably we can just accept any RE
- send_title(None, "Title search for \"" + needle + '"')
+ needle = form['q'].value
+ send_title(None, 'Title search for "' + needle + '"')
needle_re = re.compile(needle, re.IGNORECASE)
all_pages = page_list()
print_search_stats(len(hits), len(all_pages))
-def print_search_stats(hits, searched):
- print("<p>%d hits out of %d pages searched.</p>" % (hits, searched))
-
-def handle_raw(pagename):
+def handle_raw(pagename, form):
if not file_re.match(pagename):
send_httperror("403 Forbidden", pagename)
return
Page(pagename).send_raw()
-def handle_edit(pagename):
+def handle_edit(pagename, form):
if not file_re.match(pagename):
send_httperror("403 Forbidden", pagename)
return
- pg = Page(pagename)
+ pg = Page(form['q'].value)
if 'save' in form:
if form['file'].value:
pg.save(form['file'].file.read(), form['changelog'].value)
text = form['savetext'].value
pg.send_editor(text)
+def handle_get(pagename, form):
+ if file_re.match(pagename):
+ # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
+ from mimetypes import MimeTypes
+ mimetype, encoding = MimeTypes().guess_type(pagename)
+ if mimetype:
+ Page(pagename).send_raw(mimetype=mimetype, args=form)
+ else:
+ Page(pagename).format()
+ else:
+ send_httperror("403 Forbidden", pagename)
+
# Used by macros/WordIndex and macros/TitleIndex
def make_index_key():
links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
self.msg_text = 'Thank you for your contribution. Your attention to detail is appreciated.'
self.msg_type = 'success'
-def main():
- for cmd in form:
- handler = globals().get('handle_' + cmd)
- if handler:
- handler(form[cmd].value)
- break
- else:
- query = query_string()
- if file_re.match(query):
- # 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:
- Page(query).format()
- else:
- send_httperror("403 Forbidden", query)
-
try:
exec(open("geekigeeki.conf.py").read())
form = cgi.FieldStorage()
- main()
+ action = form.getvalue('a', 'get')
+ handler = globals().get('handle_' + action)
+ if handler:
+ handler(query_string(), form)
+ else:
+ send_httperror("403 Forbidden", query_string())
+
except Exception:
import traceback
msg_text = traceback.format_exc()