function processViewership()
 {
     $thresholds = array(25, 100, 500, 1000, 5000);
     $thresh2 = 10000;
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select(array('email_notifications'), array('en_viewership_email', 'en_viewership', 'en_user', 'en_page'), array('en_watch' => 1), __METHOD__);
     while ($row = $dbr->fetchObject($res)) {
         $sendflag = 0;
         $viewership = 0;
         $milestone = 0;
         $title = Title::newFromID($row->en_page);
         $user = User::newFromID($row->en_user);
         if (isset($title)) {
             $viewership = $dbr->selectField('page', 'page_counter', array('page_id' => $title->getArticleID()), __METHOD__);
             $prev = $row->en_viewership;
             if ($viewership > $thresh2) {
                 $a = floor($prev / $thresh2);
                 $b = floor($viewership / $thresh2);
                 if ($b > $a) {
                     $milestone = $b * $thresh2;
                     $sendflag = 1;
                 }
             } else {
                 foreach ($thresholds as $level) {
                     if ($prev < $level && $level < $viewership) {
                         $milestone = $level;
                         $sendflag = 1;
                     }
                 }
             }
             if ($sendflag) {
                 echo "Processing: [TITLE] " . $title->getText() . "(" . $title->getArticleID() . ") [USER] " . $user->getName() . ", [VIEWS]" . $row->en_viewership . " - " . $viewership . " [MILESTONE] {$milestone} \n";
                 AuthorEmailNotification::notifyViewership($title, $user, $milestone, $viewership, $row->en_viewership_email);
             } else {
                 echo "Skipping: [TITLE] " . $title->getText() . "(" . $title->getArticleID() . ") [USER] " . $user->getName() . ", [VIEWS]" . $row->en_viewership . " - " . $viewership . " [MILESTONE] {$milestone} \n";
             }
         } else {
             echo "Article Removed: [PAGE] " . $row->en_page . " [USER] " . $row->en_user . "\n";
         }
     }
 }
    AuthorEmailNotification::notifyFeatured($t);
}
// PROCESS VIEWERSHIP EMAILS
$ts = wfTimestamp(TS_MW, time() - 86400);
$sql = "SELECT page_namespace, page_title, page_counter, en_viewership, en_user\n\t\tFROM email_notifications \n\t\tLEFT JOIN page ON en_page=page_id\n\t\tWHERE en_viewership_email IS NULL\n\t\t\tOR en_viewership_email < '{$ts}'";
$res = $dbr->query($sql, __FILE__);
$milestones = array(10000, 5000, 1000, 500, 100);
while ($row = $dbr->fetchObject($res)) {
    $send = false;
    if (!$row->page_title) {
        continue;
    }
    if ($row->page_counter >= 10000 && $row->page_counter - $row->en_viewership >= 10000) {
        $milestone = floor($row->page_counter / 10000) * 10000;
        $send = true;
    } else {
        foreach ($milestones as $m) {
            if ($row->page_counter >= $m && $row->en_viewership < $m) {
                $milestone = $m;
                $send = true;
                break;
            }
        }
    }
    if ($send) {
        $title = Title::makeTitle($row->page_namespace, $row->page_title);
        $user = User::newFromID($row->en_user);
        $user->load();
        AuthorEmailNotification::notifyViewership($title, $user, $milestone, $milestone, null);
    }
}