changeset 785:e0c61257b6c4 pytest2

whooshify include converter (use wildcard instead of regex term for now) whoosh has upcoming regex term support, but it is not released yet, so we use a wildcard term for now and get rid of the leading ^ that Include macro needs for getting into regex mode. that ^ was doubled to ^^ due to escaping done in the Include macro code. the data_unescape property of XPointer Entry looks like to be intended to reverse that, so we fixed one place in the code to use .data_unescape rather than .data. TODO: review code - there might be other places needing .data_unescape. Something like <<Include("^foob*")>> now includes all items named foob* (foobar, foobar1, foobar2 - in that order).
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 28 Aug 2011 15:06:44 +0200
parents 22350c783ec5
children bb40c019139c
files MoinMoin/converter/include.py
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/include.py	Sun Aug 28 00:26:05 2011 +0200
+++ b/MoinMoin/converter/include.py	Sun Aug 28 15:06:44 2011 +0200
@@ -1,5 +1,5 @@
 # Copyright: 2008 MoinMoin:BastianBlank
-# Copyright: 2010 MoinMoin:ThomasWaldmann
+# Copyright: 2010-2011 MoinMoin:ThomasWaldmann
 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
 
 """
@@ -17,8 +17,12 @@
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
+from flask import current_app as app
 from flask import g as flaskg
 
+from whoosh.query import Term, And, Wildcard
+
+from MoinMoin.config import NAME
 from MoinMoin import wikiutil
 from MoinMoin.items import Item
 from MoinMoin.util.mime import type_moin_document
@@ -154,7 +158,7 @@
 
                     if xp_include:
                         for entry in xp_include:
-                            name, data = entry.name, entry.data
+                            name, data = entry.name, entry.data_unescape
                             if name == 'pages':
                                 xp_include_pages = data
                             elif name == 'sort':
@@ -197,13 +201,16 @@
                     pages = ((page, link), )
 
                 elif xp_include_pages:
-                    # We have a regex of pages to include
-                    from MoinMoin.storage.terms import NameFn
-                    inc_match = re.compile(xp_include_pages)
-                    root_item = Item(name=u'')
-                    pagelist = sorted([item.name for item in root_item.list_items(NameFn(inc_match))])
-                    if xp_include_sort == 'descending':
-                        pagelist.reverse()
+                    # XXX we currently interpret xp_include_pages as wildcard, but it should be regex
+                    # for compatibility with moin 1.9. whoosh has upcoming regex support, but it is not
+                    # released yet.
+                    if xp_include_pages.startswith('^'):
+                        # get rid of the leading ^ the Include macro needed to get into "regex mode"
+                        xp_include_pages = xp_include_pages[1:]
+                    query = And([Term("wikiname", app.cfg.interwikiname), Wildcard("name_exact", xp_include_pages)])
+                    reverse = xp_include_sort == 'descending'
+                    results = flaskg.storage.search(query, all_revs=False, sortedby="name_exact", reverse=reverse, limit=None)
+                    pagelist = [result[NAME] for result in results]
                     if xp_include_skipitems is not None:
                         pagelist = pagelist[xp_include_skipitems:]
                     if xp_include_items is not None: