projects
/
geekigeeki.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allow specifying CSS class for thumbnails
[geekigeeki.git]
/
geekigeeki.py
diff --git
a/geekigeeki.py
b/geekigeeki.py
index 6170d7394ca6bb7b91d3fdb195d0d2ba6a5b4503..b8aeee89402cddc8bfe65b947e63c12d550cad27 100755
(executable)
--- a/
geekigeeki.py
+++ b/
geekigeeki.py
@@
-22,12
+22,10
@@
__version__ = '$Id$'[4:12]
from time import clock
start_time = clock()
from time import clock
start_time = clock()
+title_done = False
import cgi, sys, os, re, errno, stat
import cgi, sys, os, re, errno, stat
-# Regular expression defining a WikiWord
-# (but this definition is also assumed in other places)
-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|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", 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)
@@
-35,8
+33,6
@@
video_re = re.compile(r"^.*\.(ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re
url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$")
ext_re = re.compile(r"\.([^\./]+)$")
url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$")
ext_re = re.compile(r"\.([^\./]+)$")
-title_done = False
-
# CGI stuff ---------------------------------------------------------
def script_name():
return os.environ.get('SCRIPT_NAME', '')
# CGI stuff ---------------------------------------------------------
def script_name():
return os.environ.get('SCRIPT_NAME', '')
@@
-82,6
+78,9
@@
def relative_url(pathname, privileged=False):
def permalink(s):
return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
def permalink(s):
return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
+def humanlink(s):
+ return re.search('([^:/\.]+)(?:\.[^/:]+|)$', s).group(1).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
def parse_args(s):
# 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):
@@
-197,7
+196,7
@@
def send_httperror(status="403 Not Found", query=""):
def link_tag(params, text=None, link_class=None, privileged=False, **kvargs):
if text is None:
def link_tag(params, text=None, link_class=None, privileged=False, **kvargs):
if text is None:
- text =
params # default
+ text =
humanlink(params)
elif img_re.match(text):
text = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
elif img_re.match(text):
text = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
@@
-218,7
+217,7
@@
def link_tag(params, text=None, link_class=None, privileged=False, **kvargs):
return '<a %shref="%s">%s</a>' % (classattr, relative_url(params, privileged=privileged), text)
def link_inline(name, descr=None, kvargs={}):
return '<a %shref="%s">%s</a>' % (classattr, relative_url(params, privileged=privileged), text)
def link_inline(name, descr=None, kvargs={}):
- if not descr: descr =
name
+ if not descr: descr =
humanlink(name)
url = relative_url(name)
if video_re.match(name):
return '<video src="%s">Your browser does not support the HTML5 video tag</video>' % url
url = relative_url(name)
if video_re.match(name):
return '<video src="%s">Your browser does not support the HTML5 video tag</video>' % url
@@
-264,7
+263,6
@@
def handle_fullsearch(query, form):
print_search_stats(len(hits), len(all_pages))
def handle_titlesearch(query, form):
print_search_stats(len(hits), len(all_pages))
def handle_titlesearch(query, form):
- # TODO: check needle is legal -- but probably we can just accept any RE
needle = form['q'].value
send_title(None, 'Title search for "' + needle + '"')
needle = form['q'].value
send_title(None, 'Title search for "' + needle + '"')
@@
-325,7
+323,10
@@
def make_index_key():
links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
return '<p style="text-align: center">' + ' | '.join(links) + '</p>'
links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
return '<p style="text-align: center">' + ' | '.join(links) + '</p>'
-def page_list(dirname = None, re = word_re):
+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)))
def send_footer(mod_string=None):
return sorted(filter(re.match, os.listdir(dirname or data_dir)))
def send_footer(mod_string=None):
@@
-414,8
+415,9
@@
class WikiFormatter:
name = args.pop(0)
if len(args):
descr = args.pop(0)
name = args.pop(0)
if len(args):
descr = args.pop(0)
- # The "extthumb" nonsense works around a limitation of the HTML block model
- return '<div class="extthumb"><div class="thumb">' \
+ # This double div nonsense works around a limitation of the HTML block model
+ return '<div class="' + kvargs.get('class', 'thumb') + '">' \
+ + '<div class="innerthumb">' \
+ link_inline(name, descr, kvargs) \
+ '<div class="caption">' + descr + '</div></div></div>'
else:
+ link_inline(name, descr, kvargs) \
+ '<div class="caption">' + descr + '</div></div></div>'
else:
@@
-648,8
+650,8
@@
class Page:
for filename in page_list(self._filename(), file_re):
if img_re.match(filename):
if image_maxwidth:
for filename in page_list(self._filename(), file_re):
if img_re.match(filename):
if image_maxwidth:
- maxwidth_arg = '
|
maxwidth=' + str(image_maxwidth)
- out += '{{' + self.page_name + '/' + filename + '
|' + filename + maxwidth_arg + '
}}\n'
+ maxwidth_arg = '
|
maxwidth=' + str(image_maxwidth)
+ out += '{{' + self.page_name + '/' + filename + '
| ' + humanlink(filename) + maxwidth_arg + ' | class=thumbleft
}}\n'
else:
out += ' * [[' + self.page_name + '/' + filename + ']]\n'
return out
else:
out += ' * [[' + self.page_name + '/' + filename + ']]\n'
return out