X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=d208bb723fa672890c99155a6791d93d921c29da;hb=3f737b8a960486cd16aaa4acacc83acb24c7d42f;hp=ca16283d5ea2f2c78c573b3863a371add9c15aef;hpb=7ce906e26b7c2c91e232508ccd0af6fe9ec4aeec;p=geekigeeki.git
diff --git a/geekigeeki.py b/geekigeeki.py
index ca16283..d208bb7 100755
--- a/geekigeeki.py
+++ b/geekigeeki.py
@@ -3,7 +3,7 @@
#
# Copyright 1999, 2000 Martin Pool
# Copyright 2002 Gerardo Poggiali
-# Copyright 2007, 2008 Bernie Innocenti
+# Copyright 2007, 2008, 2009 Bernie 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
@@ -30,18 +30,25 @@ import cgi, sys, os, re, errno, stat
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)$", re.IGNORECASE)
+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("(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})")
+link_re = re.compile(r"(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})")
+ext_re = re.compile(r"\.([^\./]+)$")
title_done = False
-
# CGI stuff ---------------------------------------------------------
-
def script_name():
return os.environ.get('SCRIPT_NAME', '')
+def query_string():
+ path_info = os.environ.get('PATH_INFO', '')
+ if len(path_info) and path_info[0] == '/':
+ return path_info[1:] or 'FrontPage'
+ else:
+ return os.environ.get('QUERY_STRING', '') or 'FrontPage'
+
def privileged_path():
return privileged_url or script_name()
@@ -61,14 +68,17 @@ def get_hostname(addr):
except Exception:
return addr
+def is_external_url(pathname):
+ return (url_re.match(pathname) or pathname.startswith('/'))
+
def relative_url(pathname, privileged=False):
- if not (url_re.match(pathname) or pathname.startswith('/')):
+ if not is_external_url(pathname):
if privileged:
url = privileged_path()
else:
url = script_name()
pathname = url + '/' + pathname
- return pathname
+ return cgi.escape(pathname, quote=True)
def permalink(s):
return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
@@ -84,30 +94,9 @@ def send_guru(msg_text, msg_type):
print(' Software Failure. Press left mouse button to continue.\n')
print(msg_text)
if msg_type == 'error':
- print('\n Guru Meditation #DEADBEEF.ABADC0DE')
- print('')
- # FIXME: This little JS snippet is harder to pass than ACID 3.0
- print("""
- """)
+ 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):
global title_done
@@ -153,11 +142,11 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
# Navbar
print('')
+ print link_tag('FrontPage', site_icon or 'Home', 'navlink')
if name:
print('
' + link_tag('?fullsearch=' + name, text, 'navlink') + ' ')
else:
print('
' + text + ' ')
- print(' | ' + link_tag('FrontPage', 'Home', 'navlink'))
print(' | ' + link_tag('FindPage', 'Find Page', 'navlink'))
if 'history_url' in globals():
print(' |
Recent Changes')
@@ -177,7 +166,7 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
user = remote_user()
if user != 'AnonymousCoward':
- print(' |
logged in as ' + cgi.escape(user) + '')
+ print(' |
' + link_tag('User/' + user, user) + '')
print('
')
@@ -186,19 +175,41 @@ def send_httperror(status="403 Not Found", query=""):
send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
send_footer()
-def link_tag(params, text=None, ss_class=None, privileged=False):
+def link_tag(params, text=None, link_class=None, privileged=False):
if text is None:
text = params # default
- classattr = ''
- if ss_class:
- classattr += 'class="%s" ' % ss_class
- # Prevent crawlers from following links potentially added by spammers or to generated pages
- if ss_class == 'external' or ss_class == 'navlink':
- classattr += 'rel="nofollow" '
- elif url_re.match(params):
- classattr += 'rel="nofollow" '
+ elif img_re.match(text):
+ text = ''
+
+ if not link_class:
+ if is_external_url(params):
+ link_class = 'external'
+ elif file_re.match(params) and Page(params).exists():
+ link_class = 'wikilink'
+ else:
+ params = nonexist_pfx + params
+ link_class = 'nonexistent'
+
+ classattr = 'class="%s" ' % link_class
+ # Prevent crawlers from following links potentially added by spammers or to generated pages
+ if link_class == 'external' or link_class == 'navlink':
+ classattr += 'rel="nofollow"'
+
return '%s' % (classattr, relative_url(params, privileged=privileged), text)
+def link_inline(name, descr=None, args=''):
+ if not descr: descr = name
+ url = relative_url(name)
+ if video_re.match(name):
+ return '' % url
+ elif img_re.match(name):
+ return '' % (url, url + args, descr)
+ elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
+ return Page(name).send_naked()
+ else:
+ return '' \
+ % (url, url, name)
+
# Search ---------------------------------------------------
def handle_fullsearch(needle):
@@ -220,8 +231,8 @@ def handle_fullsearch(needle):
print("")
for (count, page_name) in hits:
- print('' + Page(page_name).link_to())
- print(' . . . . ' + repr(count))
+ print('
' + link_tag(page_name))
+ print(' . . . . ' + `count`)
print(['match', 'matches'][count != 1])
print('
')
print("
")
@@ -238,7 +249,7 @@ def handle_titlesearch(needle):
print("")
print_search_stats(len(hits), len(all_pages))
@@ -275,9 +286,10 @@ def handle_edit(pagename):
text = form['savetext'].value
pg.send_editor(text)
+# Used by macros/WordIndex and macros/TitleIndex
def make_index_key():
links = ['%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
- return ''+ ' | '.join(links) + '
'
+ return '' + ' | '.join(links) + '
'
def page_list(dirname = None, re = word_re):
return sorted(filter(re.match, os.listdir(dirname or data_dir)))
@@ -290,10 +302,10 @@ def send_footer(mod_string=None):
print('''