Merge commit 'upstream/master' into prv/po
[ikiwiki.git] / IkiWiki / Plugin / anonok.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::anonok;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 sub import {
9         hook(type => "getsetup", id => "anonok", call => \&getsetup);
10         hook(type => "canedit", id => "anonok", call => \&canedit);
11 }
12
13 sub getsetup () {
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => 0,
18                 },
19                 anonok_pagespec => {
20                         type => "pagespec",
21                         example => "*/discussion",
22                         description => "PageSpec to limit which pages anonymous users can edit",
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 $ret;
35
36         if (exists $config{anonok_pagespec} && length $config{anonok_pagespec}) {
37                 if (pagespec_match($page, $config{anonok_pagespec},
38                                    location => $page)) {
39                         return "";
40                 }
41                 else {
42                         return undef;
43                 }
44         }
45         else {
46                 return "";
47         }
48 }
49
50 1