I was thinking that it'd be cool if we could subscribe to articles and every 24hrs get an e-mail message listing the changes to those articles, recent changes style. I know it is kind of like a watch list, but watch lists have a problem, they only show the last change. this would show all the updates to certain articles whithing the last 24 hours. I know its kind of like recent changes too, and it should feed from the recent changes table, but I couldnt find too much documentation on the recent changes table. that table has another problem. currently we just store the last x recent changes in there. If wikipedia continues growing and that table grows so much that the ammount of changes per day is bigger than the table size then that would break the subscription system. thats why it feeds directly from curr and old.
Anyways, I hacked up some basic code. theres no UI in it, I hate programming UI's and the code has a lot of pseudo-code isms. It is by no means complete, its just an example to illustrate the concept and a basic implementation. It is by no means optimized or tested. oh yeah, thre is also hard code english in it. I wold have made a more complete example but i the current codebase drives me nuts. i just dont understand it too well. anyways, Brion and other developers, please look over it, you should be able to grasp the idea easily in case i didn't explain it clearly above. If you like the idea and you think it could be put into the current code base I'd be glad to further develop it. Of course I'd code it as an option that could be turned off easily. enough of this.. code follows
/////////////////////////////////////////////////////////////////////// /* #new table subscriptions subscriptions ->int unsigned user_id INDEX ->int unsigned article_id INDEX
##add a new column to user user + bool daily_subs default false */
$time = time(); $users = array(); $articles = array(); $user_subs = array();
$Q1 = SELECT user_id from users WHERE daily_subs = true
$Q2 = SELECT UNIQUE article_id FROM subscriptions WHERE user_id IN($Q1)
$Q3 = SELECT user_id,article_id FROM subscriptions WHERE user_id IN($Q1)
$Q4 = SELECT old_id as id, old_namespace as namespace, old_title as title, old_comment as comment, old_user_text as user_text, old_minor_edit as minor, old_timestamp as timestamp FROM old WHERE timestamp > ( $time-(86400) ) AND id IN($Q2) ORDER BY timestamp DESC
$Q5 = SELECT cur_id as id, cur_namespace as namespace, cur_title as title, cur_comment as comment, cur_user_text as user_text, cur_minor_edit as minor, cur_timestamp as timestamp FROM cur WHERE timestamp > ( $time-(86400) ) AND id IN($Q2) ORDER BY timestamp DESC
//curr first so that the newest rev is the first item the array foreach($Q5 as $change){ $articles[$change->id][] = $change; } //revisions ordered DESC the newer the revision, the smaller the array index foreach($Q4 as $change){ $articles[$change->id][] = $change; } //sort it all out foreach($Q3 as $sub){ if( isset($articles[$sub->article_id]) ){ $user_subs[$sub->user_id][$sub->article_id] =& $articles[$sub->article_id];
if( !(in_array($sub->user_id,$users)) ) $users[] = $sub->user_id; } }
$Q6 = SELECT user_id, user_email WHERE user_id IN(explode(',',$users))
//mail it out foreach($Q6 as $user){
$email = ""; $email = $user->user_email; unset($subs); $subs =& $users[$user->user_id];
foreach($subs as $mod_article){ //make an e-mail message listing the changes for this particular user $msg .= "\n"; $msg .= $mod_article[0]->title." was modified " .count($mod_article)." times today, details as follows \n"; foreach($mod_article as $rev){ $msg .= " * "; if($rev->minor) $msg .= "M " $msg .= date("H:i:s").' -- "'.$rev->comment.'" by '.$rev->user_text.'\n'; }
} //off we go mail($email, "Your Wikipedia subscriptions", $msg, "From: subscriptions@wikipedia.org\r\n");
}
///////////////////////////////////////////////////////////////////////////////////
Lightning