summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/recentchanges.pm
blob: bdd386c7bf3001ac4f0785d8c204e838c2bc6bad (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::recentchanges;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. sub import { #{{{
  7. hook(type => "checkconfig", id => "recentchanges",
  8. call => \&checkconfig);
  9. hook(type => "needsbuild", id => "recentchanges",
  10. call => \&needsbuild);
  11. hook(type => "preprocess", id => "recentchanges",
  12. call => \&preprocess);
  13. hook(type => "htmlize", id => "_change",
  14. call => \&htmlize);
  15. } #}}}
  16. sub checkconfig () { #{{{
  17. my @changes=IkiWiki::rcs_recentchanges(100);
  18. updatechanges("*", "recentchanges", \@changes);
  19. } #}}}
  20. sub needsbuild () { #{{{
  21. # TODO
  22. } #}}}
  23. sub preprocess (@) { #{{{
  24. my %params=@_;
  25. # TODO
  26. return "";
  27. } #}}}
  28. # Pages with extension _change have plain html markup, pass through.
  29. sub htmlize (@) { #{{{
  30. my %params=@_;
  31. return $params{content};
  32. } #}}}
  33. sub store ($$) { #{{{
  34. my $change=shift;
  35. my $subdir=shift;
  36. my $page="$subdir/change_".IkiWiki::titlepage($change->{rev});
  37. # Optimisation to avoid re-writing pages. Assumes commits never
  38. # change (or that any changes are not important).
  39. return if exists $pagesources{$page} && ! $config{rebuild};
  40. # Limit pages to first 10, and add links to the changed pages.
  41. my $is_excess = exists $change->{pages}[10];
  42. delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
  43. $change->{pages} = [
  44. map {
  45. if (length $config{url}) {
  46. $_->{link} = "<a href=\"$config{url}/".
  47. urlto($_->{page},"")."\">".
  48. IkiWiki::pagetitle($_->{page})."</a>";
  49. }
  50. else {
  51. $_->{link} = IkiWiki::pagetitle($_->{page});
  52. }
  53. $_;
  54. } @{$change->{pages}}
  55. ];
  56. push @{$change->{pages}}, { link => '...' } if $is_excess;
  57. # Take the first line of the commit message as a summary.
  58. #my $m=shift @{$change->{message}};
  59. #$change->{summary}=$m->{line};
  60. #delete $change->{message} unless @{$change->{message}};
  61. # See if the committer is an openid.
  62. my $oiduser=IkiWiki::openiduser($change->{user});
  63. if (defined $oiduser) {
  64. $change->{authorurl}=$change->{user};
  65. $change->{user}=$oiduser;
  66. }
  67. elsif (length $config{url}) {
  68. $change->{authorurl}="$config{url}/".
  69. (length $config{userdir} ? "$config{userdir}/" : "").
  70. $change->{user};
  71. }
  72. # Fill out a template with the change info.
  73. my $template=template("change.tmpl", blind_cache => 1);
  74. $template->param(
  75. %$change,
  76. commitdate => displaytime($change->{when}, "%x %x"),
  77. wikiname => $config{wikiname},
  78. );
  79. $template->param(baseurl => "$config{url}/") if length $config{url};
  80. IkiWiki::run_hooks(pagetemplate => sub {
  81. shift->(page => $page, destpage => $page, template => $template);
  82. });
  83. writefile($page."._change", $config{srcdir}, $template->output);
  84. utime $change->{when}, $change->{when}, "$config{srcdir}/$page._change";
  85. } #}}}
  86. sub updatechanges ($$) { #{{{
  87. my $pagespec=shift;
  88. my $subdir=shift;
  89. my @changes=@{shift()};
  90. foreach my $change (@changes) {
  91. store($change, $subdir);
  92. }
  93. # TODO: delete old
  94. } #}}}
  95. 1