view data/plugin/macro/ @ 511:ef1f74bf4776

macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 19 Mar 2010 22:59:00 +0100
parents 2bf20bdbbde9
children 56cbdae11f25
line wrap: on
line source
# -*- 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 <>,
                2003-2008 MoinMoin:ThomasWaldmann
                2009-2010 MoinMoin:ReimarBauer
    @license: GNU GPL, see COPYING for details.

Dependencies = ["namespace"]

import re
from MoinMoin import search, wikiutil

def macro_ListPages(macro, search_term=u'.+'):
    lists pages
    @param search_term: regex for searching of page titles
    _ = macro._
    case = 0

    # With whitespace argument, return same error message as FullSearch
    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
        rootpage = macro.request.rootpage
        filterfn = re.compile(ur"%s" % 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),
               f.url(1, href=page.url(macro.request, escape=0)),
               f.url(0)]) for page in pageobjs]
        ret = ''.join([f.number_list(1), ''.join(ret), f.number_list(0)])
    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(search_term),
    return ret