All pastes #502891 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-05-22 17:25 UTC
rendered paste body
<?php
$total_count = 0;
$add_count = 0;
$delete_count = 0;
$newbie_count = 0;

// 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++;
    }
  }
  else {
    // Book page was spam.
    $delete_count++;
  }
}

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.";

function user_is_on_docs_team($uid) {
  // Role 4 = site maintaner, 5 = docs maintainer.
  return db_result(db_queryd("SELECT 1 FROM {users_roles} WHERE uid = %d AND (rid = %d OR rid = %d)",  $uid, 4, 5));
}