2 # -*- coding: utf-8 -*-
4 # Copyright (C) 1999, 2000 Martin Pool <mbp@humbug.org.au>
5 # Copyright (C) 2002 Gerardo Poggiali
6 # Copyright (C) 2007, 2008, 2009 Bernie Innocenti <bernie@codewiz.org>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
12 # You should have received a copy of the GNU Affero General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 __version__ = '4.0-' + '$Id$'[4:11]
17 from time import clock, localtime, gmtime, strftime
21 import cgi, sys, os, re, errno, stat, glob
23 image_ext = 'png|gif|jpg|jpeg|bmp|ico'
24 video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt
25 image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")$", re.IGNORECASE)
26 video_re = re.compile(r".*\.(" + video_ext + ")$", re.IGNORECASE)
27 # FIXME: we accept stuff like foo/../bar and we shouldn't
28 file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)$")
29 url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S$")
30 ext_re = re.compile(r"\.([^\./]+)$")
32 # CGI stuff ---------------------------------------------------------
33 def config_get(key, default=None):
34 return globals().get(key, default)
37 return os.environ.get('SCRIPT_NAME', '')
39 #TODO: move post-edit hook into wiki, then kill this
41 return os.path.split(os.environ.get('SCRIPT_FILENAME', ''))[0]
44 path_info = os.environ.get('PATH_INFO', '')
45 if len(path_info) and path_info[0] == '/':
46 return path_info[1:] or 'FrontPage'
48 return os.environ.get('QUERY_STRING', '') or 'FrontPage'
51 purl = config_get('privileged_url')
52 return (purl is not None) and os.environ.get('SCRIPT_URI', '').startswith(purl)
55 user = os.environ.get('REMOTE_USER', '')
56 if user is None or user == '' or user == 'anonymous':
57 user = 'AnonymousCoward'
61 return os.environ.get('REMOTE_ADDR', '')
63 def get_hostname(addr):
65 from socket import gethostbyaddr
66 return gethostbyaddr(addr)[0] + ' (' + addr + ')'
70 def is_external_url(pathname):
71 return (url_re.match(pathname) or pathname.startswith('/'))
73 def relative_url(pathname, privileged=False):
74 if not is_external_url(pathname):
76 url = config_get('privileged_url') or script_name()
79 pathname = url + '/' + pathname
80 return cgi.escape(pathname, quote=True)
83 return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
86 return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' '))
88 # Split arg lists like "blah|blah blah| width=100 | align = center",
89 # return a list containing anonymous arguments and a map containing the named arguments
93 for arg in s.strip('<[{}]>').split('|'):
94 m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg)
96 kvargs[m.group(1)] = m.group(2)
98 args.append(arg.strip())
101 def url_args(kvargs):
103 for k, v in kvargs.items():
104 argv.append(k + '=' + v)
106 return '?' + '&'.join(argv)
109 # Formatting stuff --------------------------------------------------
110 def emit_header(mtime=None, mime_type="text/html"):
112 print("Last-Modified: " + strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(mtime)))
113 print("Content-type: " + mime_type + "; charset=utf-8\n")
115 def send_guru(msg_text, msg_type):
116 if not msg_text: return
117 print('<pre id="guru" onclick="this.style.display = \'none\'" class="' + msg_type + '">')
118 if msg_type == 'error':
119 print(' Software Failure. Press left mouse button to continue.\n')
120 print(cgi.escape(msg_text))
121 if msg_type == 'error':
122 print '\n Guru Meditation #DEADBEEF.ABADC0DE'
123 print('</pre><script language="JavaScript" type="text/javascript" src="%s" defer="defer"></script>' \
124 % relative_url('sys/GuruMeditation.js'))
126 def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False, mtime=None):
128 if title_done: return
132 print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"')
133 print(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
134 print('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">')
136 print("<head><title>%s: %s</title>" % (config_get('site_name', "Unconfigured Wiki"), text))
137 print(' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />')
139 print(' <meta name="robots" content="noindex,nofollow" />')
141 for http_equiv, content in config_get('meta_urls', {}):
142 print(' <meta http-equiv="%s" content="%s" />' % (http_equiv, relative_url(content)))
144 for link in config_get('link_urls', {}):
146 print(' <link rel="%s" href="%s" />' % (rel, relative_url(href)))
148 editable = name and writable and is_privileged()
150 print(' <link rel="alternate" type="application/x-wiki" title="Edit this page" href="%s" />' \
151 % relative_url('?a=edit&q=' + name, privileged=True))
153 history = config_get('history_url')
154 if history is not None:
155 print(' <link rel="alternate" type="application/rss+xml" title="RSS" href="%s" />' \
156 % relative_url(history + '?a=rss'))
162 print('<body ondblclick="location.href=\'' + relative_url('?a=edit&q=' + name, privileged=True) + '\'">')
167 send_guru(msg_text, msg_type)
170 print('<div class="nav">')
171 print link_tag('FrontPage', config_get('site_icon', 'Home'), cssclass='navlink')
173 print(' <b>' + link_tag('?fullsearch=' + name, text, cssclass='navlink') + '</b> ')
175 print(' <b>' + text + '</b> ')
176 print(' | ' + link_tag('FindPage', 'Find Page', cssclass='navlink'))
178 print(' | <a href="' + relative_url(history) + '" class="navlink">Recent Changes</a>')
180 print(' | <a href="' + relative_url(history + '?a=history;f=' + name) + '" class="navlink">Page History</a>')
183 print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink'))
184 if config_get('privileged_url') is not None:
186 print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', cssclass='navlink', privileged=True))
188 print(' | ' + link_tag(name, 'Login', cssclass='navlink', privileged=True))
191 print(' | <i>Immutable Page</i>')
194 if user != 'AnonymousCoward':
195 print(' | <span class="login"><i><b>' + link_tag('User/' + user, user) + '</b></i></span>')
197 print('<hr /></div>')
199 def send_httperror(status="403 Not Found", query=""):
200 print("Status: %s" % status)
201 send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
204 def link_tag(dest, text=None, privileged=False, **kvargs):
206 text = humanlink(dest)
207 elif image_re.match(text):
208 text = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
210 link_class = kvargs.get('class', kvargs.get('cssclass', None))
212 if is_external_url(dest):
213 link_class = 'external'
214 elif file_re.match(dest) and Page(dest).exists():
215 link_class = 'wikilink'
217 text = config_get('nonexist_pfx', '') + text
218 link_class = 'nonexistent'
220 # Prevent crawlers from following links potentially added by spammers or to generated pages
222 if link_class == 'external' or link_class == 'navlink':
223 nofollow = 'rel="nofollow" '
225 return '<a class="%s" %shref="%s">%s</a>' % (link_class, nofollow, relative_url(dest, privileged=privileged), text)
227 def link_inline(name, descr=None, kvargs={}):
228 if not descr: descr = humanlink(name)
229 url = relative_url(name)
230 if video_re.match(name):
231 return '<video controls="1" src="%s">Your browser does not support HTML5 video</video>' % url
232 elif image_re.match(name):
233 return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (url, url + url_args(kvargs), descr)
234 elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
235 Page(name).send_naked(kvargs) # FIXME: we should return the page as a string rather than print it
238 return '<iframe width="100%%" scrolling="auto" frameborder="0" src="%s"><a href="%s">%s</a></iframe>' \
241 def link_inline_glob(pattern, descr=None, kvargs={}):
242 if not url_re.match(pattern) and bool(set(pattern) & set('?*[')):
244 for name in glob.glob(pattern):
245 s += link_inline(name, descr, kvargs)
248 return link_inline(pattern, descr, kvargs)
250 # Search ---------------------------------------------------
252 def print_search_stats(hits, searched):
253 print("<p>%d hits out of %d pages searched.</p>" % (hits, searched))
255 def handle_fullsearch(query, form):
256 needle = form['q'].value
257 send_title(None, 'Full text search for "' + needle + '"')
259 needle_re = re.compile(needle, re.IGNORECASE)
261 all_pages = page_list()
262 for page_name in all_pages:
263 body = Page(page_name).get_raw_body()
264 count = len(needle_re.findall(body))
266 hits.append((count, page_name))
268 # The default comparison for tuples compares elements in order,
269 # so this sorts by number of hits
274 for (count, page_name) in hits:
275 print('<li><p>' + link_tag(page_name))
276 print(' . . . . ' + `count`)
277 print(['match', 'matches'][count != 1])
281 print_search_stats(len(hits), len(all_pages))
283 def handle_titlesearch(query, form):
284 needle = form['q'].value
285 send_title(None, 'Title search for "' + needle + '"')
287 needle_re = re.compile(needle, re.IGNORECASE)
288 all_pages = page_list()
289 hits = list(filter(needle_re.search, all_pages))
292 for filename in hits:
293 print('<li><p>' + link_tag(filename) + "</p></li>")
296 print_search_stats(len(hits), len(all_pages))
298 def handle_raw(pagename, form):
299 if not file_re.match(pagename):
300 send_httperror("403 Forbidden", pagename)
303 Page(pagename).send_raw()
305 def handle_edit(pagename, form):
306 if not file_re.match(pagename):
307 send_httperror("403 Forbidden", pagename)
310 pg = Page(form['q'].value)
312 if form['file'].value:
313 pg.save(form['file'].file.read(), form['changelog'].value)
315 pg.save(form['savetext'].value.replace('\r\n', '\n'), form['changelog'].value)
317 elif 'cancel' in form:
318 pg.msg_text = 'Editing canceled'
319 pg.msg_type = 'notice'
321 else: # preview or edit
323 if 'preview' in form:
324 text = form['savetext'].value
327 def handle_get(pagename, form):
328 if file_re.match(pagename):
329 # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
330 from mimetypes import MimeTypes
331 mimetype, encoding = MimeTypes().guess_type(pagename)
333 Page(pagename).send_raw(mimetype=mimetype, args=form)
335 Page(pagename).format()
337 send_httperror("403 Forbidden", pagename)
339 # Used by sys/macros/WordIndex and sys/macros/TitleIndex
340 def make_index_key():
341 links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
342 return '<p style="text-align: center">' + ' | '.join(links) + '</p>'
344 def page_list(dirname=None, search_re=None):
345 if search_re is None:
346 # FIXME: WikiWord is too restrictive now!
347 search_re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
348 return sorted(filter(search_re.match, os.listdir(dirname or '.')))
350 def send_footer(mtime=None):
351 if config_get('debug_cgi', False):
352 cgi.print_arguments()
355 link_inline("sys/footer", kvargs = {
356 'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%a %d %b %Y %I:%M %p'), localtime(mtime))
358 print("</body></html>")
360 def _macro_ELAPSED_TIME(*args, **kvargs):
361 return "%03f" % (clock() - start_time)
363 def _macro_VERSION(*args, **kvargs):
367 """Object that turns Wiki markup into HTML.
369 All formatting commands can be parsed one line at a time, though
370 some state is carried over between lines.
372 def __init__(self, raw, kvargs=None):
374 self.kvargs = kvargs or {}
376 self.in_pre = self.in_html = self.in_table = self.in_li = False
377 self.in_header = True
378 self.list_indents = [] # a list of pairs (indent_level, list_type) to track nested lists
386 "--": ["del", False],
387 "^^": ["sup", False],
388 ",,": ["sub", False],
389 "''": ["em", False], # LEGACY
390 "'''": ["b", False], # LEGACY
391 "``": ["tt", False], # LEGACY
394 def _b_repl(self, word):
395 style = self.styles[word]
396 style[1] = not style[1]
397 return ['</', '<'][style[1]] + style[0] + '>'
399 def _glyph_repl(self, word):
402 def _tit_repl(self, word):
404 result = '</h%d><p>\n' % self.h_level
407 self.h_level = len(word) - 1
408 link = permalink(self.line)
409 result = '\n</p><h%d id="%s"><a class="heading" href="#%s">¶</a> ' % (self.h_level, link, link)
412 def _br_repl(self, word):
415 def _rule_repl(self, word):
416 return '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
418 def _macro_repl(self, word):
420 args, kvargs = parse_args(word)
421 if args[0] in self.kvargs:
422 return self.kvargs[args[0]]
423 macro = globals().get('_macro_' + args[0])
425 exec(open("sys/macros/" + args[0] + ".py").read(), globals())
426 macro = globals().get('_macro_' + args[0])
427 return macro(*args, **kvargs)
429 msg = cgi.escape(word) + ": " + cgi.escape(str(e))
431 msg = '<strong class="error">' + msg + '</strong>'
434 def _hurl_repl(self, word):
435 args, kvargs = parse_args(word)
436 return link_tag(*args, **kvargs)
438 def _inl_repl(self, word):
439 args, kvargs = parse_args(word)
443 # This double div nonsense works around a limitation of the HTML block model
444 return '<div class="' + kvargs.get('class', 'thumb') + '">' \
445 + '<div class="innerthumb">' \
446 + link_inline_glob(name, descr, kvargs) \
447 + '<div class="caption">' + descr + '</div></div></div>'
449 return link_inline_glob(name, None, kvargs)
451 def _html_repl(self, word):
452 if not self.in_html and word.startswith('<div'): word = '</p>' + word
454 return word; # Pass through
456 def _htmle_repl(self, word):
458 if not self.in_html and word.startswith('</div'): word += '<p>'
459 return word; # Pass through
461 def _ent_repl(self, s):
463 return s; # Pass through
464 return {'&': '&',
468 def _img_repl(self, word): # LEGACY
469 return self._inl_repl('{{' + word + '}}')
471 def _word_repl(self, word): # LEGACY
472 if self.in_html: return word # pass through
473 return link_tag(word)
475 def _url_repl(self, word): # LEGACY
476 if self.in_html: return word # pass through
477 return link_tag(word)
479 def _email_repl(self, word): # LEGACY
480 if self.in_html: return word # pass through
481 return '<a href="mailto:%s">%s</a>' % (word, word)
483 def _li_repl(self, match):
490 def _pre_repl(self, word):
491 if word == '{{{' and not self.in_pre:
499 def _hi_repl(self, word):
500 return '<strong class="highlight ' + word + '">' + word + '</strong>'
502 def _tr_repl(self, word):
504 if not self.in_table:
507 out = '</p><table><tbody>\n'
509 out = out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '">'
510 return out + ['<td>', '<th>'][word.strip() == '||=']
512 def _td_repl(self, word):
514 return ['</td><td>', '</th><th>'][word.strip() == '||=']
517 def _tre_repl(self, word):
519 return ['</td></tr>', '</th></tr>'][word.strip() == '||=']
522 def _indent_level(self):
523 return len(self.list_indents) and self.list_indents[-1][0]
525 def _indent_to(self, new_level, list_type=''):
526 if self._indent_level() == new_level:
529 while self._indent_level() > new_level:
532 self.in_li = False # FIXME
533 s += '</' + self.list_indents[-1][1] + '>\n'
534 del(self.list_indents[-1])
536 list_type = ('ul', 'ol')[list_type == '#']
537 while self._indent_level() < new_level:
538 self.list_indents.append((new_level, list_type))
539 s += '<' + list_type + '>\n'
543 def replace(self, match):
544 for rule, hit in list(match.groupdict().items()):
546 return getattr(self, '_' + rule + '_repl')(hit)
548 raise Exception("Can't handle match " + repr(match))
550 def print_html(self):
551 print('<div class="wiki"><p>')
553 scan_re = re.compile(r"""(?:
554 # Styles and formatting ("--" must cling to a word to disambiguate it from the dash)
555 (?P<b> \*\* | // | \#\# | __ | --\b | \b-- | \^\^ | ,, | ''' | '' | `` )
559 | (?P<hi> \b( FIXME | TODO | DONE )\b )
563 | (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
564 | (?P<hurl> \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
567 | (?P<html> <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
568 | (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
571 # Auto links (LEGACY)
572 | (?P<img> \b[a-zA-Z0-9_/-]+\.(""" + image_ext + "|" + video_ext + r"""))
573 | (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
574 | (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
575 | (?P<email> [-\w._+]+\@[\w.-]+)
577 # Lists, divs, spans and inline objects
578 | (?P<li> ^\s+[\*\#]\s+)
579 | (?P<pre> \{\{\{|\s*\}\}\})
580 | (?P<inl> \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
583 | (?P<tr> ^\s*\|\|(=|)\s*)
584 | (?P<tre> \s*\|\|(=|)\s*$)
585 | (?P<td> \s*\|\|(=|)\s*)
587 # TODO: highlight search words (look at referrer)
589 pre_re = re.compile("""(?:
593 blank_re = re.compile(r"^\s*$")
594 indent_re = re.compile(r"^(\s*)(\*|\#|)")
595 tr_re = re.compile(r"^\s*\|\|")
596 eol_re = re.compile(r"\r?\n")
597 # For each line, we scan through looking for magic strings, outputting verbatim any intervening text
598 #3.0: for self.line in eol_re.split(str(self.raw.expandtabs(), 'utf-8')):
599 for self.line in eol_re.split(str(self.raw.expandtabs())):
602 if self.line.startswith('#'):
604 self.in_header = False
607 print(re.sub(pre_re, self.replace, self.line))
609 if self.in_table and not tr_re.match(self.line):
610 self.in_table = False
611 print('</tbody></table><p>')
613 if blank_re.match(self.line):
616 indent = indent_re.match(self.line)
617 #3.0: print(self._indent_to(len(indent.group(0))), end=' ')
618 print(self._indent_to(len(indent.group(1)), indent.group(2)))
619 print(re.sub(scan_re, self.replace, self.line))
621 if self.in_pre: print('</pre>')
622 if self.in_table: print('</tbody></table><p>')
623 print(self._indent_to(0))
627 def __init__(self, page_name):
628 self.page_name = page_name
630 self.msg_type = 'error'
632 def split_title(self):
633 # look for the end of words and the start of a new word and insert a space there
634 return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
637 return self.page_name
639 def _tmp_filename(self):
640 return self.page_name + '.tmp' + str(os.getpid()) + '#'
644 return os.stat(self._filename()).st_mtime
646 if err.errno == errno.ENOENT:
655 def get_raw_body(self, default=None):
657 return open(self._filename(), 'rb').read()
659 if err.errno == errno.ENOENT:
661 default = '//[[?a=edit&q=%s|Describe %s]]//' % (self.page_name, self.page_name)
663 if err.errno == errno.EISDIR:
664 return self.format_dir()
667 def format_dir(self):
670 for dirname in self.page_name.strip('/').split('/'):
671 pathname = (pathname + '/' + dirname) if pathname else dirname
672 out += '[[' + pathname + '|' + dirname + ']]/'
675 for filename in page_list(self._filename(), file_re):
676 if image_re.match(filename):
677 maxwidth = config_get('image_maxwidth', '400')
679 maxwidth = ' | maxwidth=' + str(maxwidth)
680 out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth + ' | class=thumbleft}}\n'
682 out += ' * [[' + self.page_name + '/' + filename + ']]\n'
686 if not '_pragmas' in self.__dict__:
689 file = open(self._filename(), 'rt')
690 attr_re = re.compile(r"^#(\S*)(.*)$")
692 m = attr_re.match(line)
695 self._pragmas[m.group(1)] = m.group(2).strip()
696 #print "bernie: pragmas[" + m.group(1) + "] = " + m.group(2) + "<br>\n"
698 if err.errno != errno.ENOENT and err.errno != errno.EISDIR:
702 def pragma(self, name, default):
703 return self.pragmas().get(name, default)
705 def can(self, action, default=True):
708 #acl SomeUser:read,write All:read
709 acl = self.pragma("acl", None)
710 for rule in acl.split():
711 (user, perms) = rule.split(':')
712 if user == remote_user() or user == "All":
713 return action in perms.split(',')
717 self.msg_text = 'Illegal acl line: ' + acl
721 return self.can("write", True)
724 return self.can("read", True)
726 def send_naked(self, kvargs=None):
728 WikiFormatter(self.get_raw_body(), kvargs).print_html()
730 send_guru("Read access denied by ACLs", "notice")
734 value = self.pragma("css", None)
737 link_urls += [ [ "stylesheet", value ] ]
739 send_title(self.page_name, self.split_title(),
740 msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write(), mtime=self._mtime())
742 send_footer(mtime=self._mtime())
744 def send_editor(self, preview=None):
745 send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
746 if not self.can_write():
747 send_guru("Write access denied by ACLs", "error")
751 preview = self.get_raw_body(default='')
753 link_inline("sys/EditPage", kvargs = {
754 'EDIT_BODY': cgi.escape(preview),
755 #'EDIT_PREVIEW': WikiFormatter(preview).print_html(),
759 print("<div class='preview'>")
760 WikiFormatter(preview).print_html()
764 def send_raw(self, mimetype='text/plain', args=[]):
765 if not self.can_read():
766 send_title(None, msg_text='Read access denied by ACLs', msg_type='notice', mtime=self._mtime())
769 emit_header(self._mtime(), mimetype)
770 if 'maxwidth' in args:
773 subprocess.check_call(['gm', 'convert', self._filename(),
774 '-scale', args['maxwidth'].value + ' >', '-'])
776 body = self.get_raw_body()
779 def _write_file(self, data):
780 tmp_filename = self._tmp_filename()
781 open(tmp_filename, 'wb').write(data)
782 name = self._filename()
784 # Bad Bill! POSIX rename ought to replace. :-(
788 if err.errno != errno.ENOENT: raise err
789 path = os.path.split(name)[0]
790 if path and not os.path.exists(path):
792 os.rename(tmp_filename, name)
794 def save(self, newdata, changelog):
795 if not self.can_write():
796 self.msg_text = 'Write access denied by Access Control List'
798 if not is_privileged():
799 self.msg_text = 'Unauthenticated access denied'
802 self._write_file(newdata)
804 if config_get('post_edit_hook'):
807 config_get('post_edit_hook'),
808 self.page_name, remote_user(),
809 remote_host(), changelog ]
810 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
811 output = child.stdout.read()
814 self.msg_text += "Post-editing hook returned %d. Command was:\n'%s'\n" % (rc, "' '".join(cmd))
816 self.msg_text += 'Output follows:\n' + output
818 self.msg_text = 'Thank you for your contribution. Your attention to detail is appreciated.'
819 self.msg_type = 'success'
822 exec(open("geekigeeki.conf.py").read())
823 os.chdir(config_get('data_dir', 'data'))
824 form = cgi.FieldStorage()
825 action = form.getvalue('a', 'get')
826 handler = globals().get('handle_' + action)
828 handler(query_string(), form)
830 send_httperror("403 Forbidden", query_string())
834 msg_text = traceback.format_exc()
836 send_guru(msg_text, "error")
838 send_title(None, msg_text=msg_text)