print text + '</b> '
print ' | ' + link_tag('FrontPage', 'Front Page', 'navlink')
print ' | ' + link_tag('FindPage', 'Find Page', 'navlink')
- if globals().has_key('history_url'):
+ if 'history_url' in globals():
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>'
def do_edit(pagename):
pg = Page(pagename)
- if 'preview' in form:
- pg.send_editor(form['savetext'].value)
- elif 'save' in form:
- pg.save_text(form['savetext'].value)
+ if 'save' in form:
+ if form['file'].value:
+ pg.save(form['file'].file.read())
+ else:
+ pg.save(form['savetext'].value.replace('\r\n', '\n'))
pg.send_page()
elif 'cancel' in form:
pg.msg_text = 'Editing canceled'
pg.msg_type = 'notice'
pg.send_page()
else:
- pg.send_editor()
+ text = None
+ if 'preview' in form:
+ text = form['savetext'].value
+ pg.send_editor(text)
def make_index_key():
links = map(lambda ch: '<a href="#%s">%s</a>' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz')
def send_footer(name, mod_string=None):
if globals().get('debug_cgi', False):
cgi.print_arguments()
- cgi.print_form(cgi.FieldStorage())
+ cgi.print_form(form)
cgi.print_environ()
print '<div id="footer"><hr />'
print ('<p class="copyright"><span class="benchmark">generated in %0.3fs</span>' +
return _macro_search("fullsearch")
def _macro_search(type):
- if form.has_key('value'):
- default = form["value"].value
- else:
- default = ''
+ default = ''
+ if 'value' in form:
+ default = form['value'].value
return """<form method="get"><input name="%s" size="30" value="%s" /><input type="submit" value="Search" /></form>""" % (type, default)
def _macro_WordIndex(*vargs):
raise er
def get_attrs(self):
- if self.__dict__.has_key('attrs'):
+ if 'attrs' in self.__dict__:
return self.attrs
self.attrs = {}
try:
return action in perms.split(',')
return False
except Exception, er:
- pass
+ if acl:
+ self.msg_text = 'Illegal acl line: ' + acl
return default
def can_write(self):
send_guru("Write access denied by ACLs", "error")
return
+ file = ''
+ if 'file' in form:
+ file = form['file'].value
+
print ('<p><b>Editing ' + self.page_name
+ ' for ' + cgi.escape(remote_user())
+ ' from ' + cgi.escape(get_hostname(remote_host()))
+ '</b></p>')
- print '<div class="editor"><form method="post" action="%s">' % relative_url(self.page_name)
+ print '<div class="editor"><form method="post" enctype="multipart/form-data" action="%s">' % relative_url(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 '<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100">%s</textarea>' % (preview or self.get_raw_body())
+ print 'Or upload a file: <input type="file" name="file" value="%s" />' % file
print """
<br />
<input type="submit" name="save" value="Save" />
else:
send_title(None, msg_text='Read access denied by ACLs', msg_type='notice')
- def _write_file(self, text):
+ def _write_file(self, data):
tmp_filename = self._tmp_filename()
- open(tmp_filename, 'wt').write(text.replace('\r\n', '\n'))
- text = self._text_filename()
+ open(tmp_filename, 'wb').write(data)
+ name = self._text_filename()
if os.name == 'nt':
# Bad Bill! POSIX rename ought to replace. :-(
try:
- os.remove(text)
+ os.remove(name)
except OSError, er:
if er.errno != errno.ENOENT: raise er
- os.rename(tmp_filename, text)
+ os.rename(tmp_filename, name)
- def save_text(self, newtext):
+ def save(self, newdata):
if not self.can_write():
self.msg_text = 'Write access denied by ACLs'
self.msg_type = 'error'
return
- self._write_file(newtext)
+ self._write_file(newdata)
rc = 0
if post_edit_hook:
# FIXME: what's the std way to perform shell quoting in python?
}
for cmd in handlers.keys():
- if form.has_key(cmd):
+ if cmd in form:
apply(handlers[cmd], (form[cmd].value,))
break
else:
else:
from mimetypes import MimeTypes
type, encoding = MimeTypes().guess_type(query)
+ type = type or 'text/plain'
Page(query).send_raw(mimetype=type)
else:
print "Status: 404 Not Found"