ikiwiki (3.20130711) unstable; urgency=low
[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 3.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                         section => "auth",
19                 },
20                 anonok_pagespec => {
21                         type => "pagespec",
22                         example => "*/discussion",
23                         description => "PageSpec to limit which pages anonymous users can edit",
24                         link => "ikiwiki/PageSpec",
25                         safe => 1,
26                         rebuild => 0,
27                 },
28 }
29
30 sub canedit ($$$) {
31         my $page=shift;
32         my $cgi=shift;
33         my $session=shift;
34
35         my $ret;
36
37         if (exists $config{anonok_pagespec} && length $config{anonok_pagespec}) {
38                 if (pagespec_match($page, $config{anonok_pagespec},
39                                    location => $page)) {
40                         return "";
41                 }
42                 else {
43                         return undef;
44                 }
45         }
46         else {
47                 return "";
48         }
49 }
50
51 1