comparison MoinMoin/macro/FullSearch.py @ 1217:237ca54182a7

copied code for search box over to macro/FullSearch.py
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Wed, 02 Aug 2006 20:56:26 +0200
parents 0e352443948b
children 12ddd8661ad6
comparison
equal deleted inserted replaced
1216:4c3b141bda6b 1217:237ca54182a7
30 import re 30 import re
31 from MoinMoin import config, wikiutil, search 31 from MoinMoin import config, wikiutil, search
32 32
33 Dependencies = ["pages"] 33 Dependencies = ["pages"]
34 34
35
36 def search_box(type, macro):
37 """ Make a search box
38
39 Make both Title Search and Full Search boxes, according to type.
40
41 @param type: search box type: 'titlesearch' or 'fullsearch'
42 @rtype: unicode
43 @return: search box html fragment
44 """
45 _ = macro._
46 if macro.form.has_key('value'):
47 default = wikiutil.escape(macro.form["value"][0], quote=1)
48 else:
49 default = ''
50
51 # Title search settings
52 boxes = ''
53 button = _("Search Titles")
54
55 # Special code for fullsearch
56 if type == "fullsearch":
57 boxes = [
58 u'<br>',
59 u'<input type="checkbox" name="context" value="160" checked="checked">',
60 _('Display context of search results'),
61 u'<br>',
62 u'<input type="checkbox" name="case" value="1">',
63 _('Case-sensitive searching'),
64 ]
65 boxes = u'\n'.join(boxes)
66 button = _("Search Text")
67
68 # Format
69 type = (type == "titlesearch")
70 html = [
71 u'<form method="get" action="">',
72 u'<div>',
73 u'<input type="hidden" name="action" value="fullsearch">',
74 u'<input type="hidden" name="titlesearch" value="%i">' % type,
75 u'<input type="text" name="value" size="30" value="%s">' % default,
76 u'<input type="submit" value="%s">' % button,
77 boxes,
78 u'</div>',
79 u'</form>',
80 ]
81 html = u'\n'.join(html)
82 return macro.formatter.rawHTML(html)
83
84
35 def execute(macro, needle): 85 def execute(macro, needle):
36 request = macro.request 86 request = macro.request
37 _ = request.getText 87 _ = request.getText
38 88
39 # if no args given, invoke "classic" behavior 89 # if no args given, invoke "classic" behavior
40 if needle is None: 90 if needle is None:
41 return macro._m_search("fullsearch") 91 return search_box("fullsearch", macro)
42 92
43 # With empty arguments, simulate title click (backlinks to page) 93 # With empty arguments, simulate title click (backlinks to page)
44 elif needle == '': 94 elif needle == '':
45 needle = '"%s"' % macro.formatter.page.page_name 95 needle = '"%s"' % macro.formatter.page.page_name
46 96