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 () { #{{{
19 example => "!*/Discussion",
20 description => "PageSpec controlling which pages are locked",
21 description_html => htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).
22 " controlling which pages are locked",
28 sub canedit ($$) { #{{{
33 my $user=$session->param("name");
34 return undef if defined $user && IkiWiki::is_admin($user);
36 if (defined $config{locked_pages} && length $config{locked_pages} &&
37 pagespec_match($page, $config{locked_pages})) {
38 if (! defined $user ||
39 ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
40 return sub { IkiWiki::needsignin($cgi, $session) };
43 return sprintf(gettext("%s is locked and cannot be edited"),
44 htmllink("", "", $page, noimageinline => 1));
49 # XXX deprecated, should be removed eventually
50 foreach my $admin (@{$config{adminuser}}) {
51 if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"))) {
52 if (! defined $user ||
53 ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
54 return sub { IkiWiki::needsignin($cgi, $session) };
57 return sprintf(gettext("%s is locked and cannot be edited"),
58 htmllink("", "", $page, noimageinline => 1));
66 sub formbuilder_setup (@) { #{{{
69 # XXX deprecated, should be removed eventually
70 my $form=$params{form};
71 if ($form->title eq "preferences") {
72 my $session=$params{session};
74 my $user_name=$session->param("name");
76 $form->field(name => "locked_pages", size => 50,
78 comment => "deprecated; please move to locked_pages in setup file"
80 if (! IkiWiki::is_admin($user_name)) {
81 $form->field(name => "locked_pages", type => "hidden");
83 if (! $form->submitted) {
84 my $value=IkiWiki::userinfo_get($user_name, "locked_pages");
86 $form->field(name => "locked_pages", force => 1, value => $value);
89 $form->field(name => "locked_pages", type => "hidden");
92 if ($form->submitted && $form->submitted eq 'Save Preferences') {
93 if (defined $form->field("locked_pages")) {
94 IkiWiki::userinfo_set($user_name, "locked_pages",
95 $form->field("locked_pages")) ||
96 error("failed to set locked_pages");
97 if (! length $form->field("locked_pages")) {
98 $form->field(name => "locked_pages", type => "hidden");