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 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));
34 sub formbuilder_setup (@) { #{{{
37 my $form=$params{form};
38 my $session=$params{session};
40 my $user_name=$session->param("name");
42 if ($form->title eq "preferences") {
43 $form->field(name => "locked_pages", size => 50,
45 comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
46 if (! IkiWiki::is_admin($user_name)) {
47 $form->field(name => "locked_pages", type => "hidden");
49 if (! $form->submitted) {
50 $form->field(name => "locked_pages", force => 1,
51 value => IkiWiki::userinfo_get($user_name, "locked_pages"));
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");