summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/recentchangesdiff.pm
blob: 36acef72ebccf8978c3c4e8348074ef4bca0565c (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::recentchangesdiff;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. my $maxlines=200;
  7. sub import { #{{{
  8. hook(type => "getsetup", id => "recentchangesdiff",
  9. call => \&getsetup);
  10. hook(type => "pagetemplate", id => "recentchangesdiff",
  11. call => \&pagetemplate);
  12. } #}}}
  13. sub getsetup () { #{{{
  14. return
  15. plugin => {
  16. safe => 1,
  17. rebuild => 1,
  18. },
  19. } #}}}
  20. sub pagetemplate (@) { #{{{
  21. my %params=@_;
  22. my $template=$params{template};
  23. if ($config{rcs} && exists $params{rev} && length $params{rev} &&
  24. $template->query(name => "diff")) {
  25. my @lines=IkiWiki::rcs_diff($params{rev});
  26. if (@lines) {
  27. my $diff;
  28. if (@lines > $maxlines) {
  29. # only include so many lines of diff
  30. $diff=join("", @lines[0..($maxlines-1)])."\n".
  31. gettext("(Diff truncated)");
  32. }
  33. else {
  34. $diff=join("", @lines);
  35. }
  36. # escape links and preprocessor stuff
  37. $diff =~ s/(?<!\\)\[\[/\\\[\[/g;
  38. $template->param(diff => $diff);
  39. }
  40. }
  41. } #}}}
  42. 1