Revision [16778]

This is an old revision of PageWatches made by Td5Mni on 2007-05-31 10:47:33.

 

Watchlist for Wikka Pages


 

This patch is based on the code published at wakkawiki by matt peperell and silBaer.

registered users can put any page on a watchlist and can optionally choose to get an email on changes.

first we need a separate database table that holds the watches:
CREATE TABLE `wikka_watches` (
  `user` varchar(80) NOT NULL default '',
  `tag` varchar(50) NOT NULL default '',
  `mail` enum('N','Y') NOT NULL default 'N',
  `time` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`user`, `tag`)
) TYPE=MyISAM;


additional functions to be used when saving pages (notifywatchers()) and in the page footer... or header, of course (watchlink())
wikka.php inside class Wakka {
%%(php)<?
WATCHES
function IsWatched($user, $tag) { return $this->LoadSingle("select * from ".$this->config["table_prefix"]."watches where user = '".mysql_real_escape_string($user)."' and tag = '".mysql_real_escape_string($tag)."'"); }
function WatchLink($delimiter = "::", $unwatch = "unwatch", $watch = "watch") {
if ($this->GetUser()) {
echo ($this->IsWatched($this->GetUserName(), $this->tag) ?
$delimiter." <a href='".$this->href("watch")."'>".$unwatch."</a>" :
$delimiter.":: <a href='".$this->href("watch")."'>".$watch."</a>");
}
}
function NotifyWatchers($tag) {
$w = $this->config["table_prefix"]."watches";
$u = $this->config["table_prefix"]."users";
$sql = "select $w.user, $u.email from $w, $u".
" where $w.user = $u.name and $w.mail = 'Y'".
" and $w.tag = '".mysql_real_escape_string($tag)."'";
$notify = $this->LoadAll($sql);
foreach ($notify as $watcher) $watchers[$notify["user"]] = $notify["email"];

needs group management
add chief editors, a group that always will be notified
if ($chiefeditors = $this->GetMembers($this->config["always_notify"]) {
foreach ($chiefeditors as $chiefeditor) {
if ($editor = $this->LoadSingle("select * from $u where user='".mysql_real_escape_string($chiefeditor)."'")) {
$watchers[$editor["user"]] = $editor["email"];
}
}
}

foreach ($watchers as $watcher => $email) {
if ($watcher != $user
There are 4 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki