/**
  * Called from maintenance script only.  Send Digest emails for any founders with that preference enabled
  *
  * @param array $events Events is empty for this type
  */
 public function process(array $events)
 {
     global $wgTitle;
     wfProfileIn(__METHOD__);
     $founderEmailObj = FounderEmails::getInstance();
     $wgTitle = Title::newMainPage();
     // Get list of founders with digest mode turned on
     $cityList = $founderEmailObj->getFoundersWithPreference('founderemails-views-digest');
     $wikiService = new WikiService();
     // Gather daily page view stats for each wiki requesting views digest
     foreach ($cityList as $cityID) {
         $user_ids = $wikiService->getWikiAdminIds($cityID);
         $foundingWiki = WikiFactory::getWikiById($cityID);
         $page_url = GlobalTitle::newFromText('Createpage', NS_SPECIAL, $cityID)->getFullUrl(array('modal' => 'AddPage'));
         $emailParams = array('$WIKINAME' => $foundingWiki->city_title, '$WIKIURL' => $foundingWiki->city_url, '$PAGEURL' => $page_url, '$UNIQUEVIEWS' => $founderEmailObj->getPageViews($cityID));
         foreach ($user_ids as $user_id) {
             $user = User::newFromId($user_id);
             // skip if not enable
             if (!$this->enabled($user, $cityID)) {
                 continue;
             }
             self::addParamsUser($cityID, $user->getName(), $emailParams);
             $langCode = $user->getGlobalPreference('language');
             $links = array('$WIKINAME' => $emailParams['$WIKIURL']);
             $mailSubject = strtr(wfMsgExt('founderemails-email-views-digest-subject', array('content')), $emailParams);
             $mailBody = strtr(wfMsgExt('founderemails-email-views-digest-body', array('content', 'parsemag'), $emailParams['$UNIQUEVIEWS']), $emailParams);
             $mailBodyHTML = F::app()->renderView('FounderEmails', 'GeneralUpdate', array_merge($emailParams, array('language' => 'en', 'type' => 'views-digest')));
             $mailBodyHTML = strtr($mailBodyHTML, FounderEmails::addLink($emailParams, $links));
             $mailCategory = FounderEmailsEvent::CATEGORY_VIEWS_DIGEST . (!empty($langCode) && $langCode == 'en' ? 'EN' : 'INT');
             $founderEmailObj->notifyFounder($user, $this, $mailSubject, $mailBody, $mailBodyHTML, $cityID, $mailCategory);
         }
     }
     wfProfileOut(__METHOD__);
 }
