<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;

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

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);

	foreach my $admin (@{$config{adminuser}}) {
		if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"), "")) {
			return sprintf(gettext("%s is locked by %s and cannot be edited"),
				htmllink("", "", $page, noimageinline =&gt; 1),
				IkiWiki::userlink($admin));
		}
	}

	return undef;
} #}}}

sub formbuilder_setup (@) { #{{{
	my %params=@_;
	
	my $form=$params{form};
	my $session=$params{session};
	my $cgi=$params{cgi};
	my $user_name=$session-&gt;param("name");

	if ($form-&gt;title eq "preferences") {
		$form-&gt;field(name =&gt; "locked_pages", size =&gt; 50,
			comment =&gt; "(".htmllink("", "", "PageSpec", noimageinline =&gt; 1).")");
		if (! IkiWiki::is_admin($user_name)) {
			$form-&gt;field(name =&gt; "locked_pages", type =&gt; "hidden");
		}
		if (! $form-&gt;submitted) {
			$form-&gt;field(name =&gt; "locked_pages", force =&gt; 1,
				value =&gt; IkiWiki::userinfo_get($user_name, "locked_pages"));
		}
		if ($form-&gt;submitted &amp;&amp; $form-&gt;submitted eq 'Save Preferences') {
			if (defined $form-&gt;field("locked_pages")) {
				IkiWiki::userinfo_set($user_name, "locked_pages",
					$form-&gt;field("locked_pages")) ||
						error("failed to set locked_pages");
			}
		}
	}
} #}}}

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