--- Page.py.orig        Fri Jan 18 21:42:47 2008
+++ Page.py     Wed Mar 26 08:53:50 2008
@@ -1161,6 +1161,16 @@
         elif not request.user.may.read(self.page_name):
             request.write("<strong>%s</strong><br>" % _("You are not allowed to view this page.", formatted=False))
         else:
+            # if the config file has the "auto_toc" setting, insert a table
+            # of contents if the page has any headings
+            want_toc = True
+            try:
+                want_toc = self.cfg.auto_toc
+            except:
+                pass
+            if want_toc and pi['format'] == 'wiki' and not send_missing_page and (body.find("\n= ") >= 0 or body.find("\n== ") >= 0):
+                body = "<<TableOfContents>>\n" + body
+
             # start wiki content div
             request.write(self.formatter.startContent(content_id))