Example #2
0
 /**
  * @return FounderEmails
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new FounderEmails();
     }
     return self::$instance;
 }
 public static function register($user)
 {
     wfProfileIn(__METHOD__);
     $eventData = array('userName' => $user->getName(), 'userPageUrl' => $user->getUserPage()->getFullUrl(), 'userTalkPageUrl' => $user->getTalkPage()->getFullUrl());
     FounderEmails::getInstance()->registerEvent(new FounderEmailsRegisterEvent($eventData));
     wfProfileOut(__METHOD__);
     return true;
 }
 public static function register($wikiParams, $debugMode = false)
 {
     global $wgFounderEmailsExtensionConfig, $wgCityId;
     wfProfileIn(__METHOD__);
     $founderEmailObj = FounderEmails::getInstance();
     $wikiFounder = $founderEmailObj->getWikiFounder();
     $mainpageTitle = Title::newFromText(wfMsgForContent('Mainpage'));
     // set FounderEmails notifications enabled by default for wiki founder
     //		$wikiFounder->setOption( 'founderemailsenabled', true );
     $wikiFounder->setOption("founderemails-joins-{$wgCityId}", true);
     $wikiFounder->setOption("founderemails-edits-{$wgCityId}", true);
     $wikiFounder->saveSettings();
     foreach ($wgFounderEmailsExtensionConfig['events']['daysPassed']['days'] as $daysToActivate) {
         switch ($daysToActivate) {
             case 0:
                 $dayName = 'DayZero';
                 $doProcess = true;
                 break;
             case 3:
                 $dayName = 'DayThree';
                 $doProcess = false;
                 break;
             case 10:
                 $dayName = 'DayTen';
                 $doProcess = false;
                 break;
             default:
                 $dayName = 'DayZero';
                 $doProcess = true;
         }
         $mainPage = wfMsgForContent('mainpage');
         $eventData = array('activateDays' => $daysToActivate, 'activateTime' => time() + 86400 * $daysToActivate, 'wikiName' => $wikiParams['title'], 'wikiUrl' => $wikiParams['url'], 'wikiMainpageUrl' => $mainpageTitle->getFullUrl(), 'addapageUrl' => Title::newFromText('Createpage', NS_SPECIAL)->getFullUrl(array('modal' => 'AddPage')), 'addaphotoUrl' => Title::newFromText('NewFiles', NS_SPECIAL)->getFullUrl(array('modal' => 'UploadImage')), 'customizethemeUrl' => Title::newFromText('ThemeDesigner', NS_SPECIAL)->getFullUrl(array('modal' => 'Login')), 'editmainpageUrl' => Title::newFromText($mainPage)->getFullUrl(array('action' => 'edit', 'modal' => 'Login')), 'exploreUrl' => 'http://www.wikia.com', 'dayName' => $dayName);
         if ($debugMode) {
             $eventData['activateTime'] = 0;
         }
         $founderEmailObj->registerEvent(new FounderEmailsDaysPassedEvent($eventData), $doProcess);
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Called from maintenance script only.  Send Digest emails for any founders with that preference enabled
  * @param array $events
  */
 public function process(array $events)
 {
     global $wgTitle;
     wfProfileIn(__METHOD__);
     $wgTitle = Title::newMainPage();
     $founderEmailObj = FounderEmails::getInstance();
     // Get list of founders with digest mode turned on (defined in FounderEmailsEvent
     $cityList = $founderEmailObj->getFoundersWithPreference('founderemails-complete-digest');
     $wikiService = F::build('WikiService');
     foreach ($cityList as $cityID) {
         $user_ids = $wikiService->getWikiAdminIds($cityID);
         $foundingWiki = WikiFactory::getWikiById($cityID);
         $page_url = GlobalTitle::newFromText('WikiActivity', NS_SPECIAL, $cityID)->getFullUrl();
         $emailParams = array('$WIKINAME' => $foundingWiki->city_title, '$WIKIURL' => $foundingWiki->city_url, '$PAGEURL' => $page_url, '$UNIQUEVIEWS' => $founderEmailObj->getPageViews($cityID), '$USERJOINS' => $founderEmailObj->getNewUsers($cityID), '$USEREDITS' => $founderEmailObj->getDailyEdits($cityID));
         foreach ($user_ids as $user_id) {
             $user = User::newFromId($user_id);
             // skip if not enable
             if (!$this->enabled($cityID, $user)) {
                 continue;
             }
             self::addParamsUser($cityID, $user->getName(), $emailParams);
             $langCode = $user->getOption('language');
             // Only send digest emails for English users until translation is done
             if ($langCode == 'en') {
                 $links = array('$WIKINAME' => $emailParams['$WIKIURL']);
                 $mailSubject = strtr(wfMsgExt('founderemails-email-complete-digest-subject', array('content')), $emailParams);
                 $mailBody = strtr(wfMsgExt('founderemails-email-complete-digest-body', array('content', 'parsemag'), $emailParams['$UNIQUEVIEWS'], $emailParams['$USEREDITS'], $emailParams['$USERJOINS']), $emailParams);
                 $mailBodyHTML = F::app()->renderView("FounderEmails", "GeneralUpdate", array_merge($emailParams, array('language' => 'en', 'type' => 'complete-digest')));
                 $mailBodyHTML = strtr($mailBodyHTML, FounderEmails::addLink($emailParams, $links));
                 $mailCategory = FounderEmailsEvent::CATEGORY_COMPLETE_DIGEST . (!empty($langCode) && $langCode == 'en' ? 'EN' : 'INT');
                 // Only send email if there is some kind of activity to report
                 if ($emailParams['$UNIQUEVIEWS'] > 0 || $emailParams['$USERJOINS'] > 0 || $emailParams['$USEREDITS'] > 0) {
                     $founderEmailObj->notifyFounder($user, $this, $mailSubject, $mailBody, $mailBodyHTML, $cityID, $mailCategory);
                 }
             }
         }
     }
     wfProfileOut(__METHOD__);
 }
Example #6
0
 * this script should be run once a day
 *
 * @package MediaWiki
 * @addtopackage maintenance
 *
 * @author Adrian 'ADi' Wieczorek <adi(at)wikia-inc.com>
 *
 */
