X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=73c45ce41d3f36a82c5adedacb370a930b1c9e14;hb=341fe4ae99533d8ce81d9dcd1fa973ce5796923c;hp=afaebefc6a4321560a861d04f174c7d8661a304b;hpb=3cebb905becc61868f9431c2cf8939d1f1cd198e;p=geekigeeki.git
diff --git a/geekigeeki.py b/geekigeeki.py
index afaebef..73c45ce 100755
--- a/geekigeeki.py
+++ b/geekigeeki.py
@@ -18,7 +18,7 @@
# 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()
@@ -26,15 +26,19 @@ title_done = False
import cgi, sys, os, re, errno, stat
-# FIXME: we accept stuff like foo/../bar and we shouldn't
-file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)")
+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
-img_re = re.compile(r".*\.(png|gif|jpg|jpeg|bmp|ico|" + video_ext + ")", re.IGNORECASE)
+image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")", re.IGNORECASE)
video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE)
-url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S")
-ext_re = re.compile(r"\.([^\./]+)$")
+# FIXME: we accept stuff like foo/../bar and we shouldn't
+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 config_get(key, default=None):
+ return globals().get(key, default)
+
def script_name():
return os.environ.get('SCRIPT_NAME', '')
@@ -82,18 +86,18 @@ def permalink(s):
def humanlink(s):
return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' '))
-# Split arg lists like "blah| blah blah| width=100 | align = center",
+# 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 = {}
+ kvargs = {}
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)
+ kvargs[m.group(1)] = m.group(2)
else:
args.append(arg.strip())
- return (args, kwargs)
+ return (args, kvargs)
def url_args(kvargs):
argv = []
@@ -128,16 +132,15 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
print(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
print('')
- print("
%s: %s" % (site_name, text))
+ print("%s: %s" % (config_get('site_name', "Unconfigured Wiki"), text))
print(' ')
if not name:
print(' ')
- for meta in meta_urls:
- http_equiv, content = meta
+ for http_equiv, content in config_get('meta_urls', {}):
print(' ' % (http_equiv, relative_url(content)))
- for link in link_urls:
+ for link in config_get('link_urls', {}):
rel, href = link
print(' ' % (rel, relative_url(href)))
@@ -145,9 +148,10 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
print(' ' \
% (privileged_path() + '?a=edit&q=' + name))
- if history_url is not None:
+ history = config_get('history_url')
+ if history is not None:
print(' ' \
- % relative_url(history_url + '?a=rss'))
+ % relative_url(history + '?a=rss'))
print('')
@@ -162,16 +166,16 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
# Navbar
print('')
- print link_tag('FrontPage', site_icon or 'Home', cssclass='navlink')
+ print link_tag('FrontPage', config_get('site_icon', 'Home'), cssclass='navlink')
if name:
print('
' + link_tag('?fullsearch=' + name, text, cssclass='navlink') + ' ')
else:
print('
' + text + ' ')
print(' | ' + link_tag('FindPage', 'Find Page', cssclass='navlink'))
- if 'history_url' in globals():
- print(' |
Recent Changes')
+ if history:
+ print(' |
Recent Changes')
if name:
- print(' |
Page History')
+ print(' |
Page History')
if name:
print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink'))
@@ -198,7 +202,7 @@ def send_httperror(status="403 Not Found", query=""):
def link_tag(dest, text=None, privileged=False, **kvargs):
if text is None:
text = humanlink(dest)
- elif img_re.match(text):
+ elif image_re.match(text):
text = '
![' + text + '](' + relative_url(text) + ')
'
link_class = kvargs.get('class', kvargs.get('cssclass', None))
@@ -208,7 +212,7 @@ def link_tag(dest, text=None, privileged=False, **kvargs):
elif file_re.match(dest) and Page(dest).exists():
link_class = 'wikilink'
else:
- text = nonexist_pfx + text
+ text = config_get('nonexist_pfx', '') + text
link_class = 'nonexistent'
# Prevent crawlers from following links potentially added by spammers or to generated pages
@@ -223,10 +227,10 @@ def link_inline(name, descr=None, kvargs={}):
url = relative_url(name)
if video_re.match(name):
return '
' % url
- elif img_re.match(name):
+ elif image_re.match(name):
return '
![%s](%s)
' % (url, url + url_args(kvargs), descr)
elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
- return Page(name).send_naked()
+ return Page(name).send_naked(kvargs)
else:
return '
' \
% (url, url, name)
@@ -329,23 +333,21 @@ def page_list(dirname=None, re=None):
if re is None:
# FIXME: WikiWord is too restrictive now!
re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
- return sorted(filter(re.match, os.listdir(dirname or data_dir)))
+ return sorted(filter(re.match, os.listdir(dirname or config_get(data_dir, ''))))
def send_footer(mod_string=None):
- if globals().get('debug_cgi', False):
+ if config_get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
- print('''
-')
+ link_inline("sys/footer", kvargs= { 'LAST_MODIFIED': mod_string })
+ print("