view MoinMoin/macro/ @ 3622:29ae93c888f2

fix PageList macro with search errors
author Johannes Berg <johannes AT sipsolutions DOT net>
date Mon, 19 May 2008 16:44:53 +0200
parents c1fa007b9e2f
children 8e5559a0a08b
line wrap: on
line source

# -*- coding: iso-8859-1 -*-
    MoinMoin - PageList

    print a list of pages whose title matches the search term

    @copyright: @copyright: 2001-2003 Juergen Hermann <>,
                2003-2008 MoinMoin:ThomasWaldmann
                2008 MoinMoin:ReimarBauer
    @license: GNU GPL, see COPYING for details.

Dependencies = ["namespace"]
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.
        results = search.searchPages(macro.request, needle,
                                     titlesearch=1, case=case,
        ret = results.pageList(macro.request, macro.formatter, paging=False)
    except ValueError:
        # same error as in MoinMoin/action/, 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),
    return ret