X-Git-Url: https://codewiz.org/gitweb?p=geekigeeki.git;a=blobdiff_plain;f=geekigeeki.py;h=71920f370b9dd74f6c0df8b057bf308a404fa9f0;hp=d208bb723fa672890c99155a6791d93d921c29da;hb=093f6c0344c19dcdf8d3bb7e437dd9c45a5982f9;hpb=3f737b8a960486cd16aaa4acacc83acb24c7d42f diff --git a/geekigeeki.py b/geekigeeki.py index d208bb7..71920f3 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3.0 +#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright 1999, 2000 Martin Pool @@ -18,25 +18,22 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '$Id$'[4:12] +__version__ = '4.0-' + '$Id$'[4:11] from time import clock start_time = clock() +title_done = False import cgi, sys, os, re, errno, stat -# Regular expression defining a WikiWord -# (but this definition is also assumed in other places) -word_re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$") +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) +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"^\b([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)\b$") -img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE) -video_re = re.compile(r"^.*\.(ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE) -url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") -link_re = re.compile(r"(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})") -ext_re = re.compile(r"\.([^\./]+)$") - -title_done = False +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 script_name(): @@ -83,6 +80,30 @@ def relative_url(pathname, privileged=False): def permalink(s): return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip()) +def humanlink(s): + return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' ')) + +# Split arg lists like "blah| blah blah| width=100 | align = center", +# return a list containing anonymous arguments and a map containing the named arguments +def parse_args(s): + args = [] + kwargs = {} + for arg in s.strip('<[{}]>').split('|'): + m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg) + if m is not None: + kwargs[m.group(1)] = m.group(2) + else: + args.append(arg.strip()) + return (args, kwargs) + +def url_args(kvargs): + argv = [] + for k, v in kvargs.items(): + argv.append(k + '=' + v) + if argv: + return '?' + '&'.join(argv) + return '' + # Formatting stuff -------------------------------------------------- def emit_header(mime_type="text/html"): print("Content-type: " + mime_type + "; charset=utf-8\n") @@ -123,7 +144,7 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal if name and writable and privileged_url is not None: print(' ' \ - % (privileged_path() + '?edit=' + name)) + % (privileged_path() + '?a=edit&q=' + name)) if history_url is not None: print(' ' \ @@ -133,7 +154,7 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Body if name and writable and privileged_url is not None: - print('') + print('') else: print('') @@ -142,24 +163,24 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Navbar print('