<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
package IkiWiki::Plugin::lockedit;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "lockedit", call =&gt; \&amp;getsetup);
	hook(type =&gt; "canedit", id =&gt; "lockedit", call =&gt; \&amp;canedit);
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 0,
			section =&gt; "auth",
		},
		locked_pages =&gt; {
			type =&gt; "pagespec",
			example =&gt; "!*/Discussion",
			description =&gt; "PageSpec controlling which pages are locked",
			link =&gt; "ikiwiki/PageSpec",
			safe =&gt; 1,
			rebuild =&gt; 0,
		},
}

sub canedit ($$) {
	my $page=shift;
	my $cgi=shift;
	my $session=shift;

	my $user=$session-&gt;param("name");
	return undef if defined $user &amp;&amp; IkiWiki::is_admin($user);

	if (defined $config{locked_pages} &amp;&amp; length $config{locked_pages} &amp;&amp;
	    pagespec_match($page, $config{locked_pages},
		    user =&gt; $session-&gt;param("name"),
		    ip =&gt; $ENV{REMOTE_ADDR},
	    )) {
		if ((! defined $user ||
		    ! IkiWiki::userinfo_get($session-&gt;param("name"), "regdate")) &amp;&amp;
		    exists $IkiWiki::hooks{auth}) {
			return sub { IkiWiki::needsignin($cgi, $session) };
		}
		else {
			return sprintf(gettext("%s is locked and cannot be edited"),
				htmllink("", "", $page, noimageinline =&gt; 1));
			
		}
	}

	return undef;
}

1
</pre></body></html>