function notifyUserTalk($aid, $from_uid, $comment, $type = 'talk')
 {
     global $wgServer, $wgLang, $wgParser;
     $fname = "AuthorEmailNotification::notifyUserTalk";
     wfProfileIn($fname);
     $dateStr = $wgLang->timeanddate(wfTimestampNow());
     if ($type == 'talk') {
         $track_talk = '?utm_source=talk_page_message&utm_medium=email&utm_term=talk_page&utm_campaign=talk_page_message';
         $track_sender_talk = '?utm_source=talk_page_message&utm_medium=email&utm_term=talk_page_sender&utm_campaign=talk_page_message';
     } else {
         $track_talk = '?utm_source=thumbsup_message&utm_medium=email&utm_term=talk_page&utm_campaign=talk_page_message';
         $track_sender_talk = '?utm_source=thumbsup_message&utm_medium=email&utm_term=talk_page_sender&utm_campaign=talk_page_message';
     }
     if ($aid == 0) {
         return;
     }
     if (preg_match('/{{.*?}}/', $comment, $matches)) {
         return;
     }
     $t = Title::newFromID($aid);
     if ($type == 'talk') {
         $options = new ParserOptions();
         $output = $wgParser->parse($comment, $t, new ParserOptions());
         $comment = $output->getText();
         $comment = preg_replace('/href="\\//', 'href="' . $wgServer . '/', $comment);
         $comment = strip_tags($comment, '<br><a>');
     }
     $fromuser = User::newFromID($from_uid);
     if (isset($t)) {
         $touser = User::newFromName($t->getText());
     } else {
         // no article no object
         return;
     }
     if (!$touser) {
         return;
     }
     if ($t->getArticleID() > 0 && $t->getNamespace() == NS_USER_TALK && $touser->getEmail() != '' && $touser->getOption('usertalknotifications') == '0') {
         $talkpagelink = $wgServer . '/' . rawurlencode($t->getTalkPage()) . $track_talk;
         $talkpagesenderlink = $wgServer . '/' . rawurlencode($fromuser->getTalkPage()) . $track_sender_talk;
         $from_name = wfMsg('aen_from');
         $subject = wfMsg('aen_usertalk_subject', $t->getTalkPage(), $fromuser->getName());
         $body = wfMsg('aen_usertalk_body', $fromuser->getName(), $touser->getName(), $talkpagelink, $comment, $dateStr, $talkpagesenderlink);
         AuthorEmailNotification::notify($touser, $from_name, $subject, $body);
         wfDebug("AEN DEBUG: notifyUserTalk send. from:" . $fromuser->getName() . " to:" . $touser->getName() . " title:" . $t->getTalkPage() . "\nbody: " . $body . "\n");
     } else {
         wfDebug("AEN DEBUG: notifyUserTalk - called no article: " . $t->getArticleID() . "\n");
     }
     wfProfileOut($fname);
     return true;
 }
    foreach ($res as $object) {
        $views += intval($object->pv_30day);
        $articles++;
    }
    if ($views < 50) {
        //echo "No email sent to " . $user->getName() . ". Not enough views ({$views})\n";
        continue;
    }
    $from_name = "Krystle <*****@*****.**>";
    $subject = wfMsg("viewership_subject");
    $cta = AuthorEmailNotification::getCTA('monthly_views', 'email');
    if ($articles == 1) {
        $article = "article";
    } else {
        $article = "articles";
    }
    $contribsPage = SpecialPage::getTitleFor('Contributions', $user->getName());
    $contribsLink = $contribsPage->getFullURL();
    $body = wfMsg("viewership_body", $user->getName(), number_format($articles), number_format($views), $cta, $article, $contribsLink);
    wfDebug($email . " " . $subject . " " . $body . "\n");
    $emailCount++;
    AuthorEmailNotification::notify($user, $from_name, $subject, $body, "", true);
    $userNames .= $user->getName() . " ";
    if ($emailCount > 500) {
        break;
    }
}
echo "\n\nEmail sent to:\t{$userNames}\n\n";
$endTime = microtime(true);
$timeDiff = $endTime - $startTime;
echo $emailCount . " viewership emails were sent, Finished in {$timeDiff} sec.\n";
 function sendMilestoneEmails($datestamp)
 {
     wfLoadExtensionMessages('Milestones');
     $dbw = wfGetDB(DB_MASTER);
     $dbr = wfGetDB(DB_SLAVE);
     $users = $this->getMilestonesComplete($datestamp);
     $emailCount = 0;
     foreach ($users as $userInfo) {
         $user = User::newFromId($userInfo->{$this->userField});
         $email = $user->getEmail();
         if ($email == "") {
             continue;
         }
         $registration = $user->getRegistration();
         //need to check for false for the users who have no registration date
         //like Krystle and JackHerrick
         if ($registration == NULL || $registration <= $this->minRegistration) {
             echo "No email sent to " . $user->getName() . ". Not a new registration\n";
             wfDebug("No email sent to " . $user->getName() . ". Not a new registration\n");
             continue;
         }
         if ($user->getOption('disablemarketingemail') == '1') {
             wfDebug("No email sent to " . $user->getName() . ". Marketing email disabled.\n");
             continue;
         }
         $todayUnix = wfTimestamp(TS_UNIX, $datestamp + "000000");
         $minUnix = strtotime("-30 days", $todayUnix);
         $minDate = wfTimestamp(TS_MW, $minUnix);
         $views = 0;
         $articles = 0;
         $res = $dbr->select(array('revision', 'pageview'), array('pv_30day'), array('rev_page=pv_page', 'rev_user' => $user->getID(), "rev_timestamp > {$minDate}"), __METHOD__, array('GROUP BY' => 'rev_page'));
         foreach ($res as $object) {
             $views += intval($object->pv_30day);
             $articles++;
         }
         $from_name = wfMsg('milestone_from');
         $subject = wfMsg('milestone_subject');
         $message = wfMsg('milestone_message_' . $userInfo->ms_editcount);
         if ($views > 20) {
             $viewership = wfMsg('milestone_viewership', number_format($articles), number_format($views));
         } else {
             $viewership = "";
         }
         $cta = AuthorEmailNotification::getCTA('email_roll', 'email');
         $body = wfMsg('milestone_body', $user->getName(), $message, $viewership, $cta);
         wfDebug($user->getEmail() . " " . $subject . " " . $body . "\n");
         $emailCount++;
         AuthorEmailNotification::notify($user, $from_name, $subject, $body, "", true);
         $dbw->update($this->tableName, array($this->emailField => $datestamp), array($this->userField => $userInfo->{$this->userField}));
     }
     echo $emailCount . " milestone emails were sent\n";
 }