Extension:CategorySubscriptions

Purpose
CategorySubscriptions allows a user to subscribe to categories and receive daily email updates of the changes that occured within each category during the previous day.

The goal of this extension is to allow a user to easily watch changes that occur within a category. Categories can be added directly (one category at a time) or by viewing a wiki page and viewing all the categories that wiki page belongs too.

Pear
The following Pear packages are required for the php emailing script. If you do not have Pear installed you will have to install it in additon to these required packages.
 * Mail
 * Net_SMTP (if using smtp to send emails)
 * Net_socket (dependant of net_smtp)

If you are using a different emailing protocol other than SMTP you will have to configure the mailer script and Pear as needed.

SQL Table
A new table must be created in the mediawiki database. The table is very simple and has only 3 columns
 * id - unique identifier for each column (auto-increment)
 * user_id - the id of the user making the subscription
 * category - the name of the category to be subscribed too

The SQL statement to create the table (note: only tested on MySQL database):

MySQL
The mailer script is coded to use a MySQL database.

Installation

 * 1) Install required Pear packages and create new table in database
 * 2) Create directory "CategorySubscriptions" under the extensions folder of your wiki installation
 * 3) Copy all 3 php files (CategorySubscriptions.php, CategorySubscriptions.i18n.php, CategorySubscriptionsMailer.php) into the folder you just created
 * 4) Add the following code to your LocalSettings.php file:
 * 5) Configure the mailer script (database host, user name, password, etc...)
 * 6) Using your favorite automation method, set the CategorySubscriptionsMailer.php script to run every morning.

Usage
The extension works by placing a link in the Monobook skin toolbox "Subscribe to Categories", that when clicked takes the user to the CategorySubscriptions special page. From there the user can add and remove categories they want to subscribe too.

Some example usage scenarios

Clicking the "Subscribe to Categories" link while viewing an article:

Clicking the link will take the user to the special page, sending as a url parameter the article title from which they were viewing (/Special:CategorySubscriptions/Article_Title). The categories that the article belongs to will be displayed, each with a check box. Checking the box subscribes to the category as unchecking unsubscribes. If the user is already subscribed to a category the box will be pre-checked.

Clicking the "Subscribe to Categories" link while viewing a category page:

This scenario is when the user is viewing a page for a category and clicks the link in the toolbox. The category name will be sent to the special page as a url parameter (/Special:CategorySubscriptions/Category:Category_Name). The category page must have text in it for the extension to recognize it. The special page will recognize that the page accessed is a category and notify the user. The user will be able to subscribe to that specific category, as well as any of the parent categories that this category belongs to.

Clicking the "Category Subscription" link in the list of special pages

Accessing the special page directly (no url parameters) will bring up a list of all the categories the user is subscribed too. Keeping with the same convention, unchecking a box will remove the category from the user's subscription list.

Future Improvements

 * Code the mailer script to run inside mediawiki so that it can take advantage of the built in database accessors and emailer. Currently the mailer runs as a stand-alone script making direct calls to MYSQL and uses Pear to send mail.
 * When viewing a category page, display both parent and sub categories

CategorySubscriptionsMailer.php
";

if ($send_email == true){ //get user row from database using user id				$user_query = mysql_query("SELECT * from user WHERE user_id = $user_id"); //pull out user's email from query result //there should only be one row while ($user = mysql_fetch_assoc($user_query)) { $from = $user["user_email"]; $to = $user["user_email"]; }				//Subject for the email $subject = "Wiki Cateogry Subscriptions"; //Build the email headers $headers = array ('From' => $from, 'To' => $to,	'Subject' => $subject, 'Content-type' => 'text/html');

//Send the email $mail = $smtp->send($to, $headers, $email_body); //Debugging output //Uncomment if you want confirmation of email sent printed to console //if (PEAR::isError($mail)) { //	echo(" " . $mail->getMessage . " "); //} else { //	echo(" Message successfully sent! "); //}			}	}//user while loop

//free database results mysql_free_result($category_list); mysql_free_result($user_ids); mysql_free_result($new_pages); mysql_free_result($updated_pages); mysql_free_result($user_categories); mysql_free_result($user_query);

mysql_close($link);