Merge branch 'master' into autoconfig
[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                 anonok_pagespec => {
16                         type => "string",
17                         default => "",
18                         example => "*/discussion",
19                         description => "PageSpec to limit which pages anonymouse users can edit",
20                         safe => 1,
21                         rebuild => 0,
22                 },
23 } #}}}
24
25 sub canedit ($$$) { #{{{
26         my $page=shift;
27         my $cgi=shift;
28         my $session=shift;
29
30         my $ret;
31
32         if (exists $config{anonok_pagespec} && length $config{anonok_pagespec}) {
33                 if (pagespec_match($page, $config{anonok_pagespec},
34                                    location => $page)) {
35                         return "";
36                 }
37                 else {
38                         return undef;
39                 }
40         }
41         else {
42                 return "";
43         }
44 } #}}}
45
46 1