Index: tocmacro/0.11/tractoc/macro.py
===================================================================
--- tocmacro/0.11/tractoc/macro.py	(revision 2460)
+++ tocmacro/0.11/tractoc/macro.py	(working copy)
@@ -6,6 +6,7 @@
 from genshi.builder import tag
 
 from trac.core import *
+from trac.util.compat import sorted
 from trac.wiki.formatter import OutlineFormatter, system_message
 from trac.wiki.api import WikiSystem, parse_args
 from trac.wiki.macros import WikiMacroBase 
@@ -68,6 +69,11 @@
           TracRoadmap, TracChangeset, TracTickets, TracReports, TracQuery,
           TracTimeline, TracRss, TracNotification)]]
     }}}
+    A wildcard '*' can be used to fetch a sorted list of all pages starting with
+    the preceding pagename stub:
+    {{{
+    [[TOC(Trac*, WikiFormatting, WikiMacros)]]
+    }}}
     The following ''control'' arguments change the default behaviour of
     the TOC macro: 
     || '''Argument'''    || '''Meaning''' ||
@@ -76,9 +82,11 @@
     || {{{depth=<n>}}}   || Display headings of ''subsequent'' pages to a maximum depth of '''<n>'''. ||
     || {{{inline}}}      || Display TOC inline rather than as a side-bar. ||
     || {{{titleindex}}}  || Only display the page name and title of each page, similar to TitleIndex. ||
-    
-    Note that the current page must also be specified if individual wiki
-    pages are given in the argument list.
+    || {{{notitle}}}     || Supress display of page title. ||
+    For 'titleindex' argument, an empty pagelist will evaluate to all pages:
+    {{{
+    [[TOC(titleindex, notitle, heading=All pages)]]
+    }}}
     """
     
     def expand_macro(self, formatter, name, args):
@@ -97,8 +105,8 @@
         # Options
         inline = False
         pagenames = []
-        heading = kw.pop('heading', 'Table of Contents')
         
+        default_heading = 'Table of Contents'
         params = {'min_depth': 1, 'max_depth': 6}
         # Global options
         for arg in args:
@@ -106,25 +114,38 @@
             if arg == 'inline':
                 inline = True
             elif arg == 'noheading':
-                heading = ''
+                default_heading = ''
             elif arg == 'notitle':
                 params['min_depth'] = 2     # Skip page title
             elif arg == 'titleindex':
                 params['title_index'] = True
-                heading = ''
+                default_heading = default_heading and 'Page Index'
             elif arg == 'nofloat':
                 return ''
             elif arg != '':
                 pagenames.append(arg)
+        heading = kw.pop('heading', '') or default_heading
 
         if 'depth' in kw:
            params['max_depth'] = int(kw['depth'])
 
         # Has the user supplied a list of pages?
-        if not pagenames and 'title_index' not in params:
-            pagenames.append(current_page)
-            params['root'] = ''
-            params['min_depth'] = 2     # Skip page title
+        if not pagenames:
+            if 'title_index' in params:
+                pagenames.append('*')       # A marker for 'all'
+            else:
+                pagenames.append(current_page)
+                params['root'] = ''
+                params['min_depth'] = 2     # Skip page title
+        # Check for wildcards and expand lists
+        temp_pagenames = []
+        for pagename in pagenames:
+            if pagename.endswith('*'):
+                temp_pagenames.extend(sorted(
+                        WikiSystem(self.env).get_pages(pagename[:-1])))
+            else:
+                temp_pagenames.append(pagename)
+        pagenames = temp_pagenames
 
         base = tag.div(class_=not inline and 'wiki-toc' or '')
         ol = tag.ol()
@@ -134,14 +155,13 @@
         if pagenames:
             for pagename in pagenames:
                 if 'title_index' in params:
-                    prefix = pagename.split('/')[0]
-                    prefix = prefix.replace("'", "''") # FIXME: what's this?
-                    self._render_title_index(ol, prefix, active and \
-                                             pagename.startswith(current_page))
+                    self._render_title_index(ol, pagename, active and \
+                                pagename == current_page,
+                                params['min_depth'] < 2)
                 else:
                     self._render_page_outline(ol, pagename, active, params)
         else:
-            self._render_title_index(ol, '', False)
+            self._render_title_index(ol, '', False, False)
         return base
 
     def get_page_text(self, pagename):
@@ -149,30 +169,24 @@
         if pagename == self.formatter.context.id:
             return (self.formatter.source, True)
         else:
-            # TODO: after sandbox/security merge
-            # page = context(id=pagename).resource
-            from trac.wiki.model import WikiPage
-            page = WikiPage(self.env, pagename, db=self.formatter.db)
+            page = self.formatter.context(id=pagename).resource
             return (page.text, page.exists)
 
-    def _render_title_index(self, ol, prefix, active):
-        all_pages = list(WikiSystem(self.env).get_pages(prefix))
-        if all_pages:
-            all_pages.sort()
-            for page in all_pages:
-                ctx = self.formatter.context('wiki', page)
-                fmt = OutlineFormatter(ctx)
-                page_text, _ = self.get_page_text(page) # ctx.resource.text
-                fmt.format(page_text, NullOut())
-                title = ''
-                if fmt.outline:
-                    title = ': ' + fmt.outline[0][2]
-                ol.append((tag.li(tag.a(page, href=ctx.resource_href()),
-                                  Markup(title),
-                                  class_= active and 'active' or None)))
-        else:
+    def _render_title_index(self, ol, page, active, show_title):
+        if not WikiSystem(self.env).has_page(page):
             ol.append(system_message('Error: No page matching %s found' %
-                                     prefix))
+                                     page))
+            return            
+        ctx = self.formatter.context('wiki', page)
+        fmt = OutlineFormatter(ctx)
+        page_text = ctx.resource.text
+        fmt.format(page_text, NullOut())
+        title = ''
+        if show_title and fmt.outline:
+            title = ': ' + fmt.outline[0][2]
+        ol.append((tag.li(tag.a(page, href=ctx.resource_href()),
+                          Markup(title),
+                          class_= active and 'active' or None)))
 
     def _render_page_outline(self, ol, pagename, active, params):
         page = params.get('root', '') + pagename
