X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=4ae17b2996fa0da6f7a0b336c7a1df8a69f81e7d;hb=d27457c46810dade7c3fdbc38c1e0e8e8be424c6;hp=eb51489cddb74e6bf2185f6a0e05ac62ebfb6685;hpb=ce5a4dbd3de540928b7019a716859a551961105c;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index eb51489..4ae17b2 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -8,23 +8,17 @@ # 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 # the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# (at your option) any later version. You should have received a copy +# of the GNU General Public License along with this program. +# If not, see . __version__ = '4.0-' + '$Id$'[4:11] -from time import clock +from time import clock, localtime, gmtime, strftime start_time = clock() title_done = False -import cgi, sys, os, re, errno, stat +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 @@ -36,6 +30,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) + def script_name(): return os.environ.get('SCRIPT_NAME', '') @@ -47,7 +44,7 @@ def query_string(): return os.environ.get('QUERY_STRING', '') or 'FrontPage' def privileged_path(): - return privileged_url or script_name() + return config_get('privileged_url') or script_name() def remote_user(): user = os.environ.get('REMOTE_USER', '') @@ -105,7 +102,9 @@ def url_args(kvargs): return '' # Formatting stuff -------------------------------------------------- -def emit_header(mime_type="text/html"): +def emit_header(mtime=None, mime_type="text/html"): + if mtime: + print("Last-Modified: " + strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(mtime))) print("Content-type: " + mime_type + "; charset=utf-8\n") def send_guru(msg_text, msg_type): @@ -113,47 +112,48 @@ def send_guru(msg_text, msg_type): print('
')
     if msg_type == 'error':
         print('    Software Failure.  Press left mouse button to continue.\n')
-    print(msg_text)
+    print(cgi.escape(msg_text))
     if msg_type == 'error':
         print '\n           Guru Meditation #DEADBEEF.ABADC0DE'
     print('
' \ % relative_url('sys/GuruMeditation.js')) -def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False): +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() + emit_header(mtime) print('') print('') - print("%s: %s" % (site_name, text)) + print("%s: %s" % (config_get('site_name', "Unconfigured Wiki"), text)) print(' ') if not name: print(' ') - for meta in meta_urls: - http_equiv, content = meta + for http_equiv, content in config_get('meta_urls', {}): print(' ' % (http_equiv, relative_url(content))) - for link in link_urls: + for link in config_get('link_urls', {}): rel, href = link print(' ' % (rel, relative_url(href))) - if name and writable and privileged_url is not None: + editable = name and writable and config_get('privileged_url') is not None + if editable: print(' ' \ % (privileged_path() + '?a=edit&q=' + name)) - if history_url is not None: + history = config_get('history_url') + if history is not None: print(' ' \ - % relative_url(history_url + '?a=rss')) + % relative_url(history + '?a=rss')) print('') # Body - if name and writable and privileged_url is not None: + if editable: print('') else: print('') @@ -163,20 +163,20 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Navbar print('