X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=9c9efc16a65e61ce1dc9199df4cec036a141ae7e;hb=e3e7c9370317666588488fb95e081e02fc107a0d;hp=a0345ee950f0c0fc750e874717dc9d5e34ddbad6;hpb=727c1cfdb0040ca5d95efb81c975d36d1f568c0b;p=geekigeeki.git
diff --git a/geekigeeki.py b/geekigeeki.py
index a0345ee..9c9efc1 100755
--- a/geekigeeki.py
+++ b/geekigeeki.py
@@ -1,8 +1,9 @@
-#! /usr/bin/env python
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
#
# 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
@@ -17,15 +18,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-__version__ = '$Id$'[4:-2]
+__version__ = '$Id$'[4:12]
-import cgi, sys, string, os, re, errno, time, stat
+from time import clock
+start_time = clock()
+
+import cgi, sys, string, os, re, errno, stat
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$")
@@ -56,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"):
@@ -100,16 +113,17 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'):
# Head
emit_header()
- print """
-
-"""
+ print ''
+ print ''
+
+ site_name = globals().get('site_name', 'Unconfigured Site')
print "%s: %s" % (site_name, text)
print ' '
if not name:
print ' '
- if css_url:
- print ' ' % css_url
+ for css in css_url:
+ print ' ' % relative_url(css)
print ''
# Body
@@ -125,18 +139,20 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'):
print '
'
print ""
print_search_stats(len(hits), len(all_pages))
-
def do_titlesearch(needle):
# TODO: check needle is legal -- but probably we can just accept any RE
send_title(None, "Title search for \"" + needle + '"')
@@ -206,10 +217,10 @@ def do_titlesearch(needle):
print_search_stats(len(hits), len(all_pages))
-
def print_search_stats(hits, searched):
print "
%d hits out of %d pages searched.
" % (hits, searched)
+#TODO: merge into do_savepage()
def do_edit(pagename):
Page(pagename).send_editor()
@@ -239,26 +250,23 @@ def make_index_key():
s = s + '
'
return s
-
def page_list():
- return filter(word_re.match, os.listdir(text_dir))
-
+ return filter(word_re.match, os.listdir(data_dir))
def send_footer(name, mod_string=None):
- if debug_cgi:
+ if globals().get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(cgi.FieldStorage())
cgi.print_environ()
global __version__
print ''
-
# ----------------------------------------------------------
# Macros
def _macro_TitleSearch(*vargs):
@@ -292,7 +300,7 @@ def _macro_WordIndex(*vargs):
# set title
for word in all_words:
letter = string.lower(word[0])
- if letter <> last_letter:
+ if letter != last_letter:
s = s + ';
' % (letter, letter)
last_letter = letter
@@ -314,7 +322,7 @@ def _macro_TitleIndex(*vargs):
current_letter = None
for name in pages:
letter = string.lower(name[0])
- if letter <> current_letter:
+ if letter != current_letter:
s = s + '