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 if (! defined $user ||
25 ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
26 return sub { IkiWiki::needsignin($cgi, $session) };
29 return sprintf(gettext("%s is locked by %s and cannot be edited"),
30 htmllink("", "", $page, noimageinline => 1),
31 IkiWiki::userlink($admin));
39 sub formbuilder_setup (@) { #{{{
42 my $form=$params{form};
43 if ($form->title eq "preferences") {
44 my $session=$params{session};
46 my $user_name=$session->param("name");
48 $form->field(name => "locked_pages", size => 50,
50 comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
51 if (! IkiWiki::is_admin($user_name)) {
52 $form->field(name => "locked_pages", type => "hidden");
54 if (! $form->submitted) {
55 $form->field(name => "locked_pages", force => 1,
56 value => IkiWiki::userinfo_get($user_name, "locked_pages"));
58 if ($form->submitted && $form->submitted eq 'Save Preferences') {
59 if (defined $form->field("locked_pages")) {
60 IkiWiki::userinfo_set($user_name, "locked_pages",
61 $form->field("locked_pages")) ||
62 error("failed to set locked_pages");