summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/recentchangesdiff.pm
blob: 71297572d7b74a5042e18fd93128a4dca773e170 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::recentchangesdiff;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.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}, $maxlines+1);
  27. if (@lines) {
  28. my $diff;
  29. if (@lines > $maxlines) {
  30. $diff=join("", @lines[0..($maxlines-1)])."\n".
  31. gettext("(Diff truncated)");
  32. }
  33. else {
  34. $diff=join("", @lines);
  35. }
  36. # escape html
  37. $diff = encode_entities($diff);
  38. # escape links and preprocessor stuff
  39. $diff = encode_entities($diff, '\[\]');
  40. $template->param(diff => $diff);
  41. }
  42. }
  43. }
  44. 1