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 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, navbar="on"):
128 if title_done: return
132 print('<!doctype html>\n<html lang="en">')
133 print("<head><title>%s: %s</title>" % (config_get('site_name', "Unconfigured Wiki"), text))
134 print(' <meta charset="UTF-8">')
136 print(' <meta name="robots" content="noindex,nofollow" />')
138 for http_equiv, content in config_get('meta_urls', {}):
139 print(' <meta http-equiv="%s" content="%s" />' % (http_equiv, relative_url(content)))
141 for link in config_get('link_urls', {}):
143 print(' <link rel="%s" href="%s" />' % (rel, relative_url(href)))
145 editable = name and writable and is_privileged()
147 print(' <link rel="alternate" type="application/x-wiki" title="Edit this page" href="%s" />' \
148 % relative_url('?a=edit&q=' + name, privileged=True))
150 history = config_get('history_url')
151 if history is not None:
152 print(' <link rel="alternate" type="application/rss+xml" title="RSS" href="%s" />' \
153 % relative_url(history + '?a=rss'))
159 print('<body ondblclick="location.href=\'' + relative_url('?a=edit&q=' + name, privileged=True) + '\'">')
164 send_guru(msg_text, msg_type)
170 print('<nav><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></nav>')
199 def send_httperror(status="403 Not Found", query=""):
200 print("Status: %s" % status)
202 send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
205 def link_tag(dest, text=None, privileged=False, **kvargs):
207 text = humanlink(dest)
208 elif image_re.match(text):
209 text = '<img style="border: 0" src="' + relative_url(text) + '" alt="' + text + '" />'
211 link_class = kvargs.get('class', kvargs.get('cssclass', None))
213 if is_external_url(dest):
214 link_class = 'external'
215 elif file_re.match(dest) and Page(dest).exists():
216 link_class = 'wikilink'
218 text = config_get('nonexist_pfx', '') + text
219 link_class = 'nonexistent'
221 # Prevent crawlers from following links potentially added by spammers or to generated pages
223 if link_class == 'external' or link_class == 'navlink':
224 nofollow = 'rel="nofollow" '
226 return '<a class="%s" %shref="%s">%s</a>' % (link_class, nofollow, relative_url(dest, privileged=privileged), text)
228 def link_inline(name, descr=None, kvargs={}):
229 if not descr: descr = humanlink(name)
230 url = relative_url(name)
231 if video_re.match(name):
232 return '<video controls="1" src="%s">Your browser does not support HTML5 video</video>' % url
233 elif image_re.match(name):
234 return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (url, url + url_args(kvargs), descr)
235 elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
236 Page(name).send_naked(kvargs) # FIXME: we should return the page as a string rather than print it
239 return '<iframe width="100%%" scrolling="auto" frameborder="0" src="%s"><a href="%s">%s</a></iframe>' \
242 def link_inline_glob(pattern, descr=None, kvargs={}):
243 if not url_re.match(pattern) and bool(set(pattern) & set('?*[')):
245 for name in glob.glob(pattern):
246 s += link_inline(name, descr, kvargs)
249 return link_inline(pattern, descr, kvargs)
251 # Search ---------------------------------------------------
253 def print_search_stats(hits, searched):
254 print("<p>%d hits out of %d pages searched.</p>" % (hits, searched))
256 def handle_fullsearch(query, form):
257 needle = form['q'].value
258 send_title(None, 'Full text search for "' + needle + '"')
260 needle_re = re.compile(needle, re.IGNORECASE)
262 all_pages = page_list()
263 for page_name in all_pages:
264 body = Page(page_name).get_raw_body()
265 count = len(needle_re.findall(body))
267 hits.append((count, page_name))
269 # The default comparison for tuples compares elements in order,
270 # so this sorts by number of hits
275 for (count, page_name) in hits:
276 print('<li><p>' + link_tag(page_name))
277 print(' . . . . ' + `count`)
278 print(['match', 'matches'][count != 1])
282 print_search_stats(len(hits), len(all_pages))
284 def handle_titlesearch(query, form):
285 needle = form['q'].value
286 send_title(None, 'Title search for "' + needle + '"')
288 needle_re = re.compile(needle, re.IGNORECASE)
289 all_pages = page_list()
290 hits = list(filter(needle_re.search, all_pages))
293 for filename in hits:
294 print('<li><p>' + link_tag(filename) + "</p></li>")
297 print_search_stats(len(hits), len(all_pages))
299 def handle_raw(pagename, form):
300 if not file_re.match(pagename):
301 send_httperror("403 Forbidden", pagename)
304 Page(pagename).send_raw()
306 def handle_edit(pagename, form):
307 if not file_re.match(pagename):
308 send_httperror("403 Forbidden", pagename)
311 pg = Page(form['q'].value)
313 if form['file'].value:
314 pg.save(form['file'].file.read(), form['changelog'].value)
316 pg.save(form['savetext'].value.replace('\r\n', '\n'), form['changelog'].value)
318 elif 'cancel' in form:
319 pg.msg_text = 'Editing canceled'
320 pg.msg_type = 'notice'
322 else: # preview or edit
324 if 'preview' in form:
325 text = form['savetext'].value
328 def handle_get(pagename, form):
329 if file_re.match(pagename):
330 # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
331 from mimetypes import MimeTypes
332 mimetype, encoding = MimeTypes().guess_type(pagename)
334 Page(pagename).send_raw(mimetype=mimetype, args=form)
336 Page(pagename).format()
338 send_httperror("403 Forbidden", pagename)
340 # Used by sys/macros/WordIndex and sys/macros/TitleIndex
341 def make_index_key():
342 links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
343 return '<p style="text-align: center">' + ' | '.join(links) + '</p>'
345 def page_list(dirname=None, search_re=None):
346 if search_re is None:
347 # FIXME: WikiWord is too restrictive now!
348 search_re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
349 return sorted(filter(search_re.match, os.listdir(dirname or '.')))
351 def _macro_ELAPSED_TIME(*args, **kvargs):
352 return "%03f" % (clock() - start_time)
354 def _macro_VERSION(*args, **kvargs):
358 """Object that turns Wiki markup into HTML.
360 All formatting commands can be parsed one line at a time, though
361 some state is carried over between lines.
363 def __init__(self, raw, kvargs=None):
365 self.kvargs = kvargs or {}
367 self.in_pre = self.in_html = self.in_table = self.in_li = False
368 self.in_header = True
369 self.list_indents = [] # a list of pairs (indent_level, list_type) to track nested lists
377 "--": ["del", False],
378 "^^": ["sup", False],
379 ",,": ["sub", False],
380 "''": ["em", False], # LEGACY
381 "'''": ["b", False], # LEGACY
384 def _b_repl(self, word):
385 style = self.styles[word]
386 style[1] = not style[1]
387 return ['</', '<'][style[1]] + style[0] + '>'
389 def _glyph_repl(self, word):
392 def _tit_repl(self, word):
394 result = '</h%d><p>\n' % self.h_level
397 self.h_level = len(word) - 1
398 link = permalink(self.line)
399 result = '\n</p><h%d id="%s"><a class="heading" href="#%s">¶</a> ' % (self.h_level, link, link)
402 def _br_repl(self, word):
405 def _rule_repl(self, word):
406 return '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
408 def _macro_repl(self, word):
410 args, kvargs = parse_args(word)
411 if args[0] in self.kvargs:
412 return self.kvargs[args[0]]
413 macro = globals().get('_macro_' + args[0])
415 exec(open("sys/macros/" + args[0] + ".py").read(), globals())
416 macro = globals().get('_macro_' + args[0])
417 return macro(*args, **kvargs)
419 msg = cgi.escape(word) + ": " + cgi.escape(str(e))
421 msg = '<strong class="error">' + msg + '</strong>'
424 def _hurl_repl(self, word):
425 args, kvargs = parse_args(word)
426 return link_tag(*args, **kvargs)
428 def _inl_repl(self, word):
429 args, kvargs = parse_args(word)
433 # This double div nonsense works around a limitation of the HTML block model
434 return '<div class="' + kvargs.get('class', 'thumb') + '">' \
435 + '<div class="innerthumb">' \
436 + link_inline_glob(name, descr, kvargs) \
437 + '<div class="caption">' + descr + '</div></div></div>'
439 return link_inline_glob(name, None, kvargs)
441 def _html_repl(self, word):
442 if not self.in_html and word.startswith('<div'): word = '</p>' + word
444 return word; # Pass through
446 def _htmle_repl(self, word):
448 if not self.in_html and word.startswith('</div'): word += '<p>'
449 return word; # Pass through
451 def _ent_repl(self, s):
453 return s; # Pass through
454 return {'&': '&',
458 def _img_repl(self, word): # LEGACY
459 return self._inl_repl('{{' + word + '}}')
461 def _word_repl(self, word): # LEGACY
462 if self.in_html: return word # pass through
463 return link_tag(word)
465 def _url_repl(self, word): # LEGACY
466 if self.in_html: return word # pass through
467 return link_tag(word)
469 def _email_repl(self, word): # LEGACY
470 if self.in_html: return word # pass through
471 return '<a href="mailto:%s">%s</a>' % (word, word)
473 def _li_repl(self, match):
480 def _pre_repl(self, word):
481 if word == '{{{' and not self.in_pre:
489 def _hi_repl(self, word):
490 return '<strong class="highlight ' + word + '">' + word + '</strong>'
492 def _tr_repl(self, word):
494 if not self.in_table:
497 out = '</p><table><tbody>\n'
499 out = out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '">'
500 return out + ['<td>', '<th>'][word.strip() == '||=']
502 def _td_repl(self, word):
504 return ['</td><td>', '</th><th>'][word.strip() == '||=']
507 def _tre_repl(self, word):
509 return ['</td></tr>', '</th></tr>'][word.strip() == '||=']
512 def _indent_level(self):
513 return len(self.list_indents) and self.list_indents[-1][0]
515 def _indent_to(self, new_level, list_type=''):
516 if self._indent_level() == new_level:
519 while self._indent_level() > new_level:
522 self.in_li = False # FIXME
523 s += '</' + self.list_indents[-1][1] + '>\n'
524 del(self.list_indents[-1])
526 list_type = ('ul', 'ol')[list_type == '#']
527 while self._indent_level() < new_level:
528 self.list_indents.append((new_level, list_type))
529 s += '<' + list_type + '>\n'
533 def replace(self, match):
534 for rule, hit in list(match.groupdict().items()):
536 return getattr(self, '_' + rule + '_repl')(hit)
538 raise Exception("Can't handle match " + repr(match))
540 def print_html(self):
541 print('<div class="wiki"><p>')
543 scan_re = re.compile(r"""(?:
544 # Styles and formatting ("--" must cling to a word to disambiguate it from the dash)
545 (?P<b> \*\* | // | \#\# | __ | --\b | \b-- | \^\^ | ,, | ''' | '' )
549 | (?P<hi> \b( FIXME | TODO | DONE )\b )
553 | (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
554 | (?P<hurl> \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
557 | (?P<html> <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
558 | (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
561 # Auto links (LEGACY)
562 | (?P<img> \b[a-zA-Z0-9_/-]+\.(""" + image_ext + "|" + video_ext + r"""))
563 | (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
564 | (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
565 | (?P<email> [-\w._+]+\@[\w.-]+)
567 # Lists, divs, spans and inline objects
568 | (?P<li> ^\s+[\*\#]\s+)
569 | (?P<pre> \{\{\{|\s*\}\}\})
570 | (?P<inl> \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
573 | (?P<tr> ^\s*\|\|(=|)\s*)
574 | (?P<tre> \s*\|\|(=|)\s*$)
575 | (?P<td> \s*\|\|(=|)\s*)
577 # TODO: highlight search words (look at referrer)
579 pre_re = re.compile("""(?:
583 blank_re = re.compile(r"^\s*$")
584 indent_re = re.compile(r"^(\s*)(\*|\#|)")
585 tr_re = re.compile(r"^\s*\|\|")
586 eol_re = re.compile(r"\r?\n")
587 # For each line, we scan through looking for magic strings, outputting verbatim any intervening text
588 #3.0: for self.line in eol_re.split(str(self.raw.expandtabs(), 'utf-8')):
589 for self.line in eol_re.split(str(self.raw.expandtabs())):
592 if self.line.startswith('#'):
594 self.in_header = False
597 print(re.sub(pre_re, self.replace, self.line))
599 if self.in_table and not tr_re.match(self.line):
600 self.in_table = False
601 print('</tbody></table><p>')
603 if blank_re.match(self.line):
606 indent = indent_re.match(self.line)
607 print(self._indent_to(len(indent.group(1)), indent.group(2)))
608 # Stand back! Here we apply the monster regex that does all the parsing
609 print(re.sub(scan_re, self.replace, self.line))
611 if self.in_pre: print('</pre>')
612 if self.in_table: print('</tbody></table><p>')
613 print(self._indent_to(0))
617 def __init__(self, page_name="Limbo"):
618 self.page_name = page_name.rstrip('/');
620 self.msg_type = 'error'
622 def split_title(self):
623 # look for the end of words and the start of a new word and insert a space there
624 return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
627 return self.page_name
629 def _tmp_filename(self):
630 return self.page_name + '.tmp' + str(os.getpid()) + '#'
634 return os.stat(self._filename()).st_mtime
636 if err.errno == errno.ENOENT:
645 def get_raw_body(self, default=None):
647 return open(self._filename(), 'rb').read()
649 if err.errno == errno.ENOENT:
651 default = '//[[?a=edit&q=%s|Describe %s]]//' % (self.page_name, self.page_name)
653 if err.errno == errno.EISDIR:
654 return self.format_dir()
657 def format_dir(self):
660 for dirname in self.page_name.strip('/').split('/'):
661 pathname = (pathname and pathname + '/' ) + dirname
662 out += '[[' + pathname + '|' + dirname + ']]/'
666 for filename in page_list(self._filename(), file_re):
667 if image_re.match(filename):
668 maxwidth = config_get('image_maxwidth', '400')
670 maxwidth = ' | maxwidth=' + str(maxwidth)
671 images_out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth + ' | class=thumbleft}}\n'
673 out += ' * [[' + self.page_name + '/' + filename + ']]\n'
674 return out + images_out
677 if not '_pragmas' in self.__dict__:
680 file = open(self._filename(), 'rt')
681 attr_re = re.compile(r"^#(\S*)(.*)$")
683 m = attr_re.match(line)
686 self._pragmas[m.group(1)] = m.group(2).strip()
687 #print "bernie: pragmas[" + m.group(1) + "] = " + m.group(2) + "<br>\n"
689 if err.errno != errno.ENOENT and err.errno != errno.EISDIR:
693 def pragma(self, name, default):
694 return self.pragmas().get(name, default)
696 def can(self, action, default=True):
699 #acl SomeUser:read,write All:read
700 acl = self.pragma("acl", None)
701 for rule in acl.split():
702 (user, perms) = rule.split(':')
703 if user == remote_user() or user == "All":
704 return action in perms.split(',')
708 self.msg_text = 'Illegal acl line: ' + acl
712 return self.can("write", True)
715 return self.can("read", True)
717 def send_footer(mtime=None, footer="sys/footer"):
718 if config_get('debug_cgi', False):
719 cgi.print_arguments()
723 link_inline(footer, kvargs = {
724 'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%a %d %b %Y %I:%M %p'), localtime(mtime))
726 print("</body></html>")
728 def send_naked(self, kvargs=None):
730 WikiFormatter(self.get_raw_body(), kvargs).print_html()
732 send_guru("Read access denied by ACLs", "notice")
736 value = self.pragma("css", None)
739 link_urls += [ [ "stylesheet", value ] ]
741 send_title(self.page_name, self.split_title(),
742 msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write(), mtime=self._mtime(),
743 navbar=self.pragma("navbar", "on"))
745 self.send_footer(mtime=self._mtime(), footer=self.pragma("footer", "sys/footer"))
747 def send_editor(self, preview=None):
748 send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
749 if not self.can_write():
750 send_guru("Write access denied by ACLs", "error")
754 preview = self.get_raw_body(default='')
756 link_inline("sys/EditPage", kvargs = {
757 'EDIT_BODY': cgi.escape(preview),
758 #'EDIT_PREVIEW': WikiFormatter(preview).print_html(),
762 print("<div class='preview'>")
763 WikiFormatter(preview).print_html()
767 def send_raw(self, mimetype='text/plain', args=[]):
768 if not self.can_read():
769 send_title(None, msg_text='Read access denied by ACLs', msg_type='notice', mtime=self._mtime())
772 emit_header(self._mtime(), mimetype)
773 if 'maxwidth' in args:
776 subprocess.check_call(['gm', 'convert', self._filename(),
777 '-scale', args['maxwidth'].value + ' >', '-'])
779 body = self.get_raw_body()
782 def _write_file(self, data):
783 tmp_filename = self._tmp_filename()
784 open(tmp_filename, 'wb').write(data)
785 name = self._filename()
787 # Bad Bill! POSIX rename ought to replace. :-(
791 if err.errno != errno.ENOENT: raise err
792 path = os.path.split(name)[0]
793 if path and not os.path.exists(path):
795 os.rename(tmp_filename, name)
797 def save(self, newdata, changelog):
798 if not self.can_write():
799 self.msg_text = 'Write access denied by Access Control List'
801 if not is_privileged():
802 self.msg_text = 'Unauthenticated access denied'
805 self._write_file(newdata)
807 if config_get('post_edit_hook'):
810 config_get('post_edit_hook'),
811 self.page_name, remote_user(),
812 remote_host(), changelog ]
813 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
814 output = child.stdout.read()
817 self.msg_text += "Post-editing hook returned %d. Command was:\n'%s'\n" % (rc, "' '".join(cmd))
819 self.msg_text += 'Output follows:\n' + output
821 self.msg_text = 'Thank you for your contribution. Your attention to detail is appreciated.'
822 self.msg_type = 'success'
825 exec(open("geekigeeki.conf.py").read())
826 os.chdir(config_get('data_dir', 'data'))
827 form = cgi.FieldStorage()
828 action = form.getvalue('a', 'get')
829 handler = globals().get('handle_' + action)
831 handler(query_string(), form)
833 send_httperror("403 Forbidden", query_string())
837 msg_text = traceback.format_exc()
839 send_guru(msg_text, "error")
841 send_title(None, msg_text=msg_text)