X-Git-Url: https://codewiz.org/gitweb?p=geekigeeki.git;a=blobdiff_plain;f=geekigeeki.py;h=79960d45422760c24f867238426ee76b8a905af4;hp=e7d7f7d69e63c915c3c3526b5acdcf1307f20733;hb=HEAD;hpb=ad79f3880dad5a6fcc8529d682c263f74c959847 diff --git a/geekigeeki.py b/geekigeeki.py index e7d7f7d..79960d4 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -3,7 +3,7 @@ # # Copyright (C) 1999, 2000 Martin Pool # Copyright (C) 2002 Gerardo Poggiali -# Copyright (C) 2007, 2008, 2009 Bernie Innocenti +# Copyright (C) 2007, 2008, 2009, 2010, 2011 Bernie Innocenti # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -20,16 +20,15 @@ title_done = False import cgi, sys, os, re, errno, stat, glob -image_ext = 'png|gif|jpg|jpeg|bmp|ico' -video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt -image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")$", re.IGNORECASE) +image_ext = 'png|gif|jpg|jpeg|svg|bmp|ico' +video_ext = 'avi|webm|mkv|ogv' +image_re = re.compile(r".*\.(" + image_ext + ")$", re.IGNORECASE) video_re = re.compile(r".*\.(" + video_ext + ")$", re.IGNORECASE) # FIXME: we accept stuff like foo/../bar and we shouldn't -file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)$") +file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/ ]*)$") url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S$") ext_re = re.compile(r"\.([^\./]+)$") -# CGI stuff --------------------------------------------------------- def config_get(key, default=None): return globals().get(key, default) @@ -106,11 +105,15 @@ def url_args(kvargs): return '?' + '&'.join(argv) return '' -# Formatting stuff -------------------------------------------------- def emit_header(mtime=None, mime_type="text/html"): if mtime: + # Prevent caching when the wiki engine gets updated + mtime = max(mtime, os.stat(__file__).st_mtime) print("Last-Modified: " + strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(mtime))) - print("Content-type: " + mime_type + "; charset=utf-8\n") + else: + print("Cache-Control: must-revalidate, max-age=0") + print("Content-type: " + mime_type + "; charset=utf-8") + print('') def send_guru(msg_text, msg_type): if not msg_text: return @@ -120,92 +123,24 @@ def send_guru(msg_text, msg_type): print(cgi.escape(msg_text)) if msg_type == 'error': print '\n Guru Meditation #DEADBEEF.ABADC0DE' - print('' \ + print('' \ % relative_url('sys/GuruMeditation.js')) -def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False, mtime=None): - global title_done - if title_done: return - - # Head - emit_header(mtime) - print('') - print('') - - print("%s: %s" % (config_get('site_name', "Unconfigured Wiki"), text)) - print(' ') - if not name: - print(' ') - - for http_equiv, content in config_get('meta_urls', {}): - print(' ' % (http_equiv, relative_url(content))) - - for link in config_get('link_urls', {}): - rel, href = link - print(' ' % (rel, relative_url(href))) - - editable = name and writable and is_privileged() - if editable: - print(' ' \ - % relative_url('?a=edit&q=' + name, privileged=True)) - - history = config_get('history_url') - if history is not None: - print(' ' \ - % relative_url(history + '?a=rss')) - - print('') - - # Body - if editable: - print('') - else: - print('') - - title_done = True - send_guru(msg_text, msg_type) - - # Navbar - print('') - -def send_httperror(status="403 Not Found", query=""): +def send_httperror(status="404 Not Found", query="", trace=False): print("Status: %s" % status) - send_title(None, msg_text=("%s: on query '%s'" % (status, query))) - send_footer() + msg_text = "%s: on query '%s'" % (status, query) + if trace: + import traceback + msg_text += '\n\n' + traceback.format_exc() + page = Page() + page.send_title(msg_text=msg_text) + page.send_footer() def link_tag(dest, text=None, privileged=False, **kvargs): if text is None: text = humanlink(dest) elif image_re.match(text): - text = '' + text + '' + text = '' + text + '' link_class = kvargs.get('class', kvargs.get('cssclass', None)) if not link_class: @@ -217,9 +152,9 @@ def link_tag(dest, text=None, privileged=False, **kvargs): text = config_get('nonexist_pfx', '') + text link_class = 'nonexistent' - # Prevent crawlers from following links potentially added by spammers or to generated pages + # Prevent crawlers from following links potentially added by spammers and to autogenerated pages nofollow = '' - if link_class == 'external' or link_class == 'navlink': + if link_class in ('external', 'navlink', 'nonexistent'): nofollow = 'rel="nofollow" ' return '%s' % (link_class, nofollow, relative_url(dest, privileged=privileged), text) @@ -228,7 +163,10 @@ def link_inline(name, descr=None, kvargs={}): if not descr: descr = humanlink(name) url = relative_url(name) if video_re.match(name): - return '' % url + args = '' + if 'maxwidth' in kvargs: + args += 'width=' + kvargs['maxwidth'] + return '