changeset 508:19604cb73d76

macro.ListPages: refactored for argument parser
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 19 Mar 2010 19:01:51 +0100
parents d0a99da9ad77
children 2bf20bdbbde9
files data/plugin/macro/ListPages.py
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/ListPages.py	Thu Mar 18 11:23:11 2010 +0100
+++ b/data/plugin/macro/ListPages.py	Fri Mar 19 19:01:51 2010 +0100
@@ -6,7 +6,7 @@
 
     @copyright: @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
                 2003-2008 MoinMoin:ThomasWaldmann
-                2009 MoinMoin:ReimarBauer
+                2009-2010 MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -15,23 +15,24 @@
 import re
 from MoinMoin import search, wikiutil
 
-def execute(macro, args):
+def macro_ListPages(macro, search_term=u'.+'):
+    """
+    lists pages
+    @param search_term: regex for searching of page titles
+    """
     _ = macro._
     case = 0
 
-    # If called with empty or no argument, default to regex search for .+, the full page list.
-    needle = wikiutil.get_unicode(macro.request, args, 'needle', u'regex:.+')
-
     # With whitespace argument, return same error message as FullSearch
-    if not needle.strip():
-        err = _('Please use a more selective search term instead of {{{"%s"}}}', wiki=True) % needle
-        return '<span class="error">%s</span>' % err
+    if not search_term.strip():
+        msg = _('Please use a more selective search term instead of {{{"%s"}}}', wiki=True) % search_term
+        return '<span class="error">%s</span>' % msg
 
     # Return a title search for needle, sorted by name.
     # based on rootpage.getPageList because search does also list attachments
     try:
         rootpage = macro.request.rootpage
-        filterfn = re.compile(ur"%s" % re.escape(needle), re.U).match
+        filterfn = re.compile(ur"%s" % re.escape(search_term), re.U).match
         pageobjs = rootpage.getPageList(include_underlay=False, exists=1, filter=filterfn, return_objects=True)
         f = macro.request.formatter
         ret = [''.join([f.listitem(1),
@@ -45,6 +46,6 @@
         ret = ''.join([macro.formatter.text('<<PageList('),
                       _('Your search query {{{"%s"}}} is invalid. Please refer to '
                         'HelpOnSearching for more information.', wiki=True,
-                        percent=True) % wikiutil.escape(needle),
+                        percent=True) % wikiutil.escape(search_term),
                       macro.formatter.text(')>>')])
     return ret