summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/lockedit.pm
blob: 0fa329251f0b7eb5e6814e50f68d020eaf047eb8 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::lockedit;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. hook(type => "getsetup", id => "lockedit", call => \&getsetup);
  8. hook(type => "canedit", id => "lockedit", call => \&canedit);
  9. }
  10. sub getsetup () {
  11. return
  12. plugin => {
  13. safe => 1,
  14. rebuild => 0,
  15. },
  16. locked_pages => {
  17. type => "pagespec",
  18. example => "!*/Discussion",
  19. description => "PageSpec controlling which pages are locked",
  20. link => "ikiwiki/PageSpec",
  21. safe => 1,
  22. rebuild => 0,
  23. },
  24. }
  25. sub canedit ($$) {
  26. my $page=shift;
  27. my $cgi=shift;
  28. my $session=shift;
  29. my $user=$session->param("name");
  30. return undef if defined $user && IkiWiki::is_admin($user);
  31. if (defined $config{locked_pages} && length $config{locked_pages} &&
  32. pagespec_match($page, $config{locked_pages},
  33. user => $session->param("name"),
  34. ip => $ENV{REMOTE_ADDR},
  35. )) {
  36. if (! defined $user ||
  37. ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
  38. return sub { IkiWiki::needsignin($cgi, $session) };
  39. }
  40. else {
  41. return sprintf(gettext("%s is locked and cannot be edited"),
  42. htmllink("", "", $page, noimageinline => 1));
  43. }
  44. }
  45. return undef;
  46. }
  47. 1