backlinks.pl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2008 Weakish Jiang <weakish@gmail.com>
  2. #
  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.
  6. #
  7. # You can get a copy of GPL version 2 at
  8. # http://www.gnu.org/licenses/gpl-2.0.html
  9. #
  10. # For user doc, see:
  11. # http://www.oddmuse.org/cgi-bin/oddmuse/Backlinks_Extension
  12. use strict;
  13. use v5.10;
  14. AddModuleDescription('backlinks.pl', 'Backlinks Extension');
  15. our ($q, %Action, %Page, $OpenPageName);
  16. *OldGetSearchLink = \&GetSearchLink;
  17. *GetSearchLink = \&NewGetSearchLink;
  18. sub NewGetSearchLink {
  19. my ($text, $class, $name, $title) = @_;
  20. my $id = UrlEncode(QuoteRegexp($text));
  21. $name = UrlEncode($name);
  22. $text = NormalToFree($text);
  23. $id =~ s/_/\ /g; # Search for url-escaped spaces
  24. return ScriptLink("action=backlink;search=\\[\\[$id(\\|.*)*\\]\\]", $text, $class, $name, $title);
  25. }
  26. $Action{backlink} = \&DoBackLink;
  27. sub DoBackLink {
  28. my $id = shift;
  29. my $search = GetParam('search', '');
  30. my $taglabel = $search;
  31. $taglabel =~ s/\\\[\\\[//;
  32. $taglabel =~ s/\\\]\\\]//;
  33. ReportError(T('The search parameter is missing.')) unless $search;
  34. print GetHeader('', Ts('Pages link to %s', $taglabel), '');
  35. local (%Page, $OpenPageName);
  36. my %hash = ();
  37. foreach my $id (SearchTitleAndBody($search)) {
  38. $hash{$id} = 1;
  39. }
  40. my @found = keys %hash;
  41. if (defined &PageSort) {
  42. @found = sort PageSort @found;
  43. } else {
  44. @found = sort(@found);
  45. }
  46. @found = map { $q->li(GetPageLink($_)) } @found;
  47. print $q->start_div({-class=>'search list'}),
  48. $q->ul(@found), $q->end_div;
  49. PrintFooter();
  50. }