]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/lockedit.pm
8914ba49802b1f2d60fbe5142c0e24180981c387
[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 => "checkconfig", id => "lockedit", call => \&checkconfig);
11         hook(type => "canedit", id => "lockedit", call => \&canedit);
12 }
14 sub getsetup () {
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => 0,
19                 },
20                 locked_pages => {
21                         type => "pagespec",
22                         example => "!*/Discussion",
23                         description => "PageSpec controlling which pages are locked",
24                         link => "ikiwiki/PageSpec",
25                         safe => 1,
26                         rebuild => 0,
27                 },
28 }
30 sub checkconfig () {
31         if (! exists $IkiWiki::hooks{auth}) {
32                 error gettext("lockedit plugin is enabled, but no authentication plugins are enabled");
33         }
34 }
36 sub canedit ($$) {
37         my $page=shift;
38         my $cgi=shift;
39         my $session=shift;
41         my $user=$session->param("name");
42         return undef if defined $user && IkiWiki::is_admin($user);
44         if (defined $config{locked_pages} && length $config{locked_pages} &&
45             pagespec_match($page, $config{locked_pages},
46                     user => $session->param("name"),
47                     ip => $ENV{REMOTE_ADDR},
48             )) {
49                 if (! defined $user ||
50                     ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
51                         return sub { IkiWiki::needsignin($cgi, $session) };
52                 }
53                 else {
54                         return sprintf(gettext("%s is locked and cannot be edited"),
55                                 htmllink("", "", $page, noimageinline => 1));
56                         
57                 }
58         }
60         return undef;
61 }
63 1