]> sipb.mit.edu Git - ikiwiki.git/commitdiff
polishing notifyemail
authorJoey Hess <joey@kitenet.net>
Wed, 28 Mar 2012 23:39:08 +0000 (19:39 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 28 Mar 2012 23:39:08 +0000 (19:39 -0400)
IkiWiki/Plugin/notifyemail.pm
doc/templates.mdwn
templates/notifyemail.tmpl

index 192e8d7a30d7ad837525f716edd03284c31cec58..79771af743b2f875a82bc17e9e05038c01c9fccf 100644 (file)
@@ -73,32 +73,32 @@ sub notify (@) {
        error $@ if $@;
        eval q{use IkiWiki::UserInfo};
        error $@ if $@;
        error $@ if $@;
        eval q{use IkiWiki::UserInfo};
        error $@ if $@;
+       eval q{use URI};
+       error($@) if $@;
 
        # Daemonize, in case the mail sending takes a while.
 
        # 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: $!");
+       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();
 
        # 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;
+       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 $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;
-               print "!!$user\n";
 
                foreach my $file (@files) {
                        my $page=pagename($file);
 
                foreach my $file (@files) {
                        my $page=pagename($file);
-                       print "file: $file ($page)\n";
                        next unless pagespec_match($page, $pagespec);
                        my $content="";
                        my $showcontent=defined pagetype($file);
                        next unless pagespec_match($page, $pagespec);
                        my $content="";
                        my $showcontent=defined pagetype($file);
@@ -112,24 +112,28 @@ sub notify (@) {
                        }
                        elsif (defined $pagestate{$page}{meta}{permalink}) {
                                # need to use permalink for an internal page
                        }
                        elsif (defined $pagestate{$page}{meta}{permalink}) {
                                # need to use permalink for an internal page
-                               $url=$pagestate{$page}{meta}{permalink};
+                               $url=URI->new_abs($pagestate{$page}{meta}{permalink}, $config{url});
                        }
                        else {
                        }
                        else {
-                               $url=$config{wikiurl}; # crummy fallback url
+                               $url=$config{url}; # crummy fallback url
+                       }
+                       my $pagedesc=$page;
+                       if (defined $pagestate{$page}{meta}{title} &&
+                           length $pagestate{$page}{meta}{title}) {
+                               $pagedesc=qq{"$pagestate{$page}{meta}{title}"};
+                       }
+                       my $subject=gettext("change notification:")." ".$pagedesc;
+                       if (pagetype($file) eq '_comment') {
+                               $subject=gettext("comment notification:")." ".$pagedesc;
                        }
                        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 => IkiWiki::cgiurl(do => "prefs"),
+                               prefsurl => $config{cgiurl}."?do=prefs",
                                showcontent => $showcontent,
                                content => $content,
                        );
                                showcontent => $showcontent,
                                content => $content,
                        );
-                       #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 an email.
-                       my $subject=sprintf(gettext("%s: change notification for %s"),
-                               $config{wikiname}, $page);
                        sendmail(
                                To => $email,
                                From => "$config{wikiname} <$config{adminemail}>",
                        sendmail(
                                To => $email,
                                From => "$config{wikiname} <$config{adminemail}>",
@@ -139,7 +143,7 @@ sub notify (@) {
                }
        }
 
                }
        }
 
-       #exit 0; # daemon child
+       exit 0; # daemon child
 }
 
 1
 }
 
 1
index ca3f1412a82ba9b853b83ba534752d3a6696208f..d0f891c21320243125f2b5b7d26fc278c6292dde 100644 (file)
@@ -82,7 +82,7 @@ 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.
   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
+* `notifyemail.tmpl` - Used by the notifymail plugin to generate mails about
   changed pages.
 * `editpage.tmpl`, `editconflict.tmpl`, `editcreationconflict.tmpl`,
   `editfailedsave.tmpl`, `editpagegone.tmpl`, `pocreatepage.tmpl`,
   changed pages.
 * `editpage.tmpl`, `editconflict.tmpl`, `editcreationconflict.tmpl`,
   `editfailedsave.tmpl`, `editpagegone.tmpl`, `pocreatepage.tmpl`,
index 88972c36c75aab8c24222b83a040581aee4bce91..0852ad12b25323d6e1bb5213112fc5b3d448e48e 100644 (file)
@@ -1,7 +1,6 @@
-A change has been made to <TMPL_VAR URL>
+A <TMPL_IF NAME=ISCOMMENT>comment has been posted at<TMPL_ELSE>change has been made to</TMPL_IF>  <TMPL_VAR URL>
 
 To stop these notifications, visit <TMPL_VAR PREFSURL>
 
 To stop these notifications, visit <TMPL_VAR PREFSURL>
-
 <TMPL_IF NAME=SHOWCONTENT>
 ----
 
 <TMPL_IF NAME=SHOWCONTENT>
 ----