]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/lockedit.pm
* aggregate: Only save state if it was already loaded. This didn't used to
[git.ikiwiki.info.git] / IkiWiki / Plugin / lockedit.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::lockedit;
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
8 sub import { #{{{
9         hook(type => "canedit", id => "lockedit", call => \&canedit);
10         hook(type => "formbuilder_setup", id => "lockedit",
11              call => \&formbuilder_setup);
12 } # }}}
14 sub canedit ($$) { #{{{
15         my $page=shift;
16         my $cgi=shift;
17         my $session=shift;
19         my $user=$session->param("name");
20         return undef if defined $user && IkiWiki::is_admin($user);
22         foreach my $admin (@{$config{adminuser}}) {
23                 if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"))) {
24                         IkiWiki::needsignin($cgi, $session) unless defined $user;
25                         return sprintf(gettext("%s is locked by %s and cannot be edited"),
26                                 htmllink("", "", $page, noimageinline => 1),
27                                 IkiWiki::userlink($admin));
28                 }
29         }
31         return undef;
32 } #}}}
34 sub formbuilder_setup (@) { #{{{
35         my %params=@_;
36         
37         my $form=$params{form};
38         my $session=$params{session};
39         my $cgi=$params{cgi};
40         my $user_name=$session->param("name");
42         if ($form->title eq "preferences") {
43                 $form->field(name => "locked_pages", size => 50,
44                         fieldset => "admin",
45                         comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
46                 if (! IkiWiki::is_admin($user_name)) {
47                         $form->field(name => "locked_pages", type => "hidden");
48                 }
49                 if (! $form->submitted) {
50                         $form->field(name => "locked_pages", force => 1,
51                                 value => IkiWiki::userinfo_get($user_name, "locked_pages"));
52                 }
53                 if ($form->submitted && $form->submitted eq 'Save Preferences') {
54                         if (defined $form->field("locked_pages")) {
55                                 IkiWiki::userinfo_set($user_name, "locked_pages",
56                                         $form->field("locked_pages")) ||
57                                                 error("failed to set locked_pages");
58                         }
59                 }
60         }
61 } #}}}
63 1