partial-journal.pl 2.2 KB

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