from time import clock
start_time = clock()
+title_done = False
import cgi, sys, os, re, errno, stat
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', '')
return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
def humanlink(s):
- return re.compile('([^:/\.]+)(?:\.[^/:]+|)$').search(s).group(1).replace('_', ' ')
+ 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
# Navbar
print('<div class="nav">')
- print link_tag('FrontPage', site_icon or 'Home', 'navlink')
+ print link_tag('FrontPage', site_icon or 'Home', cssclass='navlink')
if name:
- print(' <b>' + link_tag('?fullsearch=' + name, text, 'navlink') + '</b> ')
+ print(' <b>' + link_tag('?fullsearch=' + name, text, cssclass='navlink') + '</b> ')
else:
print(' <b>' + text + '</b> ')
- print(' | ' + link_tag('FindPage', 'Find Page', 'navlink'))
+ print(' | ' + link_tag('FindPage', 'Find Page', cssclass='navlink'))
if 'history_url' in globals():
print(' | <a href="' + relative_url(history_url) + '" class="navlink">Recent Changes</a>')
if name:
print(' | <a href="' + relative_url(history_url + '?a=history;f=' + name) + '" class="navlink">Page History</a>')
if name:
- print(' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink'))
+ print(' | ' + link_tag('?raw=' + name, 'Raw Text', cssclass='navlink'))
if privileged_url is not None:
if writable:
- print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', 'navlink', privileged=True))
+ print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', cssclass='navlink', privileged=True))
else:
- print(' | ' + link_tag(name, 'Login', 'navlink', privileged=True))
+ print(' | ' + link_tag(name, 'Login', cssclass='navlink', privileged=True))
else:
print(' | <i>Immutable Page</i>')
send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
send_footer()
-def link_tag(params, text=None, link_class=None, privileged=False, **kvargs):
+def link_tag(dest, text=None, privileged=False, **kvargs):
if text is None:
- text = humanlink(params)
+ text = humanlink(dest)
elif img_re.match(text):
text = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
+ link_class = kvargs.get('class', kvargs.get('cssclass', None))
if not link_class:
- if is_external_url(params):
+ if is_external_url(dest):
link_class = 'external'
- elif file_re.match(params) and Page(params).exists():
+ elif file_re.match(dest) and Page(dest).exists():
link_class = 'wikilink'
else:
- params = nonexist_pfx + params
+ text = nonexist_pfx + text
link_class = 'nonexistent'
- classattr = 'class="%s" ' % link_class
# Prevent crawlers from following links potentially added by spammers or to generated pages
+ nofollow = ''
if link_class == 'external' or link_class == 'navlink':
- classattr += 'rel="nofollow"'
+ nofollow = 'rel="nofollow" '
- return '<a %shref="%s">%s</a>' % (classattr, relative_url(params, privileged=privileged), text)
+ return '<a class="%s" %shref="%s">%s</a>' % (link_class, nofollow, relative_url(dest, privileged=privileged), text)
def link_inline(name, descr=None, kvargs={}):
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
+ return '<video controls="1" src="%s">Your browser does not support the HTML5 video tag</video>' % url
elif img_re.match(name):
return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (url, url + url_args(kvargs), descr)
elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
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 + '"')
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:
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 + '|' + humanlink(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