wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / find.pl
blob90ecb1b2247c75cd24626129e32d31cac531770e
1 # Copyright (C) 2007, 2009 Alex Schroeder <alex@gnu.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/find.pl">find.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Find_Extension">Find Extension</a></p>';
18 $Action{find} = \&DoFind;
20 sub DoFind {
21 my $string = GetParam('query','');
22 my $raw = GetParam('raw','');
23 if ($string eq '') {
24 return DoIndex();
26 if ($raw) {
27 print GetHttpHeader('text/plain'), RcTextItem('title', Ts('Search for: %s', $string)),
28 RcTextItem('date', TimeToText($Now)), RcTextItem('link', $q->url(-path_info=>1, -query=>1)), "\n"
29 if GetParam('context',1);
30 } else {
31 print GetHeader('', QuoteHtml(Ts('Search for: %s', $string))),
32 $q->start_div({-class=>'content search'});
33 my @elements = (ScriptLink('action=rc;rcfilteronly=' . UrlEncode($string),
34 T('View changes for these pages')));
35 print $q->p({-class=>'links'}, @elements);
37 my $match = quotemeta($string);
38 my @results = grep(/$match/i, AllPagesList());
39 if (@results) {
40 print $q->start_div({-class=>'title'}),
41 $q->p({-class=>'intro'},
42 T('Matching page names:'));
43 foreach (@results) { PrintPage($_) }
44 print $q->end_div();
46 if (GetParam('context',1)) {
47 push(@results, SearchTitleAndBody($string, \&PrintSearchResult, SearchRegexp($string)));
48 } else {
49 push(@results, SearchTitleAndBody($string, \&PrintPage));
51 print SearchResultCount($#results + 1), $q->end_div() unless $raw;
52 PrintFooter() unless $raw;