ini_set("include_path", dirname(__FILE__) . "/../../../maintenance/");
require_once "commandLine.inc";
if (!function_exists('wfFounderEmailsInit')) {
    require_once dirname(__FILE__) . "/FounderEmails.php";
    wfFounderEmailsInit();
}
if (isset($options['help'])) {
    die("Usage: php maintenance.php [--event=(daysPassed/viewsDigest/completeDigest)] [--wikiId=12345] [--help] [--quiet]\n\t\t--event\t\t\tspecific email event i.e. daysPassed, viewsDigest, completeDigest\n\t\t--wikiId\t\tspecific wiki id\n\t\t--help\t\t\tyou are reading it right now\n\t\t--quiet\t\t\tdo not print anything to output\n\n");
}
$events = array('daysPassed', 'viewsDigest', 'completeDigest');
if (isset($options['event']) && in_array($options['event'], $events)) {
    $events = array($options['event']);
}
$wikiId = null;
if (isset($options['wikiId']) && is_numeric($options['wikiId'])) {
    $wikiId = $options['wikiId'];
}
foreach ($events as $event) {
    if (!isset($options['quiet'])) {
        echo "Sending Founder Emails ({$event}).\n";
    }
    FounderEmails::getInstance()->processEvents($event, false, $wikiId);
}
 /**
  * @param RecentChange|null $oRecentChange This is allowed to be null to stay compatible
  *                                         with FounderEmailsEvent::register()
  *
  * @return bool
  *
  * @throws Exception
  */
 public static function register($oRecentChange = null)
 {
     $currentUser = F::app()->wg->User;
     if (is_null($oRecentChange)) {
         throw new \Exception('Invalid $oRecentChange value.');
     }
     if (FounderEmails::getInstance()->getLastEventType() == 'register') {
         // special case: creating user page after user registration, ignore event
         return true;
     }
     $isRegisteredUser = false;
     $isRegisteredUserFirstEdit = false;
     if ($oRecentChange->getAttribute('rc_user')) {
         $editorId = $oRecentChange->getAttribute('rc_user');
         $editor = $currentUser->getId() == $editorId ? $currentUser : User::newFromID($editorId);
         $isRegisteredUser = true;
         // if first edit email was already sent this is an additional edit
         $wasNotificationSent = static::getFirstEmailSentFlag($editor->getName()) === '1';
         if (!$wasNotificationSent) {
             $userEditStatus = static::getUserEditsStatus($editor, true);
             /*
             					If there is at least one edit, flag that we should not send this email anymore;
             					either first email is sent out as a result of this request,
             					or there was more than 1 edit so we will never need to send it again
             */
             switch ($userEditStatus) {
                 case self::NO_EDITS:
                     return true;
                     break;
                 case self::FIRST_EDIT:
                     $isRegisteredUserFirstEdit = true;
                     static::setFirstEmailSentFlag($editor->getName());
                     break;
                 case self::MULTIPLE_EDITS:
                     static::setFirstEmailSentFlag($editor->getName());
             }
         }
     } else {
         // Anon user
         $editorName = $oRecentChange->getAttribute('rc_user_text');
         $editor = $currentUser->getName() == $editorName ? $currentUser : User::newFromName($editorName, false);
     }
     $config = FounderEmailsEvent::getConfig('edit');
     if (in_array('staff', $editor->getGroups()) || in_array($editor->getId(), $config['skipUsers'])) {
         // page edited by founder, staff member or excluded user, skipping..
         return true;
     }
     if ($editor->isAllowed('bot')) {
         // skip bots
         return true;
     }
     $eventData = static::getEventData($editor, $oRecentChange, $isRegisteredUser, $isRegisteredUserFirstEdit);
     FounderEmails::getInstance()->registerEvent(new FounderEmailsEditEvent($eventData));
     return true;
 }
