2007-02-02 03:33:03 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::lockedit;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2007-02-02 03:33:03 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-01 21:45:57 +02:00
|
|
|
hook(type => "getsetup", id => "lockedit", call => \&getsetup);
|
2007-02-02 03:33:03 +01:00
|
|
|
hook(type => "canedit", id => "lockedit", call => \&canedit);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2007-02-02 03:33:03 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-01 21:45:57 +02:00
|
|
|
return
|
2008-08-03 22:40:12 +02:00
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 0,
|
|
|
|
},
|
2008-08-01 21:45:57 +02:00
|
|
|
locked_pages => {
|
2008-08-02 22:40:46 +02:00
|
|
|
type => "pagespec",
|
2008-08-01 21:45:57 +02:00
|
|
|
example => "!*/Discussion",
|
|
|
|
description => "PageSpec controlling which pages are locked",
|
2008-08-03 20:36:17 +02:00
|
|
|
link => "ikiwiki/PageSpec",
|
2008-08-01 21:45:57 +02:00
|
|
|
safe => 1,
|
|
|
|
rebuild => 0,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-01 21:45:57 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub canedit ($$) {
|
2007-02-02 03:33:03 +01:00
|
|
|
my $page=shift;
|
|
|
|
my $cgi=shift;
|
|
|
|
my $session=shift;
|
|
|
|
|
|
|
|
my $user=$session->param("name");
|
|
|
|
return undef if defined $user && IkiWiki::is_admin($user);
|
|
|
|
|
2008-08-01 21:45:57 +02:00
|
|
|
if (defined $config{locked_pages} && length $config{locked_pages} &&
|
2008-10-08 23:47:38 +02:00
|
|
|
pagespec_match($page, $config{locked_pages},
|
|
|
|
user => $session->param("name"),
|
|
|
|
ip => $ENV{REMOTE_ADDR},
|
|
|
|
)) {
|
2008-08-01 21:45:57 +02:00
|
|
|
if (! defined $user ||
|
|
|
|
! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
|
|
|
|
return sub { IkiWiki::needsignin($cgi, $session) };
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return sprintf(gettext("%s is locked and cannot be edited"),
|
|
|
|
htmllink("", "", $page, noimageinline => 1));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-02 03:33:03 +01:00
|
|
|
return undef;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2007-02-02 03:33:03 +01:00
|
|
|
|
|
|
|
1
|