1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - PageListPlus 4 5 print a list of pages whose title matches the search term 6 7 @copyright: 2010 Paul Boddie <paul@boddie.org.uk> 8 @license: GNU GPL, see COPYING for details. 9 """ 10 11 Dependencies = ["pages"] 12 from MoinMoin import wikiutil 13 import ImprovedMoinSearch 14 import re 15 16 format_pattern = re.compile("""format:(?P<quote>['"])(?P<format>.*?)(?P=quote)""") 17 paging_pattern = re.compile("""paging:(?P<paging>on|off|yes|no|true|false)""") 18 19 def extract_option(query, pattern, group): 20 21 """ 22 Remove from 'query', using the given regular expression 'pattern' object, 23 a particular form of argument text, accessing such text through the group 24 with the given 'group' name, and returning a tuple of the form 25 (edited_query, value_of_group). 26 """ 27 28 m = pattern.search(query) 29 if m: 30 value = m.group(group) 31 query = query[:m.start()] + query[m.end():] 32 else: 33 value = None 34 return query, value 35 36 # Macro functions. 37 38 def execute(macro, args): 39 40 """ 41 Execute the 'macro' with the given 'args': 42 """ 43 44 request = macro.request 45 formatter = macro.formatter 46 _ = macro._ 47 48 # If called with empty or no argument, default to regex search for .+, the full page list. 49 50 needle = wikiutil.get_unicode(request, args, 'needle', u'regex:.+') 51 52 # Extract format and paging options. 53 54 needle, format = extract_option(needle, format_pattern, "format") 55 needle, paging = extract_option(needle, paging_pattern, "paging") 56 57 # With whitespace argument, return same error message as FullSearch. 58 59 if not needle.strip(): 60 err = _('Please use a more selective search term instead of {{{"%s"}}}', wiki=True) % needle 61 return '<span class="error">%s</span>' % err 62 63 # Return a title search for needle, sorted by name. 64 65 try: 66 pages = ImprovedMoinSearch.getSearchResultPages(request, needle, titlesearch=1, sort='page_name') 67 68 # Format the results. 69 70 ret = ImprovedMoinSearch.formatResultPages(request, formatter, pages, paging, format) 71 72 except ValueError: 73 74 # Same error as in MoinMoin/action/fullsearch.py, keep it that way! 75 76 ret = ''.join([formatter.text('<<PageListPlus('), 77 _('Your search query {{{"%s"}}} is invalid. Please refer to ' 78 'HelpOnSearching for more information.', wiki=True, 79 percent=True) % wikiutil.escape(needle), 80 formatter.text(')>>')]) 81 82 return ret 83 84 # vim: tabstop=4 expandtab shiftwidth=4