Extension:Email Digest

Email watchlist changes
I modified MediaWiki on some installations I administer to email daily watchlist changes as a digest.

My HTTP server is Apache 2.0.50, operating system is Mandrakelinux 10.1, mailer is sendmail.

Please forgive any primitive aspects of this code - this is the first time I've ever used PHP. :-)

This documentation is for MediaWiki version 1.3 and may need some adjustments to work with later versions.

Modify /languages/Language.php
MediaWiki very cleanly handles additional fields in the Misc settings of preferences. Find the section: and add: What this does is give the emailing script some defaults - namely DON'T email the watchlist and use plain (non-HTML) format.

Version 1.3
Now find this section: and add the description for the Misc settings to the end (probably after . Don't forget to add the comma to the last entry.

Version 1.4.4

 * 1) Find   and add
 * 1) Find   and add

Version 1.15
Please take a look at Extension:MailDigest. It is based upon this code, yet supports the newer mediawiki database format and is installable as a regular Extension, without the need to replace original mw-files.

Copy and modify /includes/SpecialPage.php
First, find SpecialPage.php in the /includes folder. Copy it to SpecialPage2.php. Note that you can actually modify SpecialPage.php instead of making the copy... I just like to keep my pages relatively 'pristine', except for the changes to Languages (harder since it's referenced a lot).

Just add a single element to the end of the  array (you should be an expert at this by now...)

SpecialWatchlist2.php
Download:  SpecialWatchlist2.tgz 

Okay, this one is a bit too long to try to post in the body, so it's posted on a site of mine.

Below are explanations on how this works, but you should just download the file and look at it.

It's a brand new page anyway, so just put it into your /includes folder. I copied the SpecialWatchlist.php page and made the following modifications:

Security
I didn't want just anyone to be able to launch this page, so it will only work if the server itself runs it:

Daily watchlist
Since this is a daily digest, I added a line to force the query to only include pages modified in the last day (just below $id = $wgRequest etc...):

Looping query of users
Now for the meat of it. Just before the $sql to get the COUNT(*) of the pages, I add a SQL loop query to circle through all users, plus get the user from the DB to see if they've selected to email a watchlist.

Mail sender
Then add code to send the email after all the watchlist generation code, right below $wgLoadBalancer->force(0);

MailWatchlist.php
Download:  MailWatchlist.tgz 

This is a new page that goes in your wiki root folder - same place as index.php. It's actually a copy of index.php with a lot of stuff removed. This is the page you browse to in order to run the script that sends the emails, i.e. . As noted above, however, it only works when the server itself (localhost) is the one browsing to it.

Basically all I did was remove the big  and   stuff that figured out where to browse to and just made it default to the 'SpecialPage - but with a change that forced it to my SpecialPage2.php copy.

Just copy the file into your main wiki folder along with index.php.

Automatic mailing
I wanted the MailWatchlist.php to execute automatically on the Mandrakelinux box, so I used cron - the Linux/UNIX scheduling service.

It took me a bit of trial and error to get it to work - I was trying to browse to it using FireFox at first. I finally tried Lynx, the terminal-based linux/unix http browser, and that was the trick.

Open a terminal window and type:

That will open the vi text editor with your user's schedule. Press I to go into insert mode, then type:

or wherever your wiki is installed, like:

or by using wget you also may use:

If you have multiple wikis installed, just create a line for each one. The numbers mean at 50 minutes, hour 23 (11pm), every day, every month, every year (iirc), run that command.

Now save your crontab file by pressing ESC to exit Insert mode, then press : and wq and press enter. That will put you in command mode and execute the write and quit commands. You should get a message like "installing new crontab".

You can test your setup by saving crontab with a line like:

and then just wait a minute to see if it runs.

sendmail issues
Once sendmail is installed with its default configuration, you'll need to tell it that it's okay to let Apache use it for mailing stuff.

On my Mandrakelinux distribution, I edited /etc/mail/trusted-users and added:

(opened a terminal window, vi or gedit as su (super user/root) make the changes and save) = See also = Extension:MailDigest