]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/notifyemail.pm
Call srcfile() with nothrow, as clearly intended.
[git.ikiwiki.info.git] / IkiWiki / Plugin / notifyemail.pm
index 0c067270cf6e9c4c1bd70baffa96d1c42be0ccb6..079bb10d4fb7eda121916976ddd0945934a4557b 100644 (file)
@@ -6,7 +6,6 @@ use strict;
 use IkiWiki 3.00;
 
 sub import {
 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);
        hook(type => "formbuilder", id => "notifyemail", call => \&formbuilder);
        hook(type => "getsetup", id => "notifyemail",  call => \&getsetup);
        hook(type => "changes", id => "notifyemail", call => \&notify);
@@ -20,28 +19,23 @@ sub getsetup () {
                },
 }
 
                },
 }
 
-sub formbuilder_setup (@) {
+sub formbuilder (@) {
        my %params=@_;
        my %params=@_;
-
        my $form=$params{form};
        return unless $form->title eq "preferences";
        my $session=$params{session};
        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).")");
        if (! $form->submitted) {
                $form->field(name => "subscriptions", force => 1,
        $form->field(name => "subscriptions", size => 50,
                fieldset => "preferences",
                comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
        if (! $form->submitted) {
                $form->field(name => "subscriptions", force => 1,
-                       value => getsubscriptions($session->param("name")));
+                       value => getsubscriptions($username));
+       }
+       elsif ($form->submitted eq "Save Preferences" && $form->validate &&
+              defined $form->field("subscriptions")) {
+               setsubscriptions($username, scalar $form->field('subscriptions'));
        }
        }
-}
-
-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'));
 }
 
 sub getsubscriptions ($) {
 }
 
 sub getsubscriptions ($) {
@@ -68,9 +62,23 @@ sub subscribe ($$) {
                length $pagespec ? $pagespec." or ".$addpagespec : $addpagespec);
 }
 
                length $pagespec ? $pagespec." or ".$addpagespec : $addpagespec);
 }
 
+# Called by other plugins to subscribe an email to a pagespec.
+sub anonsubscribe ($$) {
+       my $email=shift;
+       my $addpagespec=shift;
+       if (IkiWiki::Plugin::passwordauth->can("anonuser")) {
+               my $user=IkiWiki::Plugin::passwordauth::anonuser($email);
+               if (! defined $user) {
+                       error(gettext("Cannot subscribe your email address without logging in."));
+               }
+               subscribe($user, $addpagespec);
+       }
+}
+
 sub notify (@) {
        my @files=@_;
        return unless @files;
 sub notify (@) {
        my @files=@_;
        return unless @files;
+       return if $config{rebuild};
 
        eval q{use Mail::Sendmail};
        error $@ if $@;
 
        eval q{use Mail::Sendmail};
        error $@ if $@;
@@ -129,11 +137,20 @@ sub notify (@) {
                        if (pagetype($file) eq '_comment') {
                                $subject=gettext("comment notification:")." ".$pagedesc;
                        }
                        if (pagetype($file) eq '_comment') {
                                $subject=gettext("comment notification:")." ".$pagedesc;
                        }
+                       my $prefsurl=IkiWiki::cgiurl_abs(do => 'prefs');
+                       if (IkiWiki::Plugin::passwordauth->can("anonusertoken")) {
+                               my $token=IkiWiki::Plugin::passwordauth::anonusertoken($userinfo->{$user});
+                               $prefsurl=IkiWiki::cgiurl_abs(
+                                       do => 'tokenauth',
+                                       name => $user,
+                                       token => $token,
+                               ) if defined $token;
+                       }
                        my $template=template("notifyemail.tmpl");
                        $template->param(
                                wikiname => $config{wikiname},
                                url => $url,
                        my $template=template("notifyemail.tmpl");
                        $template->param(
                                wikiname => $config{wikiname},
                                url => $url,
-                               prefsurl => $config{cgiurl}."?do=prefs",
+                               prefsurl => $prefsurl,
                                showcontent => $showcontent,
                                content => $content,
                        );
                                showcontent => $showcontent,
                                content => $content,
                        );