#format Python """ MoinMoin - IncludePages macro Copyright (c) 2002 by Michael Reinsch All rights reserved, see COPYING for details. Code based on the MoinMoin PageList macro Copyright (c) 2000, 2001, 2002 by Jürgen Hermann This macro includes the formatted content of the given pages, following recursive includes if encountered. Cycles are detected! It uses the MoinMoin Include macro which does the real work. Usage: [[IncludePages(pagepattern,level)]] pagepattern Pattern of the page(s) to include level Level (1..5) of the generated heading (optional) The headings for the included pages will be generated from the page names Examples: [[IncludePages(FooBar/20.*)]] -- includes all pages which start with FooBar/20 this is usefull in combination with the MonthCalendar macro [[IncludePages(FooBar/20.*, 2)]] -- set level to 2 (default is 1) $Id$ """ import re from MoinMoin import user from MoinMoin import config from MoinMoin import wikiutil from MoinMoin.i18n import _ import MoinMoin.macro.Include _arg_level = r',\s*(?P\d+)' _args_re_pattern = r'^(?P[^,]+)(%s)?$' % (_arg_level,) def execute(macro, text, args_re=re.compile(_args_re_pattern)): ret = '' # parse and check arguments args = args_re.match(text) if not args: return ('

%s

' % _('Invalid include arguments "%s"!')) % (text,) # get the pages inc_pattern = args.group('pattern') if args.group('level'): level = int(args.group('level')) else: level = 1 try: needle_re = re.compile(inc_pattern, re.IGNORECASE) except re.error, e: return ('

%s

' % _("ERROR in regex '%s'") % (inc_pattern,), e) all_pages = wikiutil.getPageList(config.text_dir) hits = filter(needle_re.search, all_pages) hits.sort() for inc_name in hits: params = '%s,,%s' % (inc_name, level) ret = ret +"

"+ MoinMoin.macro.Include.execute(macro, params) +"\n" # return include text return ret