ext_re = re.compile(r"\.([^\./]+)$")
# CGI stuff ---------------------------------------------------------
+def config_get(key, default=None):
+ return globals().get(key, default)
+
def script_name():
return os.environ.get('SCRIPT_NAME', '')
print(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
print('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">')
- print("<head><title>%s: %s</title>" % (site_name, text))
+ print("<head><title>%s: %s</title>" % (config_get('site_name', "Unconfigured Wiki"), text))
print(' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />')
if not name:
print(' <meta name="robots" content="noindex,nofollow" />')
- for meta in meta_urls:
- http_equiv, content = meta
+ for http_equiv, content in config_get('meta_urls', {}):
print(' <meta http-equiv="%s" content="%s" />' % (http_equiv, relative_url(content)))
- for link in link_urls:
+ for link in config_get('link_urls', {}):
rel, href = link
print(' <link rel="%s" href="%s" />' % (rel, relative_url(href)))
print(' <link rel="alternate" type="application/x-wiki" title="Edit this page" href="%s" />' \
% (privileged_path() + '?a=edit&q=' + name))
- if history_url is not None:
+ history = config_get('history_url')
+ if history is not None:
print(' <link rel="alternate" type="application/rss+xml" title="RSS" href="%s" />' \
- % relative_url(history_url + '?a=rss'))
+ % relative_url(history + '?a=rss'))
print('</head>')
# Navbar
print('<div class="nav">')
- print link_tag('FrontPage', site_icon or 'Home', cssclass='navlink')
+ print link_tag('FrontPage', config_get('site_icon', 'Home'), cssclass='navlink')
if name:
print(' <b>' + link_tag('?fullsearch=' + name, text, cssclass='navlink') + '</b> ')
else:
print(' <b>' + text + '</b> ')
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 history:
+ print(' | <a href="' + relative_url(history) + '" class="navlink">Recent Changes</a>')
if name:
- print(' | <a href="' + relative_url(history_url + '?a=history;f=' + name) + '" class="navlink">Page History</a>')
+ print(' | <a href="' + relative_url(history + '?a=history;f=' + name) + '" class="navlink">Page History</a>')
if name:
print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink'))
elif file_re.match(dest) and Page(dest).exists():
link_class = 'wikilink'
else:
- text = nonexist_pfx + text
+ text = config_get('nonexist_pfx', '') + text
link_class = 'nonexistent'
# Prevent crawlers from following links potentially added by spammers or to generated pages
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)))
+ return sorted(filter(re.match, os.listdir(dirname or config_get(data_dir, ''))))
def send_footer(mod_string=None):
- if globals().get('debug_cgi', False):
+ if config_get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
if hit:
return getattr(self, '_' + rule + '_repl')(hit)
else:
- raise "Can't handle match " + repr(match)
+ raise Exception("Can't handle match " + repr(match))
def print_html(self):
print('<div class="wiki"><p>')
return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
def _filename(self):
- return os.path.join(data_dir, self.page_name)
+ return os.path.join(config_get('data_dir', ''), self.page_name)
def _tmp_filename(self):
- return os.path.join(data_dir, ('#' + self.page_name.replace('/','_') + '.' + str(os.getpid()) + '#'))
+ return os.path.join(config_get('data_dir', ''), ('#' + self.page_name.replace('/','_') + '.' + str(os.getpid()) + '#'))
def exists(self):
try:
for filename in page_list(self._filename(), file_re):
if image_re.match(filename):
- if image_maxwidth:
- maxwidth_arg = ' | maxwidth=' + str(image_maxwidth)
+ maxwidth = config_get(image_maxwidth)
+ if maxwidth:
+ maxwidth_arg = ' | maxwidth=' + str(maxwidth)
out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth_arg + ' | class=thumbleft}}\n'
else:
out += ' * [[' + self.page_name + '/' + filename + ']]\n'
if err.errno != errno.ENOENT:
raise err
return None
- return strftime(datetime_fmt, modtime)
+ return strftime(config_get(datetime_fmt, '%a %d %b %Y %I:%M %p'), modtime)
def send_editor(self, preview=None):
send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
self._write_file(newdata)
rc = 0
- if post_edit_hook:
+ if config_get('post_edit_hook'):
import subprocess
- cmd = [ post_edit_hook, data_dir + '/' + self.page_name, remote_user(), remote_host(), changelog]
+ cmd = [
+ config_get(post_edit_hook),
+ config_get(data_dir, '') + '/' + self.page_name, remote_user(),
+ remote_host(), changelog ]
child = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
output = child.stdout.read()
rc = child.wait()