changeset 458:ab5d047d3fa9

macro ListPages: lists only pages without attachments based on filter matching of rootpage.getPageList. Also if xapian is enabled.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 23 Nov 2009 00:29:00 +0100
parents c1ce8d0fec5d
children a725a4651011
files data/plugin/macro/ListPages.py
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/plugin/macro/ListPages.py	Mon Nov 23 00:29:00 2009 +0100
@@ -0,0 +1,50 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - ListPages
+
+    print a list of pages whose title matches the filter term of getPageList
+
+    @copyright: @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
+                2003-2008 MoinMoin:ThomasWaldmann
+                2009 MoinMoin:ReimarBauer
+    @license: GNU GPL, see COPYING for details.
+"""
+
+Dependencies = ["namespace"]
+
+import re
+from MoinMoin import search, wikiutil
+
+def execute(macro, args):
+    _ = 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
+
+    # 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
+        pageobjs = rootpage.getPageList(include_underlay=False, exists=1, filter=filterfn, return_objects=True)
+        f = macro.request.formatter
+        ret = [''.join([f.listitem(1),
+               f.url(1, href=page.url(macro.request, escape=0)),
+               page.page_name,
+               f.url(0)]) for page in pageobjs]
+        ret.sort()
+        ret = ''.join([f.number_list(1), ''.join(ret), f.number_list(0)])
+    except ValueError:
+        # same error as in MoinMoin/action/fullsearch.py, keep it that way!
+        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),
+                      macro.formatter.text(')>>')])
+    return ret