summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/lockedit.pm
blob: 82ce1e7be75e2a7a6e0ae70e8a83c776e5068da0 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::lockedit;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. sub import { #{{{
  7. hook(type => "canedit", id => "lockedit", call => \&canedit);
  8. hook(type => "formbuilder_setup", id => "lockedit",
  9. call => \&formbuilder_setup);
  10. } # }}}
  11. sub canedit ($$) { #{{{
  12. my $page=shift;
  13. my $cgi=shift;
  14. my $session=shift;
  15. my $user=$session->param("name");
  16. return undef if defined $user && IkiWiki::is_admin($user);
  17. foreach my $admin (@{$config{adminuser}}) {
  18. if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"))) {
  19. IkiWiki::needsignin($cgi, $session) unless defined $user;
  20. return sprintf(gettext("%s is locked by %s and cannot be edited"),
  21. htmllink("", "", $page, noimageinline => 1),
  22. IkiWiki::userlink($admin));
  23. }
  24. }
  25. return undef;
  26. } #}}}
  27. sub formbuilder_setup (@) { #{{{
  28. my %params=@_;
  29. my $form=$params{form};
  30. my $session=$params{session};
  31. my $cgi=$params{cgi};
  32. my $user_name=$session->param("name");
  33. if ($form->title eq "preferences") {
  34. $form->field(name => "locked_pages", size => 50,
  35. fieldset => "admin",
  36. comment => "(".htmllink("", "", "PageSpec", noimageinline => 1).")");
  37. if (! IkiWiki::is_admin($user_name)) {
  38. $form->field(name => "locked_pages", type => "hidden");
  39. }
  40. if (! $form->submitted) {
  41. $form->field(name => "locked_pages", force => 1,
  42. value => IkiWiki::userinfo_get($user_name, "locked_pages"));
  43. }
  44. if ($form->submitted && $form->submitted eq 'Save Preferences') {
  45. if (defined $form->field("locked_pages")) {
  46. IkiWiki::userinfo_set($user_name, "locked_pages",
  47. $form->field("locked_pages")) ||
  48. error("failed to set locked_pages");
  49. }
  50. }
  51. }
  52. } #}}}
  53. 1