X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=geekigeeki.py;h=470752de0d44076f31272693a206bf0a1ed9cdc2;hb=0a5c27be02429f5fb00be79c4e11b70666713530;hp=8bd3e0b9be13ec871c6fe3aea0ed84966a2682ff;hpb=f4934967798c0c68c535bc2fa6cb26fff82512ff;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index 8bd3e0b..470752d 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -22,12 +22,10 @@ __version__ = '$Id$'[4:12] 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$") # 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) @@ -35,8 +33,6 @@ video_re = re.compile(r"^.*\.(ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") ext_re = re.compile(r"\.([^\./]+)$") -title_done = False - # CGI stuff --------------------------------------------------------- def script_name(): return os.environ.get('SCRIPT_NAME', '') @@ -82,16 +78,19 @@ 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('|'): - try: - key, val = arg.split('=', 1) - kwargs[key.strip()] = val.strip() - except ValueError: + 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) @@ -143,7 +142,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(' ' \ @@ -153,7 +152,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('') @@ -162,24 +161,24 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Navbar print('