find.pl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2007, 2009 Alex Schroeder <alex@gnu.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 3 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, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('find.pl', 'Find Extension');
  18. our ($q, $Now, %Action);
  19. $Action{find} = \&DoFind;
  20. sub DoFind {
  21. my $string = GetParam('query','');
  22. my $raw = GetParam('raw','');
  23. if ($string eq '') {
  24. return DoIndex();
  25. }
  26. if ($raw) {
  27. print GetHttpHeader('text/plain'), RcTextItem('title', Ts('Search for: %s', $string)),
  28. RcTextItem('date', TimeToText($Now)), RcTextItem('link', $q->url(-path_info=>1, -query=>1)), "\n"
  29. if GetParam('context',1);
  30. } else {
  31. print GetHeader('', QuoteHtml(Ts('Search for: %s', $string))),
  32. $q->start_div({-class=>'content search'});
  33. my @elements = (ScriptLink('action=rc;rcfilteronly=' . UrlEncode($string),
  34. T('View changes for these pages')));
  35. print $q->p({-class=>'links'}, @elements);
  36. }
  37. my $match = quotemeta($string);
  38. my @results = grep(/$match/i, AllPagesList());
  39. if (@results) {
  40. print $q->start_div({-class=>'title'}),
  41. $q->p({-class=>'intro'},
  42. T('Matching page names:'));
  43. foreach (@results) { PrintPage($_) }
  44. print $q->end_div();
  45. }
  46. if (GetParam('context',1)) {
  47. push(@results, SearchTitleAndBody($string, \&PrintSearchResult, SearchRegexp($string)));
  48. } else {
  49. push(@results, SearchTitleAndBody($string, \&PrintPage));
  50. }
  51. print SearchResultCount($#results + 1), $q->end_div() unless $raw;
  52. PrintFooter() unless $raw;
  53. }