2008-04-25 12:02:14 +00:00
|
|
|
# Copyright (C) 2006, 2007, 2008 Alex Schroeder <alex@emacswiki.org>
|
2006-06-04 21:58:54 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2016-08-16 14:59:13 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2006-06-04 21:58:54 +00:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-08-16 14:59:13 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-04-25 12:00:00 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('search-list.pl', 'Search List Extension');
|
2006-06-04 21:58:54 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, $bol, %Action, %Page, $OpenPageName, @MyRules);
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2006-06-04 21:58:54 +00:00
|
|
|
push(@MyRules, \&SearchListRule);
|
|
|
|
|
|
|
|
|
|
sub SearchListRule {
|
2008-04-25 12:00:00 +00:00
|
|
|
if ($bol && /\G(<list (.*?)>)/cgis) {
|
2006-06-05 00:17:01 +00:00
|
|
|
# <list regexp>
|
2006-06-04 21:58:54 +00:00
|
|
|
Clean(CloseHtmlEnvironments());
|
|
|
|
|
Dirty($1);
|
|
|
|
|
my ($oldpos, $old_) = (pos, $_);
|
|
|
|
|
my $original = $OpenPageName;
|
2007-11-13 20:24:50 +00:00
|
|
|
my $term = $2;
|
|
|
|
|
if ($term eq "") {
|
|
|
|
|
$term = GetId();
|
|
|
|
|
}
|
2006-06-04 21:58:54 +00:00
|
|
|
local ($OpenPageName, %Page);
|
2006-06-06 22:59:21 +00:00
|
|
|
my %hash = ();
|
2007-11-13 20:22:05 +00:00
|
|
|
foreach my $id (SearchTitleAndBody($term)) {
|
2006-06-04 21:58:54 +00:00
|
|
|
$hash{$id} = 1 unless $id eq $original; # skip the page with the query
|
|
|
|
|
}
|
2006-06-04 23:36:52 +00:00
|
|
|
my @found = keys %hash;
|
|
|
|
|
if (defined &PageSort) {
|
|
|
|
|
@found = sort PageSort @found;
|
|
|
|
|
} else {
|
|
|
|
|
@found = sort(@found);
|
|
|
|
|
}
|
2006-06-06 20:15:27 +00:00
|
|
|
@found = map { $q->li(GetPageLink($_)) } @found;
|
2006-06-04 21:58:54 +00:00
|
|
|
print $q->start_div({-class=>'search list'}),
|
|
|
|
|
$q->ul(@found), $q->end_div;
|
|
|
|
|
Clean(AddHtmlEnvironment('p')); # if dirty block is looked at later, this will disappear
|
|
|
|
|
($_, pos) = ($old_, $oldpos); # restore \G (assignment order matters!)
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2015-02-27 12:10:18 +02:00
|
|
|
return;
|
2006-06-04 21:58:54 +00:00
|
|
|
}
|
2008-04-25 12:02:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Add a new action list
|
|
|
|
|
|
|
|
|
|
$Action{list} = \&DoList;
|
|
|
|
|
|
|
|
|
|
sub DoList {
|
|
|
|
|
my $id = shift;
|
|
|
|
|
my $match = GetParam('match', '');
|
|
|
|
|
my $search = GetParam('search', '');
|
2008-04-25 12:55:50 +00:00
|
|
|
ReportError(T('The search parameter is missing.')) unless $match or $search;
|
2008-04-25 12:02:14 +00:00
|
|
|
print GetHeader('', Ts('Page list for %s', $match||$search), '');
|
|
|
|
|
local (%Page, $OpenPageName);
|
|
|
|
|
my %hash = ();
|
|
|
|
|
foreach my $id (grep(/$match/, $search
|
|
|
|
|
? SearchTitleAndBody($search)
|
|
|
|
|
: AllPagesList())) {
|
|
|
|
|
$hash{$id} = 1;
|
|
|
|
|
}
|
|
|
|
|
my @found = keys %hash;
|
|
|
|
|
if (defined &PageSort) {
|
|
|
|
|
@found = sort PageSort @found;
|
|
|
|
|
} else {
|
|
|
|
|
@found = sort(@found);
|
|
|
|
|
}
|
|
|
|
|
@found = map { $q->li(GetPageLink($_)) } @found;
|
|
|
|
|
print $q->start_div({-class=>'search list'}),
|
2015-03-27 03:01:01 +02:00
|
|
|
$q->ul(@found), $q->end_div;
|
2008-04-25 12:02:14 +00:00
|
|
|
PrintFooter();
|
|
|
|
|
}
|