summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/moderatedcomments.pm
blob: afe1ceedf0940cf3ebe94e7de56b5faf0f1c720f (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_users => {
  18. type => 'boolean',
  19. example => 1,
  20. description => 'Moderate comments of logged-in users?',
  21. safe => 1,
  22. rebuild => 0,
  23. },
  24. }
  25. sub checkcontent (@) {
  26. my %params=@_;
  27. # only handle comments
  28. return undef unless pagespec_match($params{page}, "postcomment(*)",
  29. location => $params{page});
  30. # admins and maybe users can comment w/o moderation
  31. my $session=$params{session};
  32. my $user=$session->param("name") if $session;
  33. return undef if defined $user && (IkiWiki::is_admin($user) ||
  34. (exists $config{moderate_users} && ! $config{moderate_users}));
  35. return gettext("comment needs moderation");
  36. }
  37. 1