search-list.pl 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (C) 2006, 2007, 2008 Alex Schroeder <alex@emacswiki.org>
  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 as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  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.
  12. #
  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
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('search-list.pl', 'Search List Extension');
  21. our ($q, $bol, %Action, %Page, $OpenPageName, @MyRules);
  22. 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();
  33. }
  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
  38. }
  39. my @found = keys %hash;
  40. if (defined &PageSort) {
  41. @found = sort PageSort @found;
  42. } else {
  43. @found = sort(@found);
  44. }
  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 '';
  51. }
  52. return;
  53. }
  54. # Add a new action list
  55. $Action{list} = \&DoList;
  56. sub DoList {
  57. my $id = shift;
  58. my $match = GetParam('match', '');
  59. my $search = GetParam('search', '');
  60. ReportError(T('The search parameter is missing.')) unless $match or $search;
  61. print GetHeader('', Ts('Page list for %s', $match||$search), '');
  62. local (%Page, $OpenPageName);
  63. my %hash = ();
  64. foreach my $id (grep(/$match/, $search
  65. ? SearchTitleAndBody($search)
  66. : AllPagesList())) {
  67. $hash{$id} = 1;
  68. }
  69. my @found = keys %hash;
  70. if (defined &PageSort) {
  71. @found = sort PageSort @found;
  72. } else {
  73. @found = sort(@found);
  74. }
  75. @found = map { $q->li(GetPageLink($_)) } @found;
  76. print $q->start_div({-class=>'search list'}),
  77. $q->ul(@found), $q->end_div;
  78. PrintFooter();
  79. }