1.1 --- a/ImprovedMoinSearch.py Fri Jun 25 01:48:21 2010 +0200
1.2 +++ b/ImprovedMoinSearch.py Mon Jun 28 01:39:21 2010 +0200
1.3 @@ -8,6 +8,7 @@
1.4
1.5 from MoinMoin.search import searchPages
1.6 from MoinMoin.Page import Page
1.7 +from MoinMoin import wikiutil
1.8 import re
1.9
1.10 heading_regexp = re.compile(r"^(?P<level>=+)(?P<heading>.*?)(?P=level)$", re.UNICODE | re.MULTILINE)
1.11 @@ -44,15 +45,23 @@
1.12
1.13 return None
1.14
1.15 -def formatResultPages(request, formatter, pages, paging, format):
1.16 +def formatResultPages(request, formatter, pages, paging, format, page_from=0):
1.17
1.18 """
1.19 Using the given 'request' and 'formatter', return a formatted string showing
1.20 the result 'pages', providing paging controls when 'paging' is set to a true
1.21 value, and providing page details according to the given 'format'.
1.22 +
1.23 + If the optional 'pages_from' parameter is set, the result pages from the
1.24 + given result (specified within a range from 0 to the length of the 'pages'
1.25 + collection) will be shown.
1.26 """
1.27
1.28 - m = heading_options_regexp.search(format)
1.29 + if format:
1.30 + m = heading_options_regexp.search(format)
1.31 + else:
1.32 + m = None
1.33 +
1.34 if m:
1.35 format = "heading"
1.36 min_level = int_or_none(m.group("min"))
1.37 @@ -60,11 +69,22 @@
1.38 else:
1.39 format = "name"
1.40
1.41 + # Use paging only when there are enough results.
1.42 +
1.43 + results_per_page = request.cfg.search_results_per_page
1.44 + paging = paging and len(pages) > results_per_page
1.45 +
1.46 + if paging:
1.47 + pages_to_show = pages[page_from:page_from + results_per_page]
1.48 + else:
1.49 + pages_to_show = pages
1.50 +
1.51 + # Prepare the output.
1.52 +
1.53 output = []
1.54 -
1.55 output.append(formatter.number_list(on=1))
1.56
1.57 - for page in pages:
1.58 + for page in pages_to_show:
1.59 output.append(formatter.listitem(on=1))
1.60
1.61 if format == "heading":
1.62 @@ -79,8 +99,65 @@
1.63
1.64 output.append(formatter.number_list(on=0))
1.65
1.66 + # Show paging navigation.
1.67 +
1.68 + if paging:
1.69 + output.append(formatPagingNavigation(request, formatter, pages, page_from))
1.70 +
1.71 return "".join(output)
1.72
1.73 +def formatPagingNavigation(request, formatter, pages, page_from=0):
1.74 +
1.75 + """
1.76 + Using the given 'request' and 'formatter', return a formatted string showing
1.77 + the paging navigation for the result 'pages', according to the 'page_from'
1.78 + indicator which provides the current position in the result set.
1.79 + """
1.80 +
1.81 + _ = request.getText
1.82 +
1.83 + output = []
1.84 +
1.85 + results_per_page = request.cfg.search_results_per_page
1.86 + number_of_results = len(pages)
1.87 +
1.88 + pages_total = number_of_results / results_per_page
1.89 + pages_before = page_from / results_per_page
1.90 + pages_after = ((number_of_results - page_from) / results_per_page) - 1
1.91 +
1.92 + querydict = wikiutil.parseQueryString(request.query_string)
1.93 +
1.94 + output.append(formatter.paragraph(on=1))
1.95 + output.append(formatter.text(_("Result pages:")))
1.96 + output.append(formatter.text(" "))
1.97 +
1.98 + n = 0
1.99 + while n < pages_before:
1.100 + output.append(formatter.pagelink(on=1, querystr=getPagingQueryString(querydict, n * results_per_page)))
1.101 + output.append(formatter.text(str(n + 1)))
1.102 + output.append(formatter.pagelink(on=0))
1.103 + output.append(formatter.text(" "))
1.104 + n += 1
1.105 +
1.106 + output.append(formatter.text(str(n + 1)))
1.107 + output.append(formatter.text(" "))
1.108 + n += 1
1.109 +
1.110 + while n < pages_total:
1.111 + output.append(formatter.pagelink(on=1, querystr=getPagingQueryString(querydict, n * results_per_page)))
1.112 + output.append(formatter.text(str(n + 1)))
1.113 + output.append(formatter.pagelink(on=0))
1.114 + output.append(formatter.text(" "))
1.115 + n += 1
1.116 +
1.117 + output.append(formatter.paragraph(on=0))
1.118 +
1.119 + return "".join(output)
1.120 +
1.121 +def getPagingQueryString(querydict, page_from):
1.122 + querydict["from"] = page_from
1.123 + return wikiutil.makeQueryString(querydict)
1.124 +
1.125 def int_or_none(x):
1.126 if x is None:
1.127 return x
2.1 --- a/macros/PageListPlus.py Fri Jun 25 01:48:21 2010 +0200
2.2 +++ b/macros/PageListPlus.py Mon Jun 28 01:39:21 2010 +0200
2.3 @@ -25,7 +25,7 @@
2.4 (edited_query, value_of_group).
2.5 """
2.6
2.7 - m = format_pattern.search(query)
2.8 + m = pattern.search(query)
2.9 if m:
2.10 value = m.group(group)
2.11 query = query[:m.start()] + query[m.end():]