X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=a0dc72ca0629280be7792e5c57d3dee60c5b2525;hb=6002848303f10b453acd930707ea436ec1183725;hp=b52d3522c88d0b5b11a5e6c46463b70a1f92ca52;hpb=84d4dd63eb79f68bec2e6172a9c701575b502243;p=geekigeeki.git
diff --git a/geekigeeki.py b/geekigeeki.py
index b52d352..a0dc72c 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,12 +26,14 @@ title_done = False
import cgi, sys, os, re, errno, stat
+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
+image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")", re.IGNORECASE)
+video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE)
# 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|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$")
-ext_re = re.compile(r"\.([^\./]+)$")
+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 script_name():
@@ -79,7 +81,7 @@ def permalink(s):
return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
def humanlink(s):
- return re.search('([^:/\.]+)(?:\.[^/:]+|)$', s).group(1).replace('_', ' ')
+ return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' '))
# Split arg lists like "blah| blah blah| width=100 | align = center",
# return a list containing anonymous arguments and a map containing the named arguments
@@ -87,10 +89,10 @@ def parse_args(s):
args = []
kwargs = {}
for arg in s.strip('<[{}]>').split('|'):
- try:
- key, val = arg.split('=', 1)
- kwargs[key.strip()] = val.strip()
- except ValueError:
+ m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg)
+ if m is not None:
+ kwargs[m.group(1)] = m.group(2)
+ else:
args.append(arg.strip())
return (args, kwargs)
@@ -173,7 +175,7 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
print(' | Page History')
if name:
- print(' | ' + link_tag('?raw=' + name, 'Raw Text', cssclass='navlink'))
+ print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink'))
if privileged_url is not None:
if writable:
print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', cssclass='navlink', privileged=True))
@@ -197,7 +199,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 = ''
link_class = kvargs.get('class', kvargs.get('cssclass', None))
@@ -222,7 +224,7 @@ 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 '' % (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()
@@ -324,7 +326,7 @@ def make_index_key():
links = ['%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
return '
' + ' | '.join(links) + '
'
-def page_list(dirname = None, re = None):
+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$")
@@ -335,6 +337,7 @@ def send_footer(mod_string=None):
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
+ #FIXME link_inline("sys/footer")
print('''