+sub test_httpauth_pagespec ($) {
+ my $page=shift;
+
+ return defined $config{httpauth_pagespec} &&
+ length $config{httpauth_pagespec} &&
+ defined $config{cgiauthurl} &&
+ pagespec_match($page, $config{httpauth_pagespec});
+}
+
+sub canedit ($$$) {
+ my $page=shift;
+ my $cgi=shift;
+ my $session=shift;
+
+ if (! defined $cgi->remote_user() && test_httpauth_pagespec($page)) {
+ return sub {
+ IkiWiki::redirect($cgi,
+ $config{cgiauthurl}.'?'.$cgi->query_string());
+ exit;
+ };
+ }
+ else {
+ return undef;
+ }
+}
+
+sub pagetemplate (@_) {
+ my %params=@_;
+ my $template=$params{template};
+
+ if ($template->param("editurl") &&
+ test_httpauth_pagespec($params{page})) {
+ # go directly to cgiauthurl when editing a page matching
+ # the pagespec
+ $template->param(editurl => IkiWiki::cgiurl(
+ cgiurl => $config{cgiauthurl},
+ do => "edit", page => $params{page}));
+ }
+}
+