po: do not beautify urls on the recentchanges page
[ikiwiki] / IkiWiki / Plugin / lockedit.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::lockedit;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7
8 sub import {
9         hook(type => "getsetup", id => "lockedit", call => \&getsetup);
10         hook(type => "canedit", id => "lockedit", call => \&canedit);
11 }
12
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 }
28
29 sub canedit ($$) {
30         my $page=shift;
31         my $cgi=shift;
32         my $session=shift;
33
34         my $user=$session->param("name");
35         return undef if defined $user && IkiWiki::is_admin($user);
36
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                         return sub { IkiWiki::needsignin($cgi, $session) };
45                 }
46                 else {
47                         return sprintf(gettext("%s is locked and cannot be edited"),
48                                 htmllink("", "", $page, noimageinline => 1));
49                         
50                 }
51         }
52
53         return undef;
54 }
55
56 1