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) {
            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 " .
        $message = "<p>Hi, " . $Watcher . "</p>";
        $message .= "<p>The following page has been edited : <a
        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

There are 10 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki