示例#1
0
 /**
  * get last active sysop for this wiki, use local user database
  *
  * @access public
  *
  * @return User class instance
  */
 public function getLastSysop()
 {
     global $wgCityId, $wgMemc, $wgLanguageCode;
     wfProfileIn(__METHOD__);
     /**
      * maybe already loaded?
      */
     if (!$this->mSysop) {
         $sysop = trim(wfMsgForContent("welcome-user"));
         if (!in_array($sysop, array("@disabled", "-"))) {
             if (in_array($sysop, array("@latest", "@sysop"))) {
                 /**
                  * first: check memcache, maybe we have already stored id of sysop
                  */
                 $sysopId = $wgMemc->get(wfMemcKey("last-sysop-id"));
                 if ($sysopId) {
                     wfDebug(__METHOD__ . "-sysop: Have sysop id from memcached: {$sysopId}");
                     $this->mSysop = User::newFromId($sysopId);
                 } else {
                     /**
                      * second: check database, could be expensive for database
                      */
                     $dbr = wfGetDB(DB_SLAVE);
                     /**
                      * prior to September 20, 2012:
                      * get all users who are sysops or staff or helpers
                      * but not bots
                      *
                      * $groups = ($sysop !== "@sysop")
                      *	? array( "ug_group" => array( "staff", "sysop", "helper", "bot" ) )
                      *	: array( "ug_group" => array( "sysop", "bot" ) );
                      *
                      * from September 20, 2012 on:
                      * BugId:41817: get all users who are sysops but not bots or staff or helpers
                      * (fallback to a staff member by calling Wikia::staffForLang()).
                      */
                     $groups = array("ug_group" => array("sysop", "bot"));
                     $bots = array();
                     $admins = array();
                     $res = $dbr->select(array("user_groups"), array("ug_user, ug_group"), $dbr->makeList($groups, LIST_OR), __METHOD__);
                     while ($row = $dbr->fetchObject($res)) {
                         if ($row->ug_group == "bot") {
                             $bots[] = $row->ug_user;
                         } else {
                             $admins[] = $row->ug_user;
                         }
                     }
                     $dbr->freeResult($res);
                     /**
                      * remove bots from admins
                      */
                     $admins = array("rev_user" => array_unique(array_diff($admins, $bots)));
                     // fetch most recently active admin that edited within the last 60 days
                     $user = $dbr->selectField("revision", "rev_user", array($dbr->makeList($admins, LIST_OR), "rev_timestamp > " . $dbr->addQuotes($dbr->timestamp(time() - 5184000))), __METHOD__, array("ORDER BY" => "rev_timestamp DESC", "DISTINCT"));
                     wfDebug(__METHOD__ . "-query: " . $dbr->lastQuery());
                     /** if there are no active wiki admins, fall back to default staffers per language
                      * Note: We used to first go to any active staff member first and then go to this method if still empty
                      * However, that was removed in revision 50184 per FB:25277
                      */
                     if (empty($user)) {
                         $staffUser = Wikia::staffForLang($wgLanguageCode);
                         if ($staffUser instanceof User) {
                             $user = $staffUser->getId();
                         }
                     }
                     $this->mSysop = User::newFromId($user);
                     // BugId:41817 - if ( 1 == $user ) { notify Mix }
                     if (1 == $user) {
                         $oTo = $oFrom = new MailAddress('*****@*****.**');
                         UserMailer::send($oTo, $oFrom, 'BugId:41817 Occurrence Report', sprintf("File: %s\nLine: %s, Date: %s\nOutput: %s", __FILE__, __LINE__, date('Y-m-d H:i:s'), var_export($user, true)));
                     }
                     $wgMemc->set(wfMemcKey("last-sysop-id"), $user, 86400);
                 }
             } else {
                 wfDebug(__METHOD__ . "-sysop: Hardcoded sysop: {$sysop}");
                 $this->mSysop = User::newFromName($sysop);
             }
         }
         /**
          * fallback, if still user is uknown we use Wikia user
          */
         if ($this->mSysop instanceof User && $this->mSysop->getId()) {
             wfDebug(__METHOD__ . "-sysop: Found sysop: " . $this->mSysop->getName());
         } else {
             $this->mSysop = Wikia::staffForLang($wgLanguageCode);
             // BugId:41817 - if ( 1 == $this->mSysop->getId() ) { notify Mix }
             if (1 == $this->mSysop->getId()) {
                 $oTo = $oFrom = new MailAddress('*****@*****.**');
                 UserMailer::send($oTo, $oFrom, 'BugId:41817 Occurrence Report', sprintf("File: %s\nLine: %s, Date: %s\nOutput: %s", __FILE__, __LINE__, date('Y-m-d H:i:s'), var_export($this->mSysop->getId(), true)));
             }
             wfDebug(__METHOD__ . "-sysop: Fallback to hardcoded user: " . $this->mSysop->getName());
         }
     }
     wfProfileOut(__METHOD__);
     return $this->mSysop;
 }
示例#2
0
 /**
  * Determines the sender of the welcome message.
  *
  * @since MediaWiki 1.19.4
  * @internal
  */
 public function setSender()
 {
     $sSender = trim($this->getTextVersionOfMessage('welcome-user'));
     // Check for known values indicating that the most recently active admin has to be the sender.
     if (in_array($sSender, array('@latest', '@sysop'))) {
         /**
          * @global Object MemcachedPhpBagOStuff A pure-PHP memcached client instance.
          * @see https://doc.wikimedia.org/mediawiki-core/master/php/html/classMemcachedPhpBagOStuff.html
          */
         global $wgMemc;
         $iSender = (int) $wgMemc->get(wfMemcKey('last-sysop-id'));
         if (!$iSender) {
             // Fetch the list of users who are sysops and/or bots.
             $oDB = wfGetDB(DB_SLAVE);
             $oResult = $oDB->select(array('user_groups'), array('ug_user', 'ug_group'), $oDB->makeList(array('ug_group' => array('sysop', 'bot')), LIST_OR), __METHOD__);
             /** @type Array Placeholder, helps to separate bots from sysops. */
             $aUsers = array('bot' => array(), 'sysop' => array());
             // Classify the users as sysops or bots.
             while ($oRow = $oDB->fetchObject($oResult)) {
                 array_push($aUsers[$oRow->ug_group], $oRow->ug_user);
             }
             $oDB->freeResult($oResult);
             // Separate bots from sysops.
             /** @type Array Welcomer candidates. */
             $aAdmins = array('rev_user' => array_unique(array_diff($aUsers['sysop'], $aUsers['bot'])));
             // Fetch the id of the latest active sysop (within the last 60 days) or 0.
             $iSender = (int) $oDB->selectField('revision', 'rev_user', array($oDB->makeList($aAdmins, LIST_OR), 'rev_timestamp > ' . $oDB->addQuotes($oDB->timestamp(time() - 5184000))), __METHOD__, array('ORDER BY' => 'rev_timestamp DESC'));
             // Cache the fetched value if non-zero.
             if ($iSender) {
                 $wgMemc->set(wfMemcKey('last-sysop-id'), $iSender);
             }
         }
         $senderObject = User::newFromId($iSender);
         // If another value has been set, assume it is meant to be the name of the sender.
     } else {
         // Create a User object.
         /** @type Object User The sender for the welcome message. */
         $senderObject = User::newFromName($sSender);
     }
     // Terminate, if a valid user object has been created.
     if ($senderObject instanceof User && $senderObject->getId()) {
         $this->senderObject = $senderObject;
         return;
     }
     // If no recently active admin has been found, fall back to a relevant staff member.
     /**
      * @global String The language of the wiki.
      * @see http://www.mediawiki.org/wiki/Manual:$wgLanguageCode
      */
     global $wgLanguageCode;
     // Create a User object.
     $senderObject = Wikia::staffForLang($wgLanguageCode);
     // Terminate, if a valid user object has been created.
     if ($senderObject instanceof User && $senderObject->getId()) {
         $this->senderObject = $senderObject;
         return;
     }
     // This should not happen. Fall back to the default welcomer.
     $this->senderObject = User::newFromName(HAWelcomeTask::DEFAULT_WELCOMER);
     return;
 }
 /**
  * setWelcomeTalkPage
  *
  * @return boolean status
  */
 private function setWelcomeTalkPage()
 {
     global $wgUser, $wgEnableWallExt;
     $saveUser = $wgUser;
     $this->info('Setting welcome talk page on new wiki or Wall', ['sitename' => $this->wikiName, 'language' => $this->wikiLang]);
     /**
      * set apropriate staff member
      */
     $wgUser = \Wikia::staffForLang($this->wikiLang);
     $wgUser = $wgUser instanceof \User ? $wgUser : \User::newFromName(\CreateWiki::DEFAULT_STAFF);
     $talkParams = array($this->founder->getName(), $wgUser->getName(), $wgUser->getRealName(), $this->wikiName);
     $wallTitle = false;
     if (!empty($this->wikiLang)) {
         $wallTitle = wfMsgExt("autocreatewiki-welcometalk-wall-title", array('language' => $this->wikiLang));
     }
     if (!$wallTitle) {
         $wallTitle = wfMsg("autocreatewiki-welcometalk-wall-title");
     }
     if (!empty($wgEnableWallExt)) {
         $msg = "autocreatewiki-welcometalk-wall";
     } else {
         $msg = "autocreatewiki-welcometalk";
     }
     $talkBody = false;
     if (!empty($this->wikiLang)) {
         /**
          * custom lang translation
          */
         $talkBody = wfMsgExt($msg, array('language' => $this->wikiLang), $talkParams);
     }
     if (!$talkBody) {
         /**
          * wfMsgExt should always return message, but just in case...
          */
         $talkBody = wfMsg($msg, $talkParams);
     }
     if (!empty($wgEnableWallExt)) {
         $wallMessage = \WallMessage::buildNewMessageAndPost($talkBody, $this->founder->getName(), $wgUser, $wallTitle, false, array(), true, false);
         if ($wallMessage === false) {
             return false;
         }
         $this->info("wall message created", ['founder_name' => $this->founder->getName()]);
         return true;
     }
     $talkPage = $this->founder->getTalkPage();
     if ($talkPage) {
         /**
          * and now create talk article
          */
         $talkArticle = new \Article($talkPage, 0);
         if (!$talkArticle->exists()) {
             $talkArticle->doEdit($talkBody, wfMsg("autocreatewiki-welcometalk-log"), EDIT_SUPPRESS_RC | EDIT_MINOR | EDIT_FORCE_BOT);
         } else {
             $this->warning('talkpage already exists', ['url' => $talkPage->getFullURL()]);
         }
     } else {
         $this->error("Can't take talk page for user", ['founder_id' => $this->founder->getId()]);
     }
     $wgUser = $saveUser;
     // Restore user object after creating talk message
     return true;
 }
示例#4
0
 /**
  * sendWelcomeMail
  *
  * sensd welcome email to founder (if founder has set email address)
  *
  * @author eloy@wikia-inc.com
  * @author adi@wikia-inc.com
  * @author moli@wikia-inc.com
  * @access private
  *
  * @return boolean status
  */
 private function sendWelcomeMail()
 {
     global $wgUser, $wgPasswordSender, $wgWikiaEnableFounderEmailsExt;
     if (!empty($wgWikiaEnableFounderEmailsExt)) {
         // skip this step when FounderEmails extension is enabled
         Wikia::log(__METHOD__, "mail", "FounderEmails extension is enabled. Welcome email is not sent");
         return true;
     }
     $oReceiver = $this->mFounder;
     $sServer = $this->mParams->url;
     /**
      * set apropriate staff member
      */
     $oStaffUser = Wikia::staffForLang($this->mParams->language);
     $oStaffUser = $oStaffUser instanceof User ? $oStaffUser : User::newFromName(CreateWiki::DEFAULT_STAFF);
     $sFrom = new MailAddress($wgPasswordSender, "The Wikia Community Team");
     $sTo = $oReceiver->getEmail();
     $aBodyParams = array($sServer, $oReceiver->getName(), $oStaffUser->getRealName(), htmlspecialchars($oStaffUser->getTitleKey()), htmlspecialchars($oReceiver->getTalkPage()->getFullURL()));
     $sBody = $sBodyHTML = $sSubject = null;
     $language = @empty($this->mParams->language) ? 'en' : $this->mParams->language;
     list($sBody, $sBodyHTML) = wfMsgHTMLwithLanguage('autocreatewiki-welcomebody', $language, array(), $aBodyParams);
     $sSubject = wfMsgExt('autocreatewiki-welcomesubject', array('language' => $language), array($this->mParams->sitename));
     if (!empty($sTo)) {
         $status = $oReceiver->sendMail($sSubject, $sBody, $sFrom, null, 'AutoCreateWiki', $sBodyHTML);
         if ($status) {
             Wikia::log(__METHOD__, "mail", "Mail to founder {$sTo} sent.");
         }
     } else {
         Wikia::log(__METHOD__, "mail", "Founder email is not set. Welcome email is not sent");
     }
 }