2 package IkiWiki::Plugin::lockedit;
9 hook(type => "canedit", id => "lockedit", call => \&canedit);
10 hook(type => "formbuilder_setup", id => "lockedit",
11 call => \&formbuilder_setup);
14 sub canedit ($$) { #{{{
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, 1),
26 IkiWiki::userlink($admin));
33 sub formbuilder_setup (@) { #{{{
36 my $form=$params{form};
37 my $session=$params{session};
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", 1).")");
44 if (! IkiWiki::is_admin($user_name)) {
45 $form->field(name => "locked_pages", type => "hidden");
47 if (! $form->submitted) {
48 $form->field(name => "locked_pages", force => 1,
49 value => IkiWiki::userinfo_get($user_name, "locked_pages"));
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");