wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / backlinks.pl
blobca58bc83de8379b8b10008610e66685e2113c11d
1 # Copyright (C) 2008 Weakish Jiang <weakish@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
7 # You can get a copy of GPL version 2 at
8 # http://www.gnu.org/licenses/gpl-2.0.html
10 # For user doc, see:
11 # http://www.oddmuse.org/cgi-bin/oddmuse/Backlinks_Extension
13 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/backlinks.pl">backlinks.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Backlinks_Extension">Backlinks Extension</a></p>';
15 *OldGetSearchLink = *GetSearchLink;
16 *GetSearchLink = *NewGetSearchLink;
17 sub NewGetSearchLink {
18 my ($text, $class, $name, $title) = @_;
19 my $id = UrlEncode(QuoteRegexp($text));
20 $name = UrlEncode($name);
21 $text = NormalToFree($text);
22 $id =~ s/_/\ /g; # Search for url-escaped spaces
23 return ScriptLink("action=backlink;search=\\[\\[$id(\\|.*)*\\]\\]", $text, $class, $name, $title);
26 $Action{backlink} = \&DoBackLink;
28 sub DoBackLink {
29 my $id = shift;
30 my $search = GetParam('search', '');
31 my $taglabel = $search;
32 $taglabel =~ s/\\\[\\\[//;
33 $taglabel =~ s/\\\]\\\]//;
34 ReportError(T('The search parameter is missing.')) unless $search;
35 print GetHeader('', Ts('Pages link to %s', $taglabel), '');
36 local (%Page, $OpenPageName);
37 my %hash = ();
38 foreach my $id (SearchTitleAndBody($search)) {
39 $hash{$id} = 1;
41 my @found = keys %hash;
42 if (defined &PageSort) {
43 @found = sort PageSort @found;
44 } else {
45 @found = sort(@found);
47 @found = map { $q->li(GetPageLink($_)) } @found;
48 print $q->start_div({-class=>'search list'}),
49 $q->ul(@found), $q->end_div;
50 PrintFooter();