From c487b847e2053b13c4eea0ccfeecf5a41c396412 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 7 Jan 2008 16:34:13 -0500 Subject: * Improved the canedit hook interface, allowing a callback function to be returned (and not run in some cases) rather than the plugins directly forcing a user to log in. * opendiscussion: allow editing of the toplevel discussion page, and, indirectly, allow creating new discussion pages. --- IkiWiki/CGI.pm | 21 ++++++++++++++------- IkiWiki/Plugin/lockedit.pm | 13 +++++++++---- IkiWiki/Plugin/signinedit.pm | 9 +++++++-- 3 files changed, 30 insertions(+), 13 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 197eabcf0..a6695b3a5 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -20,7 +20,7 @@ sub printheader ($) { #{{{ } } #}}} - + sub showform ($$$$) { #{{{ my $form=shift; my $buttons=shift; @@ -57,15 +57,22 @@ sub check_canedit ($$$;$) { #{{{ my $nonfatal=shift; my $canedit; + my $callback; run_hooks(canedit => sub { return if defined $canedit; my $ret=shift->($page, $q, $session); - if (defined $ret && $ret eq "") { - $canedit=1; - } - elsif (defined $ret) { - $canedit=0; - error($ret) unless $nonfatal; + if (defined $ret) { + if ($ret eq "") { + $canedit=1; + } + elsif (ref $ret eq 'CODE') { + $canedit=0; + $callback->() unless $nonfatal; + } + elsif (defined $ret) { + $canedit=0; + error($ret) unless $nonfatal; + } } }); return $canedit; diff --git a/IkiWiki/Plugin/lockedit.pm b/IkiWiki/Plugin/lockedit.pm index a829df1cf..5a4e2fc38 100644 --- a/IkiWiki/Plugin/lockedit.pm +++ b/IkiWiki/Plugin/lockedit.pm @@ -21,10 +21,15 @@ sub canedit ($$) { #{{{ foreach my $admin (@{$config{adminuser}}) { if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"))) { - IkiWiki::needsignin($cgi, $session) unless defined $user; - return sprintf(gettext("%s is locked by %s and cannot be edited"), - htmllink("", "", $page, noimageinline => 1), - IkiWiki::userlink($admin)); + if (! defined $user || + ! userinfo_get($session->param("name"), "regdate")) { + return sub { IkiWiki::needsignin($cgi, $session) }; + } + else { + return sprintf(gettext("%s is locked by %s and cannot be edited"), + htmllink("", "", $page, noimageinline => 1), + IkiWiki::userlink($admin)); + } } } diff --git a/IkiWiki/Plugin/signinedit.pm b/IkiWiki/Plugin/signinedit.pm index 08932e2f6..d5729f702 100644 --- a/IkiWiki/Plugin/signinedit.pm +++ b/IkiWiki/Plugin/signinedit.pm @@ -18,8 +18,13 @@ sub canedit ($$$) { #{{{ # Have the user sign in, if they are not already. This is why the # hook runs last, so that any hooks that don't need the user to # signin can override this. - IkiWiki::needsignin($cgi, $session); - return ""; + if (! defined $session->param("name") || + ! userinfo_get($session->param("name"), "regdate")) { + return sub { IkiWiki::needsignin($cgi, $session) }; + } + else { + return ""; + } } #}}} 1 -- cgit v1.2.3