partial-journal.pl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2004 Brock Wilcox <awwaiid@thelackthereof.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('partial-journal.pl', 'Partial Page Journal');
  18. our ($q, %Page, @MyRules, $CommentsPrefix);
  19. # Set up some rule so that we can mess with '-- cut --' (change to <hr>)
  20. push(@MyRules, \&PartialCutRule);
  21. sub PartialCutRule {
  22. if (m/\G(?<=\n)\s*--\s*cut\s*--\s*(?=\n)/cg) {
  23. return CloseHtmlEnvironments() . '<hr class="cut" />' . AddHtmlEnvironment('p');
  24. }
  25. return;
  26. }
  27. *OldPartialPrintJournal = \&PrintJournal;
  28. *PrintJournal = \&NewPartialPrintJournal;
  29. sub NewPartialPrintAllPages {
  30. my $links = shift;
  31. my $comments = shift;
  32. my $num = shift;
  33. for my $id (@_) {
  34. OpenPage($id);
  35. print $q->hr . $q->h1($links ? GetPageLink($id) : $q->a({-name=>$id},$id));
  36. my $text = $Page{'text'};
  37. if ($text =~ /((.*\n)*.*)\n\s*--\s*cut\s*--\s*/) {
  38. $text = $1;
  39. }
  40. PrintWikiToHTML($text); # nocache, current, not locked
  41. if ($comments and UserCanEdit($CommentsPrefix . $id, 0) and $id !~ /^$CommentsPrefix/) {
  42. print $q->p({-class=>'comment'},
  43. GetPageLink($CommentsPrefix . $id, T('Comments on this page')));
  44. }
  45. }
  46. }
  47. sub NewPartialPrintJournal {
  48. # We redefine PrintAllPages temporarily
  49. *OldPartialPrintAllPages = \&PrintAllPages;
  50. *PrintAllPages = \&NewPartialPrintAllPages;
  51. # Then we call the PrintJournal
  52. my $out = OldPartialPrintJournal(@_);
  53. # Then we put PrintAllPages back!
  54. *PrintAllPages = \&OldPartialPrintAllPages;
  55. return $out;
  56. }