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