summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/lockedit.pm
blob: 74ddbb1537929189206f675fdb49bfbf9247837c (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. exists $IkiWiki::hooks{auth}) {
  39. return sub { IkiWiki::needsignin($cgi, $session) };
  40. }
  41. else {
  42. return sprintf(gettext("%s is locked and cannot be edited"),
  43. htmllink("", "", $page, noimageinline => 1));
  44. }
  45. }
  46. return undef;
  47. }
  48. 1