wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / search-list.pl
blob6b9f850222da58818df110e78e1e8e429cb5c77b
1 # Copyright (C) 2006, 2007, 2008 Alex Schroeder <alex@emacswiki.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 2 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, write to the
15 # Free Software Foundation, Inc.
16 # 59 Temple Place, Suite 330
17 # Boston, MA 02111-1307 USA
19 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/search-list.pl">search-list.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Search_List_Extension">Search List Extension</a></p>';
21 push(@MyRules, \&SearchListRule);
23 sub SearchListRule {
24 if ($bol && /\G(&lt;list (.*?)&gt;)/cgis) {
25 # <list regexp>
26 Clean(CloseHtmlEnvironments());
27 Dirty($1);
28 my ($oldpos, $old_) = (pos, $_);
29 my $original = $OpenPageName;
30 my $term = $2;
31 if ($term eq "") {
32 $term = GetId();
34 local ($OpenPageName, %Page);
35 my %hash = ();
36 foreach my $id (SearchTitleAndBody($term)) {
37 $hash{$id} = 1 unless $id eq $original; # skip the page with the query
39 my @found = keys %hash;
40 if (defined &PageSort) {
41 @found = sort PageSort @found;
42 } else {
43 @found = sort(@found);
45 @found = map { $q->li(GetPageLink($_)) } @found;
46 print $q->start_div({-class=>'search list'}),
47 $q->ul(@found), $q->end_div;
48 Clean(AddHtmlEnvironment('p')); # if dirty block is looked at later, this will disappear
49 ($_, pos) = ($old_, $oldpos); # restore \G (assignment order matters!)
50 return '';
52 return undef;
56 # Add a new action list
58 $Action{list} = \&DoList;
60 sub DoList {
61 my $id = shift;
62 my $match = GetParam('match', '');
63 my $search = GetParam('search', '');
64 ReportError(T('The search parameter is missing.')) unless $match or $search;
65 print GetHeader('', Ts('Page list for %s', $match||$search), '');
66 local (%Page, $OpenPageName);
67 my %hash = ();
68 foreach my $id (grep(/$match/, $search
69 ? SearchTitleAndBody($search)
70 : AllPagesList())) {
71 $hash{$id} = 1;
73 my @found = keys %hash;
74 if (defined &PageSort) {
75 @found = sort PageSort @found;
76 } else {
77 @found = sort(@found);
79 @found = map { $q->li(GetPageLink($_)) } @found;
80 print $q->start_div({-class=>'search list'}),
81 $q->ul(@found), $q->end_div;
82 PrintFooter();