Example #8
0
     case 'DayTen':
         $msg_key_subj = 'founderemails' . $wikiType . '-email-10-days-passed-subject';
         $msg_key_body = 'founderemails' . $wikiType . '-email-10-days-passed-body';
         $msg_key_body_html = 'founderemails' . $wikiType . '-email-10-days-passed-body-HTML';
         $html_template = 'DayTen';
         break;
 }
 $mailBody = $mailBodyHTML = '';
 // send email
 $subject = "Founder Email Test for {$params['type']} ({$params['language']}/{$content_type}): ";
 $subject .= strtr(wfMsgExt($msg_key_subj, array('content')), $emailParams);
 if ($content_type == 'html') {
     if ($params['language'] == 'en' && empty($wgEnableAnswers) || empty($msg_key_body_html)) {
         // FounderEmailv2.1
         $links = array('$WIKINAME' => $emailParams['$WIKIURL'], '$EDITORNAME' => $emailParams['$EDITORURL'], '$PAGETITLE' => $emailParams['$PAGEURL']);
         $emailParams_new = FounderEmails::addLink($emailParams, $links);
         $emailParams_new['$HDWIKINAME'] = str_replace('#2C85D5', '#fa5c1f', $emailParams_new['$WIKINAME']);
         // header color = #fa5c1f
         $mailBodyHTML = F::app()->renderView("FounderEmails", $html_template, array_merge($emailParams_new, $params));
         $mailBodyHTML = strtr($mailBodyHTML, $emailParams_new);
     } else {
         // old emails
         $mailBodyHTML = strtr(wfMsgExt($msg_key_body_html, array('content', 'parseinline')), $emailParams);
     }
 } else {
     if ($params['type'] == 'views-digest') {
         $mailBody = strtr(wfMsgExt($msg_key_body, array('content', 'parsemag'), $emailParams['$UNIQUEVIEWS']), $emailParams);
     } else {
         if ($params['type'] == 'complete-digest') {
             $mailBody = strtr(wfMsgExt($msg_key_body, array('content', 'parsemag'), $emailParams['$UNIQUEVIEWS'], $emailParams['$USEREDITS'], $emailParams['$USERJOINS']), $emailParams);
         } else {
 public static function register(User $user)
 {
     $eventData = ['newUserName' => $user->getName()];
     FounderEmails::getInstance()->registerEvent(new FounderEmailsRegisterEvent($eventData));
     return true;
 }
 public static function register($oRecentChange)
 {
     global $wgUser, $wgCityId;
     wfProfileIn(__METHOD__);
     if (FounderEmails::getInstance()->getLastEventType() == 'register') {
         // special case: creating userpage after user registration, ignore event
         wfProfileOut(__METHOD__);
         return true;
     }
     $isRegisteredUser = false;
     $isRegisteredUserFirstEdit = false;
     if ($oRecentChange->getAttribute('rc_user')) {
         $editor = $wgUser->getId() == $oRecentChange->getAttribute('rc_user') ? $wgUser : User::newFromID($oRecentChange->getAttribute('rc_user'));
         $isRegisteredUser = true;
         if (class_exists('Masthead')) {
             $userStats = Masthead::getUserStatsData($editor->getName(), true);
             if ($userStats['editCount'] == 1) {
                 $isRegisteredUserFirstEdit = true;
             }
         }
     } else {
         // Anon user
         $editor = $wgUser->getName() == $oRecentChange->getAttribute('rc_user_text') ? $wgUser : User::newFromName($oRecentChange->getAttribute('rc_user_text'), false);
     }
     $config = FounderEmailsEvent::getConfig('edit');
     if (in_array('staff', $editor->getGroups()) || in_array($editor->getId(), $config['skipUsers'])) {
         // page edited by founder, staff member or excluded user, skipping..
         wfProfileOut(__METHOD__);
         return true;
     }
     if ($editor->isAllowed('bot')) {
         // skip bots
         wfProfileOut(__METHOD__);
         return true;
     }
     $oTitle = Title::makeTitle($oRecentChange->getAttribute('rc_namespace'), $oRecentChange->getAttribute('rc_title'));
     $eventData = array('titleText' => $oTitle->getText(), 'titleUrl' => $oTitle->getFullUrl(), 'editorName' => $editor->getName(), 'editorPageUrl' => $editor->getUserPage()->getFullUrl(), 'editorTalkPageUrl' => $editor->getTalkPage()->getFullUrl(), 'registeredUser' => $isRegisteredUser, 'registeredUserFirstEdit' => $isRegisteredUserFirstEdit, 'myHomeUrl' => Title::newFromText('WikiActivity', NS_SPECIAL)->getFullUrl());
     FounderEmails::getInstance()->registerEvent(new FounderEmailsEditEvent($eventData));
     wfProfileOut(__METHOD__);
     return true;
 }