annotate MoinMoin/macro/AdvancedSearch.py @ 6103:500f68d3e2fd

remove our own usage of python_compatibility module
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 06 Sep 2016 01:00:25 +0200
parents 5b92be3da023
children
rev   line source
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
2 """
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
3 MoinMoin - AdvancedSearch Macro
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
4
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
5 <<AdvancedSearch>>
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
6 displays advanced search dialog.
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
7
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1792
diff changeset
8 @license: GNU GPL, see COPYING for details.
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
9 """
5862
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
10 import sys
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
11
3040
8608b258f8e6 bug fix of MoinMoinBugs/MoveAttachmentNotWorkingWithModPython (thanks to Boleslaw Kulbabinski) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
12 from MoinMoin import wikiutil
1367
4c29aeea8bf7 languages dropdown menu
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1364
diff changeset
13 from MoinMoin.i18n import languages
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
14 from MoinMoin.widget import html
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
15 from MoinMoin.util.web import makeSelection
1374
aa33bb2b40d6 mimetype-search is live, i18n fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1373
diff changeset
16 import mimetypes
aa33bb2b40d6 mimetype-search is live, i18n fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1373
diff changeset
17
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
18 Dependencies = ['pages']
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
19
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
20 def getMimetypes():
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
21 # The types will be listed here, instead of parsing mimetypes.types_map
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
22 types = [
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
23 'application',
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
24 'audio',
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
25 'image',
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
26 'message',
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
27 'text',
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
28 'video',
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
29 ]
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
30 return types
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
31
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
32
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
33 def getCategories(request):
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
34 # This will return all pages with "Category" in the title
3573
124d0ef138aa change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3123
diff changeset
35 cat_filter = request.cfg.cache.page_category_regexact.search
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
36 pages = request.rootpage.getPageList(filter=cat_filter)
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
37 pages.sort()
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
38 return pages
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
39
1370
25ad5f5c6e3d py2.4 fix, sorted
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1369
diff changeset
40
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
41 def form_get(request, name, default='', escaped=False):
1506
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
42 """ Fetches a form field
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2224
diff changeset
43
1506
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
44 @param request: current request
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
45 @param name: name of the field
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
46 @param default: value if not present (default: '')
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
47 @param escaped: if True, escape value so it can be used for html generation (default: False)
1506
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
48 """
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4252
diff changeset
49 value = request.values.get(name, default)
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
50 if escaped:
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
51 value = wikiutil.escape(value, quote=True)
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
52 return value
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
53
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
54
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
55 def advanced_ui(macro):
1506
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
56 """ Returns the code for the advanced search user interface
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
57
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
58 @param macro: current macro instance
21e85d9d355e small cleanups, advanced ui can preserve search terms from other ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1501
diff changeset
59 """
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
60 _ = macro._
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
61 f = macro.formatter
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
62 request = macro.request
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
63
1491
92c7972c8d54 grey out fields not currently supported by moinSearch if xapian disabled
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1488
diff changeset
64 disabledIfMoinSearch = not request.cfg.xapian_search and \
92c7972c8d54 grey out fields not currently supported by moinSearch if xapian disabled
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1488
diff changeset
65 ' disabled="disabled"' or ''
92c7972c8d54 grey out fields not currently supported by moinSearch if xapian disabled
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1488
diff changeset
66
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
67 search_boxes = ''.join([
1369
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
68 f.table_row(1),
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
69 f.table_cell(1, attrs={'rowspan': '5', 'class': 'searchfor'}),
1460
44a52e7ff380 s/pages/items/g and s/include/exclude/g underlay
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1449
diff changeset
70 f.text(_('Search for items')),
1369
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
71 f.table_cell(0),
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
72 ''.join([''.join([
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
73 f.table_row(1),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
74 f.table_cell(1),
1444
1a3c73509f15 info for last modification date in advanced ui
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1441
diff changeset
75 f.text(txt),
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
76 f.table_cell(0),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
77 f.table_cell(1),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
78 f.rawHTML(input_field),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
79 f.table_cell(0),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
80 f.table_row(0),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
81 ]) for txt, input_field in (
1374
aa33bb2b40d6 mimetype-search is live, i18n fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1373
diff changeset
82 (_('containing all the following terms'),
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
83 '<input type="text" name="and_terms" size="30" value="%s">'
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
84 % (form_get(request, 'and_terms', escaped=True) or form_get(request, 'value', escaped=True))),
1374
aa33bb2b40d6 mimetype-search is live, i18n fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1373
diff changeset
85 (_('containing one or more of the following terms'),
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
86 '<input type="text" name="or_terms" size="30" value="%s">'
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
87 % form_get(request, 'or_terms', escaped=True)),
1374
aa33bb2b40d6 mimetype-search is live, i18n fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1373
diff changeset
88 (_('not containing the following terms'),
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
89 '<input type="text" name="not_terms" size="30" value="%s">'
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
90 % form_get(request, 'not_terms', escaped=True)),
1373
90cb8fe71cdf get fullsearch action working with the advanced search dialogue
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1372
diff changeset
91 #('containing only one of the following terms',
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
92 # '<input type="text" name="xor_terms" size="30" value="%s">'
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
93 # % form_get(request, 'xor_terms', escaped=True)),
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
94 # TODO: dropdown-box?
5187
b766ab8f2009 AdvancedSearch: example didn't work, fixed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4424
diff changeset
95 (_('last modified since (e.g. 2 weeks before)'),
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
96 '<input type="text" name="mtime" size="30" value="%s">'
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
97 % form_get(request, 'mtime', escaped=True)),
1369
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
98 )])
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
99 ])
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
100
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
101 # category selection
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
102 categories = form_get(request, 'categories')
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
103 c_select = makeSelection('categories',
3123
5cb80bd604b4 refactored _() getText calls to match new api
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3113
diff changeset
104 [('', _('any category'))] +
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
105 [(cat, '%s' % cat) for cat in getCategories(request)],
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
106 categories, 3, True)
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
107
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
108 # language selection
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
109 searchedlang = form_get(request, 'language')
1367
4c29aeea8bf7 languages dropdown menu
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1364
diff changeset
110 langs = dict([(lang, lmeta['x-language-in-english'])
1435
17e40b5bf1df reworked language list sorting
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
111 for lang, lmeta in languages.items()])
1449
e219092e1a0d a few small fixes to get misc things working with xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1448
diff changeset
112 userlang = macro.request.lang
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
113 lang_select = makeSelection('language',
3123
5cb80bd604b4 refactored _() getText calls to match new api
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3113
diff changeset
114 [('', _('any language')),
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
115 (userlang, langs[userlang])] + sorted(langs.items(), key=lambda i: i[1]),
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
116 searchedlang, 3, True)
1367
4c29aeea8bf7 languages dropdown menu
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1364
diff changeset
117
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
118 # mimetype selection
5862
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
119 # mimetypes.types_map has non-ascii encoded bytestrings sometimes!
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
120 coding = sys.getdefaultencoding() # same call used by stdlib mimetypes.py on win32
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
121 if coding == 'ascii': # we might get 'ascii'
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
122 coding = 'utf-8' # but we upgrade to utf-8, which is sometimes used for /etc/mime.types
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
123 decode = lambda s: s.decode(coding, 'replace') # use 'replace' -> never crash
1488
2178a0153213 advanced search dialogue preserves state
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1460
diff changeset
124 mimetype = form_get(request, 'mimetype')
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
125 mt_select = makeSelection('mimetype',
3123
5cb80bd604b4 refactored _() getText calls to match new api
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3113
diff changeset
126 [('', _('any mimetype'))] +
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
127 [(type, 'all %s files' % type) for type in getMimetypes()] +
5862
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
128 [(decode(m[1]), '*%s - %s' % (decode(m[0]), decode(m[1])))
5b92be3da023 work around crash of AdvancedSearch macro rendering caused by non-ascii mimetypes.types_map entries
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5187
diff changeset
129 for m in sorted(mimetypes.types_map.items())],
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
130 mimetype, 3, True)
1369
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
131
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
132 # misc search options (checkboxes)
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
133 search_options = ''.join([
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
134 ''.join([
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
135 f.table_row(1),
1372
6dacf2061124 cosmetic change for language and file type selection
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1371
diff changeset
136 f.table_cell(1, attrs={'class': 'searchfor'}),
6dacf2061124 cosmetic change for language and file type selection
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1371
diff changeset
137 txt[0],
6dacf2061124 cosmetic change for language and file type selection
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1371
diff changeset
138 f.table_cell(0),
6dacf2061124 cosmetic change for language and file type selection
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1371
diff changeset
139 f.table_cell(1, colspan=2),
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
140 unicode(txt[1]),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
141 txt[2],
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
142 f.table_cell(0),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
143 f.table_row(0),
1369
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
144 ]) for txt in (
3113
3489709aa99f AdvancedSearch: make multipe categories/languages/mimetype selections possible, thanks to James Sun (crptone@gmail.com, ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
145 (_('Categories'), unicode(c_select), ''),
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
146 (_('Language'), unicode(lang_select), ''),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
147 (_('File Type'), unicode(mt_select), ''),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
148 ('', html.INPUT(type='checkbox', name='titlesearch',
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
149 value='1', checked=form_get(request, 'titlesearch', escaped=True),
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
150 id='titlesearch'),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
151 '<label for="titlesearch">%s</label>' % _('Search only in titles')),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
152 ('', html.INPUT(type='checkbox', name='case', value='1',
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
153 checked=form_get(request, 'case', escaped=True),
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
154 id='case'),
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
155 '<label for="case">%s</label>' % _('Case-sensitive search')),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
156 ('', html.INPUT(type='checkbox', name='excludeunderlay',
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
157 value='1', checked=form_get(request, 'excludeunderlay', escaped=True),
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
158 id='excludeunderlay'),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
159 '<label for="excludeunderlay">%s</label>' % _('Exclude underlay')),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
160 ('', html.INPUT(type='checkbox', name='nosystemitems',
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
161 value='1', checked=form_get(request, 'nosystemitems', escaped=True),
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
162 id='nosystempages'),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
163 '<label for="nosystempages">%s</label>' % _('No system items')),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
164 ('', html.INPUT(type='checkbox', name='historysearch',
3834
27ddf6dfa7bd XSS security fix for advanced search form: added escaping (thanks to Emanuele Gentili from Ubuntu for discovering the problem) (ported from 1.7)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3573
diff changeset
165 value='1', checked=form_get(request, 'historysearch', escaped=True),
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
166 disabled=(not request.cfg.xapian_search or
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
167 not request.cfg.xapian_index_history),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
168 id='historysearch'),
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
169 '<label for="historysearch">%s</label>' % _('Search in all page revisions'))
1376
649b60a4064a domain-secific search (for system pages)
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1374
diff changeset
170 )
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
171 ])
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
172
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
173 # the dialogue
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
174 return f.rawHTML('\n'.join([
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4168
diff changeset
175 u'<form method="get" action="%s">' % macro.request.href(macro.request.formatter.page.page_name),
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
176 u'<div>',
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
177 u'<input type="hidden" name="action" value="fullsearch">',
1369
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
178 u'<input type="hidden" name="advancedsearch" value="1">',
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
179 f.table(1, attrs={'tableclass': 'advancedsearch'}),
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
180 search_boxes,
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
181 search_options,
1369
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
182 f.table_row(1),
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
183 f.table_cell(1, attrs={'class': 'submit', 'colspan': '3'}),
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
184 u'<input type="submit" value="%s">' % _('Go get it!'),
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
185 f.table_cell(0),
0a291dcb0555 more work on the advanced ui.. css, mimetype and language stuff
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1367
diff changeset
186 f.table_row(0),
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
187 f.table(0),
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
188 u'</div>',
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
189 u'</form>',
1509
6cd9bcede8cf make use of MoinMoin.widget.html and MoinMoin.util.web, clickable labels for advaced ui checkboxes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1506
diff changeset
190 ]))
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
191
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
192
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
193 def execute(macro, needle):
1499
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
194 # for now, just show the advanced ui
ffa0d1f81059 final polishing round adding docstrings, comments and fixing small issues
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1494
diff changeset
195 return advanced_ui(macro)
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
196