Notify On Change


[Credits: Charles Nepote, Wikini ]

This simple patch, adapted from a suggestion made by Charles Nepote on Wikini, allows the administrator or an arbitrary list of registered users to monitor the wiki and be notified by email each time a page is edited. The patch uses the php built-in mail() function and should simply be inactive if the function is not enabled on the server.

Watch out!: consider that each edited page generates an email, so add this patch at your own risk.

How to install the notification function:

1. Add the following line to wakka.config.php:

     "notify_users" =>"DarTar, OtherUser",


2. Add the following code in handlers/page/edit.php just before //forward

    if (function_exists('mail') && $this->config["notify_users"]) {
    $Watchers = explode(",", $this->config["notify_users"]);
    if ($pages = $this->LoadRevisions($this->tag)) {
        $c = 0;
        $diff = $this->GetPageTag() . "/diff?";
        foreach ($pages as $page) {
            $c++;
            if ($c <= 3) {
                if ($c == 1) $diff .= "a=".$page["id"];
                if ($c == 2) $diff .= "&amp;b=".$page["id"];
            }
        }
    }
    foreach ($Watchers as $Watcher) {
        $MailAdr = $this->LoadSingle("select email from " .$this->config["table_prefix"]."users where name = '".mysql_escape_string($Watcher)."'");
        $subject = "[".$this->config["wakka_name"]."] The page \"" . $this->GetPageTag() . "\" has been edited by " .
$this->GetUserName();
        $message = "<p>Hi, " . $Watcher . "</p>";
        $message .= "<p>The following page has been edited : <a
href=\""
.$this->Href("",$tag,"")."\">".$this->Href("",$tag,"")."<a></p>";
        if ($pages) $message .= "<p>Modifications : <a href=\"".$this->Href("",$diff,"")."\">".$this->Href("",$diff,"")."<a></p>";
        $message .= "<p>-- The ".$this->config["wakka_name"]." robot</p>";
        $headers = "From: " . $this->config["wakka_name"] . "_notifier\n";
        $headers .= "X-Mailer: PHP/".phpversion()."\n"; //mailer
        $headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
        //comment this to send text format
        $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
        mail($MailAdr["email"], $subject, $message, $headers);
    }
}


-- DarTar


Since I like to test with a 'SandBox' page, but dont want emails sent for edits to this page, I changed the first line of the above code to the following:

if (function_exists('mail') && $this->config["notify_users"] && ($this->GetPageTag() != 'SandBox')) {

Other than this small change, I love this feature.

-- AdamCrews

CategoryUserContributions
Comments [Hide comments]
Comment by AndreiBosco
2005-03-26 20:43:46
Isnt possible to let a user choose what page he whats to watch? Something like wakko wikki does.
Comment by RogerD
2005-08-09 23:58:20
This would be a damn useful addition to the code.
Comment by YanB
2005-08-23 22:52:54
Suggestion: instead of hardcoding the list of users who get this kind of notification in wikka.config.php, maybe you could add a default wikiname which would correspond to a wikipage in which people can add their wikiname? This way, anybody can choose to use the 'notification' feature by simply adding their wikiname to the list on that page -- a bit like the Usergroup technique.
Comment by TmO
2006-06-15 14:50:29
I loaded this, but it will only notify the first user in the "notify_users" list.
Any ideas?

Thansk,
TmO
Comment by DarTar
2006-06-16 04:40:43
Are you using commas to separate the usernames?
Comment by DevNet
2006-07-17 23:34:20
Wouldn't it be nice to add this functionality in the shape of a module that one could plugin?
Comment by DarTar
2006-07-18 04:32:28
DevNet, this is a quick hack that I tested a long time ago. I think it's better to create a watchlist module as other wikis do. Feel free to open a ticket in the tracker (http://tracker.wikkawiki.org) if you are interested in requesting this functionality.
Comment by DevNet
2006-07-19 09:53:26
DarTar,
I've noticed an AdminTools page here (no access of course :)). What type's of info are displayed there? Do you all just use actions there? What I mean is...I'm looking to improve overall tracking of the wiki. Previously, this was done by a guy using RSS feeds and just watching it like a hawk (the changes and comments). Now, he's stepping away from his duties and of course, I'll have to pick up the torch. So, I'm looking for ways to more efficiently administer the wiki...I would have gone to IRC for this, but we block that port here at work :D
Comment by TmO
2006-09-13 17:03:41
I eliminated the space after the comma in the notify_users list and then it worked.
Comment by SeitiYamashiro
2007-07-25 17:30:58
Nice extension to wikka! Works great!
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki