summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/moderatedcomments.pm
blob: 5957833fc2de44dc20484f616f8813ff0306400b (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::moderatedcomments;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. hook(type => "getsetup", id => "moderatedcomments", call => \&getsetup);
  8. hook(type => "checkcontent", id => "moderatedcomments", call => \&checkcontent);
  9. }
  10. sub getsetup () {
  11. return
  12. plugin => {
  13. safe => 1,
  14. rebuild => 0,
  15. section => "auth",
  16. },
  17. moderate_pagespec => {
  18. type => 'pagespec',
  19. example => '*',
  20. description => 'PageSpec matching users or comment locations to moderate',
  21. link => 'ikiwiki/PageSpec',
  22. safe => 1,
  23. rebuild => 0,
  24. },
  25. }
  26. sub checkcontent (@) {
  27. my %params=@_;
  28. # only handle comments
  29. return undef unless pagespec_match($params{page}, "postcomment(*)",
  30. location => $params{page});
  31. # backwards compatability
  32. if (exists $config{moderate_users} &&
  33. ! exists $config{moderate_pagespec}) {
  34. $config{moderate_pagespec} = $config{moderate_users}
  35. ? "!admin()"
  36. : "!user(*)";
  37. }
  38. # default is to moderate all except admins
  39. if (! exists $config{moderate_pagespec}) {
  40. $config{moderate_pagespec}="!admin()";
  41. }
  42. my $session=$params{session};
  43. my $user=$session->param("name");
  44. if (pagespec_match($params{page}, $config{moderate_pagespec},
  45. location => $params{page},
  46. (defined $user ? (user => $user) : ()),
  47. (defined $session->remote_addr() ? (ip => $session->remote_addr()) : ()),
  48. )) {
  49. return gettext("comment needs moderation");
  50. }
  51. else {
  52. return undef;
  53. }
  54. }
  55. 1