summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/lockedit.pm
blob: f204e72c0052df303469c5970a4046c6ba96bd7f (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::lockedit;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  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. return sprintf(gettext("%s is locked by %s and cannot be edited"),
  20. htmllink("", "", $page, noimageinline => 1),
  21. IkiWiki::userlink($admin));
  22. }
  23. }
  24. return undef;
  25. } #}}}
  26. sub formbuilder_setup (@) { #{{{
  27. my %params=@_;
  28. my $form=$params{form};
  29. my $session=$params{session};
  30. my $cgi=$params{cgi};
  31. my $user_name=$session->param("name");
  32. if ($form->title eq "preferences") {
  33. $form->field(name => "locked_pages", size => 50,
  34. comment => "(".htmllink("", "", "PageSpec", noimageinline => 1).")");
  35. if (! IkiWiki::is_admin($user_name)) {
  36. $form->field(name => "locked_pages", type => "hidden");
  37. }
  38. if (! $form->submitted) {
  39. $form->field(name => "locked_pages", force => 1,
  40. value => IkiWiki::userinfo_get($user_name, "locked_pages"));
  41. }
  42. if ($form->submitted && $form->submitted eq 'Save Preferences') {
  43. if (defined $form->field("locked_pages")) {
  44. IkiWiki::userinfo_set($user_name, "locked_pages",
  45. $form->field("locked_pages")) ||
  46. error("failed to set locked_pages");
  47. }
  48. }
  49. }
  50. } #}}}
  51. 1