2 package IkiWiki::Plugin::lockedit;
9 hook(type => "getsetup", id => "lockedit", call => \&getsetup);
10 hook(type => "canedit", id => "lockedit", call => \&canedit);
11 hook(type => "formbuilder_setup", id => "lockedit",
12 call => \&formbuilder_setup);
15 sub getsetup () { #{{{
23 example => "!*/Discussion",
24 description => "PageSpec controlling which pages are locked",
25 link => "ikiwiki/PageSpec",
31 sub canedit ($$) { #{{{
36 my $user=$session->param("name");
37 return undef if defined $user && IkiWiki::is_admin($user);
39 if (defined $config{locked_pages} && length $config{locked_pages} &&
40 pagespec_match($page, $config{locked_pages},
41 user => $session->param("name"),
42 ip => $ENV{REMOTE_ADDR},
44 if (! defined $user ||
45 ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
46 return sub { IkiWiki::needsignin($cgi, $session) };
49 return sprintf(gettext("%s is locked and cannot be edited"),
50 htmllink("", "", $page, noimageinline => 1));
55 # XXX deprecated, should be removed eventually
56 foreach my $admin (@{$config{adminuser}}) {
57 if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"),
58 user => $session->param("name"),
59 ip => $ENV{REMOTE_ADDR},
61 if (! defined $user ||
62 ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
63 return sub { IkiWiki::needsignin($cgi, $session) };
66 return sprintf(gettext("%s is locked and cannot be edited"),
67 htmllink("", "", $page, noimageinline => 1));
75 sub formbuilder_setup (@) { #{{{
78 # XXX deprecated, should be removed eventually
79 my $form=$params{form};
80 if ($form->title eq "preferences") {
81 my $session=$params{session};
83 my $user_name=$session->param("name");
85 $form->field(name => "locked_pages", size => 50,
87 comment => "deprecated; please move to locked_pages in setup file"
89 if (! IkiWiki::is_admin($user_name)) {
90 $form->field(name => "locked_pages", type => "hidden");
92 if (! $form->submitted) {
93 my $value=IkiWiki::userinfo_get($user_name, "locked_pages");
95 $form->field(name => "locked_pages", force => 1, value => $value);
98 $form->field(name => "locked_pages", type => "hidden");
101 if ($form->submitted && $form->submitted eq 'Save Preferences') {
102 if (defined $form->field("locked_pages")) {
103 IkiWiki::userinfo_set($user_name, "locked_pages",
104 $form->field("locked_pages")) ||
105 error("failed to set locked_pages");
106 if (! length $form->field("locked_pages")) {
107 $form->field(name => "locked_pages", type => "hidden");