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