Update to gitweb 1.5.6.5
[geekigeeki.git] / geekigeeki.py
index 64333eaf0605d79abdc674eb9a5042fed05e5050..1221e701f7f1437d09cc64913287da0ebf90b9cb 100755 (executable)
@@ -85,7 +85,7 @@ def send_guru(msg_text, msg_type):
         print '    Software Failure.  Press left mouse button to continue.\n'
     print msg_text
     if msg_type == 'error':
-        print '      Guru Meditation #DEADBEEF.ABADC0DE'
+        print '\n      Guru Meditation #DEADBEEF.ABADC0DE'
     print '</pre>'
     # FIXME: This little JS snippet is harder to pass than ACID 3.0 
     print """
@@ -126,6 +126,10 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
     if not name:
         print ' <meta name="robots" content="noindex,nofollow" />'
 
+    for meta in meta_urls:
+        http_equiv, content = meta
+        print ' <meta http-equiv="%s" content="%s" />' % (http_equiv, relative_url(content))
+
     for link in link_urls:
         rel, href = link
         print ' <link rel="%s" href="%s" />' % (rel, relative_url(href))
@@ -179,6 +183,11 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
 
     print '<hr /></div>'
 
+def send_httperror(status="403 Not Found", query=""):
+    print "Status: %s" % status
+    send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
+    send_footer(None)
+
 def link_tag(params, text=None, ss_class=None, privileged=False):
     if text is None:
         text = params # default
@@ -240,15 +249,23 @@ def print_search_stats(hits, searched):
     print "<p>%d hits out of %d pages searched.</p>" % (hits, searched)
 
 def handle_raw(pagename):
+    if not file_re.match(pagename):
+        send_httperror("403 Forbidden", pagename)
+        return
+
     Page(pagename).send_raw()
 
 def handle_edit(pagename):
+    if not file_re.match(pagename):
+        send_httperror("403 Forbidden", pagename)
+        return
+
     pg = Page(pagename)
     if 'save' in form:
         if form['file'].value:
-            pg.save(form['file'].file.read())
+            pg.save(form['file'].file.read(), form['changelog'].value)
         else:
-            pg.save(form['savetext'].value.replace('\r\n', '\n'))
+            pg.save(form['savetext'].value.replace('\r\n', '\n'), form['changelog'].value)
         pg.format()
     elif 'cancel' in form:
         pg.msg_text = 'Editing canceled'
@@ -353,7 +370,11 @@ class WikiFormatter:
 
         macro = globals().get('_macro_' + name)
         if not macro:
-            execfile("macros/" + name + ".py", globals())
+            try:
+                execfile("macros/" + name + ".py", globals())
+            except IOError, er:
+                if er.errno == errno.ENOENT:
+                    pass
             macro = globals().get('_macro_' + name)
         if macro:
             return macro(argv)
@@ -498,7 +519,7 @@ class WikiFormatter:
             + r"|(?P<hurl>\[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])"
 
             # Inline HTML
-            + r"|(?P<html><(/|)(br|hr|div|form|iframe|input|span))"
+            + r"|(?P<html><(/|)(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])[^>]*>)"
             + r"|(?P<ent>[<>&])"
 
             # Auto links (LEGACY)
@@ -544,7 +565,7 @@ class WikiFormatter:
                     print '</p><p>'
                 else:
                     indent = indent_re.match(self.line)
-                    print self._indent_to(len(indent.group(0)))
+                    print self._indent_to(len(indent.group(0))) ,
                     print re.sub(scan_re, self.replace, self.line)
 
         if self.in_pre: print '</pre>'
@@ -694,18 +715,25 @@ class Page:
             + ' for ' + cgi.escape(remote_user())
             + ' from ' + cgi.escape(get_hostname(remote_host()))
             + '</b></p>')
-        print '<div class="editor"><form method="post" enctype="multipart/form-data" action="%s">' % relative_url(self.page_name)
+        print '<div class="editor"><form name="editform" 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 'Or upload a file: <input type="file" name="file" value="%s" />' % file
+        print '<input type="input" id="editor" name="changelog" value="Edit page %s" accesskey="c" /><br />' % (self.page_name)
+        print '<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100" accesskey="e">%s</textarea>' % cgi.escape(preview or self.get_raw_body())
+        print '<label for="file" accesskey="u">Or Upload a file:</label> <input type="file" name="file" value="%s" />' % file
         print """
             <br />
-            <input type="submit" name="save" value="Save" />
-            <input type="submit" name="preview" value="Preview" />
+            <input type="submit" name="save" value="Save" accesskey="s">
+            <input type="submit" name="preview" value="Preview" accesskey="p" />
             <input type="reset" value="Reset" />
             <input type="submit" name="cancel" value="Cancel" />
             <br />
-            </form></div>"""
+            </form></div>
+            <script language="javascript">
+            <!--
+            document.editform.savetext.focus()
+            //-->
+            </script>
+            """
         print "<p>" + Page('EditingTips').link_to() + "</p>"
         if preview:
             print "<div class='preview'>"
@@ -743,7 +771,7 @@ class Page:
                 if er.errno != errno.ENOENT: raise er
         os.rename(tmp_filename, name)
 
-    def save(self, newdata):
+    def save(self, newdata, changelog):
         if not self.can_write():
             self.msg_text = 'Write access denied by ACLs'
             self.msg_type = 'error'
@@ -756,7 +784,8 @@ class Page:
             cmd = ( post_edit_hook
                 + " '" + data_dir + '/' + self.page_name
                 + "' '" + remote_user()
-                + "' '" + remote_host() + "'"
+                + "' '" + remote_host()
+               + "' '" + changelog + "'"
             )
             out = os.popen(cmd)
             output = out.read()
@@ -803,9 +832,7 @@ try:
                 else:
                     Page(query).format()
         else:
-            print "Status: 404 Not Found"
-            send_title(None, msg_text='Can\'t work out query: ' + query)
-            send_footer(None)
+            send_httperror("403 Forbidden", query)
 except Exception:
     import traceback
     msg_text = traceback.format_exc()