if msg_type == 'error':
print ' Guru Meditation #DEADBEEF.ABADC0DE'
print '</pre>'
- # FIXME: This simple JS snippet is harder to pass than ACID 3.0
+ # FIXME: This little JS snippet is harder to pass than ACID 3.0
print """
<script language="JavaScript" type="text/javascript">
var guru = document.getElementById('guru');
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()
-
def do_raw(pagename):
Page(pagename).send_raw()
-def do_savepage(pagename):
+def do_edit(pagename):
global form
pg = Page(pagename)
if 'preview' in form:
pg.msg_type = 'notice'
pg.send_page()
else:
- raise 'What did you press?'
+ pg.send_editor()
def make_index_key():
s = '<p><center>'
# For each line, we scan through looking for magic
# strings, outputting verbatim any intervening text
- # TODO: highlight search words (look at referer)
+ # TODO: highlight search words (look at referrer)
scan_re = re.compile(
r"(?:"
# Formatting
self.msg_type = 'error'
def split_title(self):
- # look for the end of words and the start of a new word,
- # and insert a space there
+ # look for the end of words and the start of a new word and insert a space there
return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
def _text_filename(self):
def get_raw_body(self):
try:
- return open(self._text_filename(), 'rt').read()
+ return open(self._text_filename(), 'rb').read()
except IOError, er:
if er.errno == errno.ENOENT:
return '' # just doesn't exist, use default
if self.can_write():
page_name = self.page_name
- #FIXME: are there security implications?
#css foo.css bar.css
global css_url
css_url = css_url + self.get_attr("css", "").split()
+ ' from ' + cgi.escape(get_hostname(remote_host()))
+ '</b></p>')
print '<div class="editor"><form method="post" action="%s">' % relative_url(self.page_name)
- print '<input type="hidden" name="savepage" value="%s">' % (self.page_name)
+ print '<input type="hidden" name="edit" value="%s">' % (self.page_name)
print """<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100">%s</textarea>""" % (preview or self.get_raw_body())
print """
<br />
print "</div>"
send_footer(self.page_name)
- def send_raw(self):
+ def send_raw(self, mimetype='text/plain'):
if not self.can_read():
send_title(None, msg='Read access denied by ACLs', msg_type='notice')
return
- emit_header("text/plain")
- print self.get_raw_body()
+ body = self.get_raw_body()
+ emit_header(mimetype)
+ print body
def _write_file(self, text):
tmp_filename = self._tmp_filename()
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(data_dir, filename)
- data = open(pathname, 'rb').read()
- emit_header(mime_type)
- sys.stdout.write(data)
-
# Main ---------------------------------------------------------------
try:
execfile("geekigeeki.conf.py")
-
form = cgi.FieldStorage()
-
- handlers = { 'fullsearch': do_fullsearch,
- 'titlesearch': do_titlesearch,
- 'edit': do_edit,
- 'raw': do_raw,
- 'savepage': do_savepage }
+ handlers = {
+ 'fullsearch': do_fullsearch,
+ 'titlesearch': do_titlesearch,
+ 'edit': do_edit,
+ 'raw': do_raw,
+ }
for cmd in handlers.keys():
if form.has_key(cmd):
Page(query).send_page()
elif img_re.match(query):
#FIXME: use correct mime type
- send_verbatim(query, 'image/jpeg')
+ Page(query).send_raw(mimetype='image/jpeg')
else:
- send_verbatim(query)
+ Page(query).send_raw(mimetype='application/octet-stream')
else:
print "Status: 404 Not Found"
send_title(None, msg='Can\'t work out query: ' + query)