<?php
$total_count = 0;
$add_count = 0;
$delete_count = 0;
$newbie_count = 0;
$newbies = array();
// Retrieve a listing of all book pages added in the past week that are still in
// the node table:
$result = db_query("SELECT nid FROM {node} WHERE type = 'book' AND created >= %d", time() - 604800);
$books = array();
while ($book = db_fetch_object($result)) {
$books[$book->nid] = $book->nid;
}
// Retrieve listing of *all* added book pages for the past week.
$result = db_query("SELECT wid, uid, link FROM {watchdog} WHERE message LIKE 'book: add%' AND type='content'");
while ($row = db_fetch_object($result)) {
$total_count++;
preg_match('!node/(\d+)!', $row->link, $matches);
$nid = $matches[1];
if (array_search($nid, $books)) {
// Book was added and hasn't been deleted.
$add_count++;
if (!user_is_on_docs_team($row->uid)) {
// Book was created by a new user; not someone on docs team.
$newbie_count++;
$newbies[$row->uid] = $row->uid;
}
}
else {
// Book page was spam.
$delete_count++;
}
}
// Get list of newbies.
foreach ($newbies as $uid => $value) {
$name = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid));
$newbies[$uid] = l($name, "user/$uid");
}
echo "In the past week, a total of $total_count handbook pages were created. Of those, $delete_count were spam. Of the $add_count added, $newbie_count were created by people not on the documentation team: ". implode(', ', $newbies);
function user_is_on_docs_team($uid) {
// Role 4 = site maintaner, 5 = docs maintainer.
return db_result(db_query("SELECT 1 FROM {users_roles} WHERE uid = %d AND (rid = %d OR rid = %d)", $uid, 4, 5));
}