From: Bernardo Innocenti Date: Sat, 5 Jan 2008 20:22:11 +0000 (+0100) Subject: Support subdirectories (FooBar/FortyTwo) X-Git-Tag: v3.0~41 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=e3e7c9370317666588488fb95e081e02fc107a0d;p=geekigeeki.git Support subdirectories (FooBar/FortyTwo) --- diff --git a/geekigeeki.py b/geekigeeki.py index cd92c54..9c9efc1 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -3,7 +3,7 @@ # # Copyright 1999, 2000 Martin Pool # Copyright 2002 Gerardo Poggiali -# Copyright 2007 Bernardo Innocenti +# Copyright 2007, 2008 Bernardo Innocenti # # 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 @@ -28,8 +28,8 @@ from os import path, environ # Regular expression defining a WikiWord # (but this definition is also assumed in other places) -file_re = re.compile(r"^\b([A-Za-z0-9_\.\-]+)\b$") -word_re = re.compile(r"^\b([A-Z][a-z]+){2,}\b$") +file_re = re.compile(r"^\b([A-Za-z0-9_\.\-/]+)\b$") +word_re = re.compile(r"^\b((([A-Z][a-z]+){2,}/)*([A-Z][a-z]+){2,})\b$") img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg)$", re.IGNORECASE) url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") @@ -60,6 +60,15 @@ def get_hostname(addr): except: return addr +def relative_url(path, privileged=False): + if not (url_re.match(path) or path.startswith('/')): + if privileged: + url = privileged_path() + else: + url = script_name() + path = url + '/' + path + return path + # Formatting stuff -------------------------------------------------- def emit_header(type="text/html"): @@ -114,7 +123,7 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'): if not name: print ' ' for css in css_url: - print ' ' % css + print ' ' % relative_url(css) print '' # Body @@ -143,7 +152,7 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'): if name: print ' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink') if privileged_url is not None: - print ' | ' + link_tag('?edit=' + name, 'Edit Page', 'navlink', authentication=True) + print ' | ' + link_tag('?edit=' + name, 'Edit Page', 'navlink', privileged=True) else: print ' | Immutable Page' @@ -153,7 +162,7 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'): print '
' -def link_tag(params, text=None, ss_class=None, authentication=False): +def link_tag(params, text=None, ss_class=None, privileged=False): if text is None: text = params # default classattr = '' @@ -162,11 +171,7 @@ def link_tag(params, text=None, ss_class=None, authentication=False): # Prevent crawlers from following links potentially added by spammers or to generated pages if ss_class == 'external' or ss_class == 'navlink': classattr += 'rel="nofollow" ' - if authentication: - path = privileged_path() - else: - path = script_name() - return '%s' % (classattr, path, params, text) + return '%s' % (classattr, relative_url(params, privileged=privileged), text) # Search --------------------------------------------------- @@ -379,7 +384,7 @@ class PageFormatter: return Page(word).link_to() def _img_repl(self, word): - path = script_name() + '/' + word; + path = relative_url(word) return '' % (path, path) def _url_repl(self, word): @@ -397,7 +402,8 @@ class PageFormatter: if macro: return apply(macro, (name, descr)) elif img_re.match(name): - return '
%s
%s
' % (name, name, descr, descr) + # The "extthumb" nonsense works around a limitation of the HTML block model + return '
%s
%s
' % (name, name, descr, descr) else: if img_re.match(descr): descr = '' @@ -685,7 +691,7 @@ class Page: + ' for ' + cgi.escape(remote_user()) + ' from ' + cgi.escape(get_hostname(remote_host())) + '

') - print '
' % (script_name(), self.page_name) + print '
' % relative_url(self.page_name) print '' % (self.page_name) print """""" % (preview or self.get_raw_body()) print """