]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/lockedit.pm
fix bugs in `find_src_files()`.
[git.ikiwiki.info.git] / IkiWiki / Plugin / lockedit.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::lockedit;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9         hook(type => "getsetup", id => "lockedit", call => \&getsetup);
10         hook(type => "canedit", id => "lockedit", call => \&canedit);
11 }
13 sub getsetup () {
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => 0,
18                 },
19                 locked_pages => {
20                         type => "pagespec",
21                         example => "!*/Discussion",
22                         description => "PageSpec controlling which pages are locked",
23                         link => "ikiwiki/PageSpec",
24                         safe => 1,
25                         rebuild => 0,
26                 },
27 }
29 sub canedit ($$) {
30         my $page=shift;
31         my $cgi=shift;
32         my $session=shift;
34         my $user=$session->param("name");
35         return undef if defined $user && IkiWiki::is_admin($user);
37         if (defined $config{locked_pages} && length $config{locked_pages} &&
38             pagespec_match($page, $config{locked_pages},
39                     user => $session->param("name"),
40                     ip => $ENV{REMOTE_ADDR},
41             )) {
42                 if ((! defined $user ||
43                     ! IkiWiki::userinfo_get($session->param("name"), "regdate")) &&
44                     exists $IkiWiki::hooks{auth}) {
45                         return sub { IkiWiki::needsignin($cgi, $session) };
46                 }
47                 else {
48                         return sprintf(gettext("%s is locked and cannot be edited"),
49                                 htmllink("", "", $page, noimageinline => 1));
50                         
51                 }
52         }
54         return undef;
55 }
57 1