# Head
emit_header()
- print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
-"""
+ print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
+ 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">'
+
+ site_name = globals().get('site_name', 'Unconfigured Site')
print "<head><title>%s: %s</title>" % (site_name, text)
print ' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />'
if not name:
print ' <meta name="robots" content="noindex,nofollow" />'
- if css_url:
+ if globals().has_key('css_url'):
print ' <link rel="stylesheet" type="text/css" href="%s" />' % css_url
print '</head>'
print text + '</b> '
print ' | ' + link_tag('FrontPage', 'Front Page', 'navlink')
print ' | ' + link_tag('FindPage', 'Find Page', 'navlink')
- print ' | <a href="' + history_url + '" class="navlink">Recent Changes</a>'
+ if globals().has_key('history_url'):
+ print ' | <a href="' + history_url + '" class="navlink">Recent Changes</a>'
+ if name:
+ print ' | <a href="' + history_url + '?a=history;f=' + name + '" class="navlink">Page History</a>'
if name:
- print ' | <a href="' + history_url + '?a=history;f=' + name + '" class="navlink">Page History</a>'
print ' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink')
if privileged_url is not None:
print ' | ' + link_tag('?edit=' + name, 'Edit Page', 'navlink', authentication=True)
for (count, page_name) in hits:
print '<li><p>' + Page(page_name).link_to()
print ' . . . . ' + `count`
- print ['match', 'matches'][count <> 1]
+ print ['match', 'matches'][count != 1]
print '</p></li>'
print "</ul>"
def print_search_stats(hits, searched):
print "<p>%d hits out of %d pages searched.</p>" % (hits, searched)
+#TODO: merge into do_savepage()
def do_edit(pagename):
Page(pagename).send_editor()
return filter(word_re.match, os.listdir(text_dir))
def send_footer(name, mod_string=None):
- if debug_cgi:
+ if globals().get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(cgi.FieldStorage())
cgi.print_environ()
# set title
for word in all_words:
letter = string.lower(word[0])
- if letter <> last_letter:
+ if letter != last_letter:
s = s + '; <a name="%s"><h3>%s</h3></a>' % (letter, letter)
last_letter = letter
current_letter = None
for name in pages:
letter = string.lower(name[0])
- if letter <> current_letter:
+ if letter != current_letter:
s = s + '<a name="%s"><h3>%s</h3></a>' % (letter, letter)
current_letter = letter
else:
def exists(self):
try:
os.stat(self._text_filename())
- return 1
+ return True
except OSError, er:
if er.errno == errno.ENOENT:
- return 0
+ return False
else:
raise er
return open(self._text_filename(), 'rt').read()
except IOError, er:
if er.errno == errno.ENOENT:
- # just doesn't exist, use default
- return 'Describe %s here.' % self.page_name
- else:
- raise er
+ return '' # just doesn't exist, use default
+ raise er
def get_attrs(self):
if self.attrs:
send_footer(page_name, self._last_modified())
def _last_modified(self):
- if not self.exists():
+ try:
+ from time import localtime, strftime
+ modtime = localtime(os.stat(self._text_filename())[stat.ST_MTIME])
+ except OSError, er:
+ if er.errno != errno.ENOENT:
+ raise er
return None
- from time import localtime, strftime
- modtime = localtime(os.stat(self._text_filename())[stat.ST_MTIME])
return strftime(datetime_fmt, modtime)
def send_editor(self, preview=None):
try:
os.remove(text)
except OSError, er:
- if er.errno <> errno.ENOENT: raise er
+ if er.errno != errno.ENOENT: raise er
os.rename(tmp_filename, text)
def save_text(self, newtext):
self.msg = 'Thank you for your contribution. Your attention to detail is appreciated.'
self.msg_type = 'success'
+#TODO: merge into send_raw()
def send_verbatim(filename, mime_type='application/octet-stream'):
pathname = path.join(text_dir, filename)
data = open(pathname, 'rb').read()
# Main ---------------------------------------------------------------
try:
- # Configuration values
- site_name = 'Codewiz'
-
- # set to None for read-only sites, leave empty ('') to allow anonymous edits
- # otherwise, set to a URL that requires authentication
- privileged_url = 'https://www.codewiz.org/~bernie/wiki'
-
- data_dir = '/home/bernie/public_html/wiki'
- text_dir = path.join(data_dir, 'text')
- css_url = '../wikidata/geekigeeki.css' # optional stylesheet link
- history_url = '../wikigit/wiki.git'
- post_edit_hook = './post_edit_hook.sh'
- datetime_fmt = '%a %d %b %Y %I:%M %p'
- allow_edit = True # Is it possible to edit pages?
- show_hosts = True # show hostnames?
- nonexist_pfx = '' # prefix before nonexistent link (usually '?')
- debug_cgi = False # Set to True for CGI var dump
+ execfile("geekigeeki.conf.py")
form = cgi.FieldStorage()
else:
send_verbatim(query)
else:
- # TODO: return 404?
+ print "Status: 404 Not Found"
send_title(None, msg='Can\'t work out query: ' + query)
except:
import traceback