')
- print link_tag('FrontPage', site_icon or 'Home', 'navlink')
+ print link_tag('FrontPage', site_icon or 'Home', cssclass='navlink')
if name:
- print(' ' + link_tag('?fullsearch=' + name, text, 'navlink') + ' ')
+ print(' ' + link_tag('?fullsearch=' + name, text, cssclass='navlink') + ' ')
else:
print(' ' + text + ' ')
- print(' | ' + link_tag('FindPage', 'Find Page', 'navlink'))
+ print(' | ' + link_tag('FindPage', 'Find Page', cssclass='navlink'))
if 'history_url' in globals():
print(' | Recent Changes')
if name:
print(' | Page History')
if name:
- print(' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink'))
+ print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink'))
if privileged_url is not None:
if writable:
- print(' | ' + link_tag('?edit=' + 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(' | Immutable Page')
@@ -195,34 +198,35 @@ def send_httperror(status="403 Not Found", query=""):
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 = params # default
- elif img_re.match(text):
+ text = humanlink(dest)
+ elif image_re.match(text):
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 '%s' % (classattr, relative_url(params, privileged=privileged), text)
+ return '%s' % (link_class, nofollow, relative_url(dest, 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 '' % url
- elif img_re.match(name):
+ return '' % url
+ 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()
@@ -232,8 +236,12 @@ def link_inline(name, descr=None, kvargs={}):
# Search ---------------------------------------------------
-def handle_fullsearch(needle):
- send_title(None, 'Full text search for "%s"' % (needle))
+def print_search_stats(hits, searched):
+ print("
%d hits out of %d pages searched.
" % (hits, searched))
+
+def handle_fullsearch(query, form):
+ needle = form['q'].value
+ send_title(None, 'Full text search for "' + needle + '"')
needle_re = re.compile(needle, re.IGNORECASE)
hits = []
@@ -259,9 +267,9 @@ def handle_fullsearch(needle):
print_search_stats(len(hits), len(all_pages))
-def handle_titlesearch(needle):
- # TODO: check needle is legal -- but probably we can just accept any RE
- send_title(None, "Title search for \"" + needle + '"')
+def handle_titlesearch(query, form):
+ needle = form['q'].value
+ send_title(None, 'Title search for "' + needle + '"')
needle_re = re.compile(needle, re.IGNORECASE)
all_pages = page_list()
@@ -274,22 +282,19 @@ def handle_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))
-
-def handle_raw(pagename):
+def handle_raw(pagename, form):
if not file_re.match(pagename):
send_httperror("403 Forbidden", pagename)
return
Page(pagename).send_raw()
-def handle_edit(pagename):
+def handle_edit(pagename, form):
if not file_re.match(pagename):
send_httperror("403 Forbidden", pagename)
return
- pg = Page(pagename)
+ pg = Page(form['q'].value)
if 'save' in form:
if form['file'].value:
pg.save(form['file'].file.read(), form['changelog'].value)
@@ -306,28 +311,44 @@ def handle_edit(pagename):
text = form['savetext'].value
pg.send_editor(text)
+def handle_get(pagename, form):
+ if file_re.match(pagename):
+ # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
+ from mimetypes import MimeTypes
+ mimetype, encoding = MimeTypes().guess_type(pagename)
+ if mimetype:
+ Page(pagename).send_raw(mimetype=mimetype, args=form)
+ else:
+ Page(pagename).format()
+ else:
+ send_httperror("403 Forbidden", pagename)
+
# Used by macros/WordIndex and macros/TitleIndex
def make_index_key():
links = ['%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
return '
' + ' | '.join(links) + '
'
-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):
+def send_footer(mtime=None):
if globals().get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
+ #FIXME link_inline("sys/footer")
print('''
')
class WikiFormatter:
@@ -349,6 +370,7 @@ class WikiFormatter:
"**": ["b", False],
"##": ["tt", False],
"__": ["u", False],
+ "--": ["del", False],
"^^": ["sup", False],
",,": ["sub", False],
"''": ["em", False], # LEGACY
@@ -361,6 +383,9 @@ class WikiFormatter:
style[1] = not style[1]
return ['', '<'][style[1]] + style[0] + '>'
+ def _glyph_repl(self, word):
+ return '—'
+
def _tit_repl(self, word):
if self.h_level:
result = '
\n' % self.h_level
@@ -400,8 +425,9 @@ class WikiFormatter:
name = args.pop(0)
if len(args):
descr = args.pop(0)
- # The "extthumb" nonsense works around a limitation of the HTML block model
- return '
' \
+ # This double div nonsense works around a limitation of the HTML block model
+ return '
' \
+ + '
' \
+ link_inline(name, descr, kvargs) \
+ '
' + descr + '
'
else:
@@ -515,29 +541,30 @@ class WikiFormatter:
print('