X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=geekigeeki.py;h=9d2bf9e12e8dea0617622960871baa95a990d753;hb=bfa2f63dc09c936f10b7cc3c1ee0c1c136af3591;hp=4569894255a653ab73d6312e6a7f62354808ed0d;hpb=2776ec9d104a0cd3fefb2ebb09bf32f4f13cc80a;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index 4569894..9d2bf9e 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -36,6 +36,10 @@ def config_get(key, default=None): def script_name(): return os.environ.get('SCRIPT_NAME', '') +#TODO: move post-edit hook into wiki, then kill this +def script_path(): + return os.path.split(os.environ.get('SCRIPT_FILENAME', ''))[0] + def query_string(): path_info = os.environ.get('PATH_INFO', '') if len(path_info) and path_info[0] == '/': @@ -43,8 +47,9 @@ def query_string(): else: return os.environ.get('QUERY_STRING', '') or 'FrontPage' -def privileged_path(): - return config_get('privileged_url') or script_name() +def is_privileged(): + purl = config_get('privileged_url') + return (purl is not None) and os.environ.get('SCRIPT_URI', '').startswith(purl) def remote_user(): user = os.environ.get('REMOTE_USER', '') @@ -68,7 +73,7 @@ def is_external_url(pathname): def relative_url(pathname, privileged=False): if not is_external_url(pathname): if privileged: - url = privileged_path() + url = config_get('privileged_url') or script_name() else: url = script_name() pathname = url + '/' + pathname @@ -140,10 +145,10 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal rel, href = link print(' ' % (rel, relative_url(href))) - editable = name and writable and config_get('privileged_url') is not None + editable = name and writable and is_privileged() if editable: print(' ' \ - % (privileged_path() + '?a=edit&q=' + name)) + % relative_url('?a=edit&q=' + name, privileged=True)) history = config_get('history_url') if history is not None: @@ -154,7 +159,7 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Body if editable: - print('
') + print('') else: print('') @@ -234,10 +239,13 @@ def link_inline(name, descr=None, kvargs={}): % (url, url, name) def link_inline_glob(pattern, descr=None, kvargs={}): - s = '' - for name in glob.glob(pattern): - s += link_inline(name, descr, kvargs) - return s + if not url_re.match(pattern) and bool(set(pattern) & set('?*[')): + s = '' + for name in glob.glob(pattern): + s += link_inline(name, descr, kvargs) + return s + else: + return link_inline(pattern, descr, kvargs) # Search --------------------------------------------------- @@ -345,7 +353,7 @@ def send_footer(mtime=None): cgi.print_form(form) cgi.print_environ() link_inline("sys/footer", kvargs = { - 'LAST_MODIFIED': strftime(config_get(datetime_fmt, '%a %d %b %Y %I:%M %p'), localtime(mtime)) + 'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%a %d %b %Y %I:%M %p'), localtime(mtime)) }) print("") @@ -367,7 +375,7 @@ class WikiFormatter: self.h_level = 0 self.in_pre = self.in_html = self.in_table = self.in_li = False self.in_header = True - self.list_indents = [] + self.list_indents = [] # a list of pairs (indent_level, list_type) to track nested lists self.tr_cnt = 0 self.styles = { #wiki html enabled? @@ -405,7 +413,7 @@ class WikiFormatter: return '' return s - def _undent(self): - res = '
' - res += ''
- self.list_indents = []
- return res
-
def replace(self, match):
for rule, hit in list(match.groupdict().items()):
if hit:
@@ -588,7 +591,7 @@ class WikiFormatter:
| (?P
') else: indent = indent_re.match(self.line) - #3.0: print(self._indent_to(len(indent.group(0))), end=' ') - print(self._indent_to(len(indent.group(0)))) + print(self._indent_to(len(indent.group(1)), indent.group(2))) + # Stand back! Here we apply the monster regex that does all the parsing print(re.sub(scan_re, self.replace, self.line)) if self.in_pre: print('') if self.in_table: print('
') - print(self._undent()) + print(self._indent_to(0)) print('
') class Page: @@ -665,13 +668,13 @@ class Page: out = '== ' pathname = '' for dirname in self.page_name.strip('/').split('/'): - pathname = (pathname + '/' + dirname) if pathname else dirname + pathname = (pathname and pathname + '/' ) + dirname out += '[[' + pathname + '|' + dirname + ']]/' out += ' ==\n' for filename in page_list(self._filename(), file_re): if image_re.match(filename): - maxwidth = config_get(image_maxwidth, '') + maxwidth = config_get('image_maxwidth', '400') if maxwidth: maxwidth = ' | maxwidth=' + str(maxwidth) out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth + ' | class=thumbleft}}\n' @@ -693,7 +696,7 @@ class Page: #print "bernie: pragmas[" + m.group(1) + "] = " + m.group(2) + "