passwordauth: Fix url in password recovery email to be absolute.
[ikiwiki.git] / IkiWiki / Plugin / notifyemail.pm
index 926761d94422add49c2b56e052edee84aad0c42c..9f5a255aeed8487153fee9b0cd63f3f72a0d3e8e 100644 (file)
@@ -6,7 +6,6 @@ use strict;
 use IkiWiki 3.00;
 
 sub import {
-       hook(type => "formbuilder_setup", id => "notifyemail", call => \&formbuilder_setup);
        hook(type => "formbuilder", id => "notifyemail", call => \&formbuilder);
        hook(type => "getsetup", id => "notifyemail",  call => \&getsetup);
        hook(type => "changes", id => "notifyemail", call => \&notify);
@@ -20,25 +19,23 @@ sub getsetup () {
                },
 }
 
-sub formbuilder_setup (@) {
+sub formbuilder (@) {
        my %params=@_;
-
        my $form=$params{form};
        return unless $form->title eq "preferences";
        my $session=$params{session};
+       my $username=$session->param("name");
        $form->field(name => "subscriptions", size => 50,
                fieldset => "preferences",
-               comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")",
-               value => getsubscriptions($session->param("name")));
-}
-
-sub formbuilder (@) {
-       my %params=@_;
-       my $form=$params{form};
-       return unless $form->title eq "preferences" &&
-               $form->submitted eq "Save Preferences" && $form->validate &&
-               defined $form->field("subscriptions");
-       setsubscriptions($form->field('name'), $form->field('subscriptions'));
+               comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
+       if (! $form->submitted) {
+               $form->field(name => "subscriptions", force => 1,
+                       value => getsubscriptions($username));
+       }
+       elsif ($form->submitted eq "Save Preferences" && $form->validate &&
+              defined $form->field("subscriptions")) {
+               setsubscriptions($username, $form->field('subscriptions'));
+       }
 }
 
 sub getsubscriptions ($) {
@@ -130,7 +127,7 @@ sub notify (@) {
                        $template->param(
                                wikiname => $config{wikiname},
                                url => $url,
-                               prefsurl => $config{cgiurl}."?do=prefs",
+                               prefsurl => IkiWiki::cgiurl_abs(do => 'prefs'),
                                showcontent => $showcontent,
                                content => $content,
                        );