summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/recentchangesdiff.pm
blob: 3942f308b05a86b5d4e7f0524fd756534a492391 (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 => "pagetemplate", id => "recentchangesdiff",
  9. call => \&pagetemplate);
  10. } #}}}
  11. sub pagetemplate (@) { #{{{
  12. my %params=@_;
  13. my $template=$params{template};
  14. if ($config{rcs} && exists $params{rev} && length $params{rev} &&
  15. $template->query(name => "diff")) {
  16. my @lines=IkiWiki::rcs_diff($params{rev});
  17. if (@lines) {
  18. my $diff;
  19. if (@lines > $maxlines) {
  20. # only include so many lines of diff
  21. $diff=join("", @lines[0..($maxlines-1)])."\n".
  22. gettext("(Diff truncated)");
  23. }
  24. else {
  25. $diff=join("", @lines);
  26. }
  27. # escape links and preprocessor stuff
  28. $diff =~ s/(?<!\\)\[\[/\\\[\[/g;
  29. $template->param(diff => $diff);
  30. }
  31. }
  32. } #}}}
  33. 1