]> sipb.mit.edu Git - ikiwiki.git/commitdiff
changemail: New plugin, sends emails about changed pages.
authorJoey Hess <joey@kitenet.net>
Wed, 28 Mar 2012 20:40:10 +0000 (16:40 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 28 Mar 2012 20:40:10 +0000 (16:40 -0400)
IkiWiki/Plugin/changemail.pm [new file with mode: 0644]
debian/changelog
doc/plugins/changeemail.mdwn [new file with mode: 0644]
doc/templates.mdwn
templates/changeemail.tmpl [new file with mode: 0644]

diff --git a/IkiWiki/Plugin/changemail.pm b/IkiWiki/Plugin/changemail.pm
new file mode 100644 (file)
index 0000000..d0b7b8d
--- /dev/null
@@ -0,0 +1,91 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::changemail;
+
+use warnings;
+use strict;
+use IkiWiki 3.00;
+
+sub import {
+       hook(type => "getsetup", id => "changemail",  call => \&getsetup);
+       hook(type => "change", id => "changemail", call => \&notify);
+}
+
+sub getsetup () {
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => 0,
+                       section => "misc",
+               },
+}
+
+sub notify (@) {
+       my @files=@_;
+       return unless @files;
+
+       eval q{use Mail::Sendmail};
+       error $@ if $@;
+       eval q{use IkiWiki::UserInfo};
+
+       # Daemonize, in case the mail sending takes a while.
+       defined(my $pid = fork) or error("Can't fork: $!");
+       return if $pid; # parent
+       chdir '/';
+       open STDIN, '/dev/null';
+       open STDOUT, '>/dev/null';
+       POSIX::setsid() or error("Can't start a new session: $!");
+       open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
+
+       # Don't need to keep a lock on the wiki as a daemon.
+       IkiWiki::unlockwiki();
+
+       my $userinfo=IkiWiki::userinfo_retrieve();
+       exit 0 unless defined $userinfo;
+
+       foreach my $user (keys %$userinfo) {
+               my $pagespec=$userinfo->{$user}->{"subscriptions"};
+               next unless defined $pagespec && length $pagespec;
+               my $email=$userinfo->{$user}->{email};
+               next unless defined $email && length $email;
+
+               foreach my $file (@files) {
+                       my $page=pagename($file);
+                       next unless pagespec_match($page, $pagespec);
+                       my $ispage=defined pagetype($file);
+                       my $url;
+                       if (! IkiWiki::isinternal($page)) {
+                               $url=urlto($page, undef, 1);
+                       }
+                       elsif (defined $pagestate{$page}{meta}{permalink}) {
+                               # need to use permalink for an internal page
+                               $url=$pagestate{$page}{meta}{permalink};
+                       }
+                       else {
+                               $url=$config{wikiurl}; # crummy fallback url
+                       }
+                       my $template=template("changemail.tmpl");
+                       $template->param(
+                               wikiname => $config{wikiname},
+                               url => $url,
+                               prefsurl => IkiWiki::cgiurl(do => "prefs"),
+                               ispage => $ispage,
+                               content => $ispage ? readfile(srcfile($file)) : "",
+                       );
+                       #translators: The two variables are the name of the wiki,
+                       #translators: and a page that was changed.
+                       #translators: This is used as the subject of a commit email.
+                       my $subject=sprintf(gettext("%s: change notification for %s"),
+                               $config{wikiname}, $page);
+                       sendmail(
+                               To => $email,
+                               From => "$config{wikiname} <$config{adminemail}>",
+                               Subject => $subject,
+                               Message => $template->output,
+                       );
+               }
+       }
+
+       exit 0; # daemon child
+}
+
+1
index f51f77cd7ee23fb5d41e2f3f0b43621691ec01d1..90e619cd13f7b69c56084bf06ea024e825fa2bf6 100644 (file)
@@ -5,6 +5,7 @@ ikiwiki (3.20120204) UNRELEASED; urgency=low
     them.
   * meta: Export author information in html <meta> tag. Closes: #664779
     Thanks, Martin Michlmayr
+  * changemail: New plugin, sends emails about changed pages.
 
  -- Joey Hess <joeyh@debian.org>  Wed, 21 Mar 2012 14:33:14 -0400
 
diff --git a/doc/plugins/changeemail.mdwn b/doc/plugins/changeemail.mdwn
new file mode 100644 (file)
index 0000000..f37d0f5
--- /dev/null
@@ -0,0 +1,12 @@
+This plugin allows emailing users when pages are created or changed. 
+It needs the [[!cpan Mail::SendMail]] perl module, and sends mail
+using the local MTA.
+
+Each user can configure which pages they are interested in, using an
+[[ikiwiki/PageSpec]] on their Preferences page. Any change to a page
+matching the pagespec will send an email that includes the new content of
+the page, and a link to the page on the web.
+
+To make it easy to subscribe to comment threads when posting a comment,
+there is a check box that can be used to subscribe, without needing to
+manually edit the [[ikiwiki/PageSpec]].
index 43bf9ee51e6d1d10c11a98ccff8719dfa0a62376..ca3f1412a82ba9b853b83ba534752d3a6696208f 100644 (file)
@@ -82,10 +82,13 @@ Here is a full list of the template files used:
   make calendar archive pages.
 * `trails.tmpl` - Used by the trail plugin to generate links on each page
   that is a member of a trail.
+* `changemail.tmpl` - Used by the changemail plugin to generate mails about
+  changed pages.
 * `editpage.tmpl`, `editconflict.tmpl`, `editcreationconflict.tmpl`,
   `editfailedsave.tmpl`, `editpagegone.tmpl`, `pocreatepage.tmpl`,
   `editcomment.tmpl` `commentmoderation.tmpl`, `renamesummary.tmpl`,
   `passwordmail.tmpl`, `openid-selector.tmpl`, `revert.tmpl` - Parts of ikiwiki's user
   interface; do not normally need to be customised.
 
+
 [[!meta robots="noindex, follow"]]
diff --git a/templates/changeemail.tmpl b/templates/changeemail.tmpl
new file mode 100644 (file)
index 0000000..c73bf92
--- /dev/null
@@ -0,0 +1,9 @@
+A change has been made to <TMPL_VAR URL>
+
+To stop these notifications, visit <TMPL_VAR PREFSURL>
+
+<TMPL_IF ISPAGE>
+----
+
+<TMPL_VAR CONTENT>
+<TMPL_IF>