]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/lockedit.pm
* Finally apply the index.html patch, with thanks to everyone who worked
[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;
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                         return sprintf(gettext("%s is locked by %s and cannot be edited"),
25                                 htmllink("", "", $page, noimageinline => 1),
26                                 IkiWiki::userlink($admin));
27                 }
28         }
30         return undef;
31 } #}}}
33 sub formbuilder_setup (@) { #{{{
34         my %params=@_;
35         
36         my $form=$params{form};
37         my $session=$params{session};
38         my $cgi=$params{cgi};
39         my $user_name=$session->param("name");
41         if ($form->title eq "preferences") {
42                 $form->field(name => "locked_pages", size => 50,
43                         comment => "(".htmllink("", "", "PageSpec", noimageinline => 1).")");
44                 if (! IkiWiki::is_admin($user_name)) {
45                         $form->field(name => "locked_pages", type => "hidden");
46                 }
47                 if (! $form->submitted) {
48                         $form->field(name => "locked_pages", force => 1,
49                                 value => IkiWiki::userinfo_get($user_name, "locked_pages"));
50                 }
51                 if ($form->submitted && $form->submitted eq 'Save Preferences') {
52                         if (defined $form->field("locked_pages")) {
53                                 IkiWiki::userinfo_set($user_name, "locked_pages",
54                                         $form->field("locked_pages")) ||
55                                                 error("failed to set locked_pages");
56                         }
57                 }
58         }
59 } #}}}
61 1