Details

Applies to
moin-1.6.3 (should be applicable to moin-1.5 as well)
Purpose
Get rid of warnings like "Include: Nothing found for...", just ignore non-matched pages
Description

When from or to parameters are supplied to the Include macro (HelpOnMacros/Include), for every included page that doesn't match the above parameters, the warning is issued and the page is included anyway.
This patch is to add an optional parameter ignorenotfound to silently ignore the pages that don't match from or to regexes.
If ignorenotfound is absent, the macro acts as it currently does.

By

MaximYanchenko

Patch

   1 --- moin-1.6.3/MoinMoin/macro/Include.py	2008-02-20 06:46:33.000000000 +0900
   2 +++ pkg/x86_64/lib/python2.4/site-packages/MoinMoin/macro/Include.py	2008-05-26 13:54:28.965396000 +0900
   3 @@ -32,9 +32,10 @@
   4  _arg_skipitems = r'(,\s*skipitems=(?P<skipitems>\d+))?'
   5  _arg_titlesonly = r'(,\s*(?P<titlesonly>titlesonly))?'
   6  _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
   7 -_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s)?$' % (
   8 +_arg_ignorenotfound = r'(,\s*(?P<ignorenotfound>ignorenotfound))?'
   9 +_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s%s)?$' % (
  10      _arg_heading, _arg_level, _arg_from, _arg_to, _arg_sort, _arg_items,
  11 -    _arg_skipitems, _arg_titlesonly, _arg_editlink)
  12 +    _arg_skipitems, _arg_titlesonly, _arg_editlink, _arg_ignorenotfound)
  13  
  14  _title_re = r"^(?P<heading>\s*(?P<hmarker>=+)\s.*\s(?P=hmarker))$"
  15  
  16 @@ -95,6 +96,7 @@
  17          skipitems = int(args.group("skipitems"))
  18      titlesonly = args.group('titlesonly')
  19      editlink = args.group('editlink')
  20 +    ignorenotfound = args.group('ignorenotfound')
  21  
  22      # iterate over pages
  23      for inc_name in pagelist:
  24 @@ -127,7 +129,11 @@
  25              if from_match:
  26                  from_pos = from_match.end()
  27              else:
  28 -                result.append(_sysmsg % ('warning', 'Include: ' + _('Nothing found for "%s"!', formatted=False)) % from_re)
  29 +                if ignorenotfound:
  30 +                    continue
  31 +                else:
  32 +                    result.append(_sysmsg % ('warning', 'Include: ' + _('Nothing found for "%s"!', formatted=False)) % from_re)
  33 +
  34          to_re = args.group('to')
  35          if to_re:
  36              try:
  37 @@ -137,7 +143,10 @@
  38              if to_match:
  39                  to_pos = to_match.start()
  40              else:
  41 -                result.append(_sysmsg % ('warning', 'Include: ' + _('Nothing found for "%s"!', formatted=False)) % to_re)
  42 +                if ignorenotfound:
  43 +                    continue
  44 +                else:
  45 +                    result.append(_sysmsg % ('warning', 'Include: ' + _('Nothing found for "%s"!', formatted=False)) % to_re)
  46  
  47          if titlesonly:
  48              levelstack = []
  49 --- moin-1.6.3/MoinMoin/macro/TableOfContents.py	2008-03-29 06:15:00.000000000 +0900
  50 +++ pkg/x86_64/lib/python2.4/site-packages/MoinMoin/macro/TableOfContents.py	2008-05-26 13:51:35.058413000 +0900
  51 @@ -24,9 +24,10 @@
  52  _arg_skipitems = r'(,\s*skipitems=(?P<skipitems>\d+))?'
  53  _arg_titlesonly = r'(,\s*(?P<titlesonly>titlesonly))?'
  54  _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
  55 -_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s)?$' % (
  56 +_arg_ignorenotfound = r'(,\s*(?P<ignorenotfound>ignorenotfound))?'
  57 +_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s%s)?$' % (
  58      _arg_heading, _arg_level, _arg_from, _arg_to, _arg_sort, _arg_items,
  59 -    _arg_skipitems, _arg_titlesonly, _arg_editlink)
  60 +    _arg_skipitems, _arg_titlesonly, _arg_editlink, _arg_ignorenotfound)
  61  
  62  # from Include, too, but with extra htext group around header text
  63  _title_re = r"^(?P<heading>(?P<hmarker>=+)\s(?P<htext>.*)\s(?P=hmarker))$"
  64 --- moin-1.6.3/wiki/underlay/pages/HelpOnMacros(2f)Include/revisions/00000001	2008-04-21 00:59:24.000000000 +0900
  65 +++ pkg/x86_64/share/moin/underlay/pages/HelpOnMacros(2f)Include/revisions/00000001	2008-05-26 14:45:28.850534000 +0900
  66 @@ -14,7 +14,7 @@
  67  
  68  '''Usage:'''
  69   {{{
  70 -<<Include(pagename, heading, level, from="regex", to="regex", sort=ascending|descending, items=n, skipitems=n, titlesonly, editlink)>>
  71 +<<Include(pagename, heading, level, from="regex", to="regex", sort=ascending|descending, items=n, skipitems=n, titlesonly, editlink, ignorenotfound)>>
  72  }}}
  73  
  74   pagename:: Name of the page to include, if it starts with a caret "`^`", a regex of pages to include.
  75 @@ -27,6 +27,7 @@
  76   skipitems:: Number of initial pages to skip over (optional).
  77   titlesonly:: Only include a link to the page, not page content (optional).
  78   editlink:: add a footer with links to the included page, both normal and edit (optional).
  79 + ignorenotfound:: don't include pages that fail to match `from` or `to` regexes (optional).
  80   
  81  All parameters except pagename are optional, but you have to follow the given order! If you want to omit "`heading`", you have to leave the second parameter empty.
  82  

include_only_successfully_matched_pages.patch

Discussion

/PageOne
/PageTwo

This is how it works now

Page One

I want this page to be included!

Include: Nothing found for "^##include this"!

Page Two

I DON'T want this page to be included!

This is how it works with the new option

Page One

I want this page to be included!

Plan


CategoryMoinMoinPatch

MoinMoin: MoinMoinPatch/IncludeOnlySuccessfullyMatchedPages (last edited 2008-05-26 06:15:37 by MaximYanchenko)