summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/lockedit.pm
blob: 1466e8337f5f16c74c6f809f7af7a62bfadfb56e (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. section => "auth",
  16. },
  17. locked_pages => {
  18. type => "pagespec",
  19. example => "!*/Discussion",
  20. description => "PageSpec controlling which pages are locked",
  21. link => "ikiwiki/PageSpec",
  22. safe => 1,
  23. rebuild => 0,
  24. },
  25. }
  26. sub canedit ($$) {
  27. my $page=shift;
  28. my $cgi=shift;
  29. my $session=shift;
  30. my $user=$session->param("name");
  31. return undef if defined $user && IkiWiki::is_admin($user);
  32. if (defined $config{locked_pages} && length $config{locked_pages} &&
  33. pagespec_match($page, $config{locked_pages},
  34. user => $session->param("name"),
  35. ip => $ENV{REMOTE_ADDR},
  36. )) {
  37. if ((! defined $user ||
  38. ! IkiWiki::userinfo_get($session->param("name"), "regdate")) &&
  39. exists $IkiWiki::hooks{auth}) {
  40. return sub { IkiWiki::needsignin($cgi, $session) };
  41. }
  42. else {
  43. return sprintf(gettext("%s is locked and cannot be edited"),
  44. htmllink("", "", $page, noimageinline => 1));
  45. }
  46. }
  47. return undef;
  48. }
  49. 1