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 if (! defined $user ||
42 ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
43 return sub { IkiWiki::needsignin($cgi, $session) };
46 return sprintf(gettext("%s is locked and cannot be edited"),
47 htmllink("", "", $page, noimageinline => 1));
52 # XXX deprecated, should be removed eventually
53 foreach my $admin (@{$config{adminuser}}) {
54 if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"))) {
55 if (! defined $user ||
56 ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
57 return sub { IkiWiki::needsignin($cgi, $session) };
60 return sprintf(gettext("%s is locked and cannot be edited"),
61 htmllink("", "", $page, noimageinline => 1));
69 sub formbuilder_setup (@) { #{{{
72 # XXX deprecated, should be removed eventually
73 my $form=$params{form};
74 if ($form->title eq "preferences") {
75 my $session=$params{session};
77 my $user_name=$session->param("name");
79 $form->field(name => "locked_pages", size => 50,
81 comment => "deprecated; please move to locked_pages in setup file"
83 if (! IkiWiki::is_admin($user_name)) {
84 $form->field(name => "locked_pages", type => "hidden");
86 if (! $form->submitted) {
87 my $value=IkiWiki::userinfo_get($user_name, "locked_pages");
89 $form->field(name => "locked_pages", force => 1, value => $value);
92 $form->field(name => "locked_pages", type => "hidden");
95 if ($form->submitted && $form->submitted eq 'Save Preferences') {
96 if (defined $form->field("locked_pages")) {
97 IkiWiki::userinfo_set($user_name, "locked_pages",
98 $form->field("locked_pages")) ||
99 error("failed to set locked_pages");
100 if (! length $form->field("locked_pages")) {
101 $form->field(name => "locked_pages", type => "hidden");