コード例 #1
0
 static function getAllAnonMessages($user, $dismissLink = true, $formatted = true)
 {
     global $wgCookiePrefix, $wgCityId, $wgLanguageCode;
     global $wgExternalSharedDB;
     wfProfileIn(__METHOD__);
     $localCityId = isset($wgCityId) ? $wgCityId : 0;
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     $tmpMsg = array();
     $dbResult = $dbr->query('SELECT msg_wiki_id, msg_id AS id, msg_text AS text, msg_expire AS expire, msg_lang AS lang, msg_status AS status' . ' FROM ' . MSG_TEXT_DB . ' USE INDEX(removed_mode_expire_date)' . ' LEFT JOIN ' . MSG_STATUS_DB . ' USE INDEX(PRIMARY) USING (msg_id)' . ' WHERE msg_mode = ' . MSG_MODE_SELECTED . ' AND msg_recipient_id = 0' . ' AND msg_recipient_name = ' . $dbr->addQuotes(MSG_RECIPIENT_ANON) . ' AND msg_status IN (' . MSG_STATUS_UNSEEN . ', ' . MSG_STATUS_SEEN . ')' . ' AND (msg_expire IS NULL OR msg_expire > ' . $dbr->addQuotes(date('Y-m-d H:i:s')) . ')' . ' AND msg_removed = ' . MSG_REMOVED_NO . " AND (msg_wiki_id = 0 OR msg_wiki_id = {$localCityId} )" . ';', __METHOD__);
     while ($oMsg = $dbr->fetchObject($dbResult)) {
         if (!isset($_COOKIE[$wgCookiePrefix . 'swm-' . $oMsg->id]) && self::getLanguageConstraintsForUser($user, $oMsg->lang)) {
             $tmpMsg[$oMsg->id] = array('wiki_id' => $oMsg->msg_wiki_id, 'text' => $oMsg->text, 'expire' => $oMsg->expire, 'status' => $oMsg->status);
         }
     }
     if ($dbResult !== false) {
         $dbr->freeResult($dbResult);
     }
     //sort from newer to older
     krsort($tmpMsg);
     $messages = array();
     $language = Language::factory($wgLanguageCode);
     foreach ($tmpMsg as $tmpMsgId => $tmpMsgData) {
         $messages[] = $dismissLink ? "<div class=\"SWM_message\" id=\"msg_{$tmpMsgId}\">\n" . "{$tmpMsgData['text']}\n" . "<span class=\"SWM_dismiss\"><nowiki>[</nowiki><span class=\"plainlinks\">[{{fullurl:Special:SiteWideMessages|action=dismiss&mID={$tmpMsgId}}} " . wfMsg('swm-link-dismiss') . "]</span><nowiki>]</nowiki></span>" . (is_null($tmpMsgData['expire']) ? '' : "<span class=\"SWM_expire\">" . wfMsg('swm-expire-info', array($language->timeanddate(strtotime($tmpMsgData['expire']), true, $user->getDatePreference()))) . "</span>") . "<div>&nbsp;</div></div>" : "<div class=\"SWM_message\">{$tmpMsgData['text']}</div>";
     }
     //prevent double execution of all those queries
     if (count($messages)) {
         self::$hasMessages = true;
     }
     if ($formatted) {
         $result = implode("\n", $messages);
     } else {
         $result = $tmpMsg;
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
コード例 #2
0
 static function getAllUserMessages($user, $dismissLink = true, $formatted = true)
 {
     global $wgMemc, $wgCityId, $wgLanguageCode;
     global $wgExternalSharedDB;
     if (!$user->isLoggedIn()) {
         return false;
     }
     wfProfileIn(__METHOD__);
     $localCityId = isset($wgCityId) ? $wgCityId : 0;
     $DB = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     //step 1 of 3: get all active messages sent to *all*
     //left outer join here now returns rows where recipient_id is null, but skips users which are NOT our guy. :)
     $dbResult = $DB->Query('SELECT ' . MSG_TEXT_DB . '.msg_id AS id, msg_text AS text, msg_expire AS expire, msg_lang AS lang, msg_recipient_id AS user_id, msg_status AS status' . ' FROM ' . MSG_TEXT_DB . ' LEFT JOIN ' . MSG_STATUS_DB . ' ON ' . MSG_TEXT_DB . '.msg_id = ' . MSG_STATUS_DB . '.msg_id' . ' AND ' . MSG_STATUS_DB . '.msg_recipient_id = ' . $DB->AddQuotes($user->GetID()) . ' WHERE msg_removed = ' . MSG_REMOVED_NO . ' AND msg_mode = ' . MSG_MODE_ALL . ' AND (msg_expire IS NULL OR msg_expire > ' . $DB->AddQuotes(date('Y-m-d H:i:s')) . ')' . " AND " . MSG_TEXT_DB . ".msg_date > '{$user->mRegistration}'" . ';', __METHOD__);
     $tmpMsg = array();
     $userId = $user->getID();
     while ($oMsg = $DB->FetchObject($dbResult)) {
         if (self::getLanguageConstraintsForUser($user, $oMsg->lang)) {
             $tmpMsg[$oMsg->id] = array('wiki_id' => null, 'text' => $oMsg->text, 'expire' => $oMsg->expire);
             //fix for RT#48187
             if ($oMsg->user_id == $userId) {
                 $tmpMsg[$oMsg->id]['status'] = $oMsg->status;
             }
         }
     }
     if ($dbResult !== false) {
         $DB->FreeResult($dbResult);
     }
     if (count($tmpMsg)) {
         //step 2 of 3: remove dismissed messages
         $dbResult = $DB->Query('SELECT msg_id AS id' . ' FROM ' . MSG_STATUS_DB . ' WHERE msg_id IN (' . implode(',', array_keys($tmpMsg)) . ')' . ' AND msg_recipient_id = ' . $DB->AddQuotes($user->GetID()) . ' AND msg_status = ' . MSG_STATUS_DISMISSED . ';', __METHOD__);
         while ($oMsg = $DB->FetchObject($dbResult)) {
             unset($tmpMsg[$oMsg->id]);
         }
         if ($dbResult !== false) {
             $DB->FreeResult($dbResult);
         }
     }
     //step 3 of 3: add undismissed messages sent to *this* user (on *all* wikis or *this* wiki)
     $dbResult = $DB->Query('SELECT msg_wiki_id, msg_id AS id, msg_text AS text, msg_expire AS expire, msg_lang AS lang, msg_status AS status' . ' FROM ' . MSG_TEXT_DB . ' LEFT JOIN ' . MSG_STATUS_DB . ' USING (msg_id)' . ' WHERE msg_mode = ' . MSG_MODE_SELECTED . ' AND msg_recipient_id = ' . $DB->AddQuotes($user->GetID()) . ' AND msg_status IN (' . MSG_STATUS_UNSEEN . ', ' . MSG_STATUS_SEEN . ')' . ' AND (msg_expire IS NULL OR msg_expire > ' . $DB->AddQuotes(date('Y-m-d H:i:s')) . ')' . ' AND msg_removed = ' . MSG_REMOVED_NO . " AND (msg_wiki_id = 0 OR msg_wiki_id = {$localCityId} )" . ';', __METHOD__);
     while ($oMsg = $DB->FetchObject($dbResult)) {
         if (self::getLanguageConstraintsForUser($user, $oMsg->lang)) {
             $tmpMsg[$oMsg->id] = array('wiki_id' => $oMsg->msg_wiki_id, 'text' => $oMsg->text, 'expire' => $oMsg->expire, 'status' => $oMsg->status);
         }
     }
     if ($dbResult !== false) {
         $DB->FreeResult($dbResult);
     }
     //sort from newer to older
     krsort($tmpMsg);
     $messages = array();
     $language = Language::factory($wgLanguageCode);
     foreach ($tmpMsg as $tmpMsgId => $tmpMsgData) {
         $messages[] = $dismissLink ? "<div class=\"SWM_message\" id=\"msg_{$tmpMsgId}\">\n" . "{$tmpMsgData['text']}\n" . "<span class=\"SWM_dismiss\"><nowiki>[</nowiki><span class=\"plainlinks\">[{{fullurl:Special:SiteWideMessages|action=dismiss&mID={$tmpMsgId}}} " . wfMsg('swm-link-dismiss') . "]</span><nowiki>]</nowiki></span>" . (is_null($tmpMsgData['expire']) ? '' : "<span class=\"SWM_expire\">" . wfMsg('swm-expire-info', array($language->timeanddate(strtotime($tmpMsgData['expire']), true, $user->getDatePreference()))) . "</span>") . "<div>&nbsp;</div></div>" : "<div class=\"SWM_message\">{$tmpMsgData['text']}</div>";
     }
     //prevent double execution of all those queries
     if (count($messages)) {
         self::$hasMessages = true;
     }
     $userID = $user->GetID();
     //once the messages are displayed, they must be marked as "seen" so user will not see "you have new messages" from now on
     $countDisplayed = count($tmpMsg);
     //do update only for not marked before
     // Keep a copy of these around to return if necessary
     $unformatted = $tmpMsg;
     if ($countDisplayed) {
         //purge the cache
         $key = 'wikia:talk_messages:' . $userID . ':' . str_replace(' ', '_', $user->getName());
         $wgMemc->set($key, 'deleted', 100);
     }
     if ($formatted) {
         $result = implode("\n", $messages);
     } else {
         $result = $unformatted;
     }
     wfProfileOut(__METHOD__);
     return $result;
 }