Wiki source for NotifyOnChange


Show raw source

=====Notify On Change=====

[**Credits**: Charles Nepote, [[http://www.wikini.net/ | Wikini]] ]

This simple patch, adapted from a [[http://www.wikini.net/wakka.php?wiki=NotificationParCourriel | suggestion]] made by Charles Nepote on [[http://www.wikini.net/ | 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##:

%%(php) "notify_users" =>"DarTar, OtherUser",
%%

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

%%(php)
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 .= "&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:

%%(php)
if (function_exists('mail') && $this->config["notify_users"] && ($this->GetPageTag() != 'SandBox')) {
%%
Other than this small change, I love this feature.

-- AdamCrews
----
CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki