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