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