Esempio n. 1
0
 /**
  * Directly check for IP block which is quicker than looping through all filters as we don't support
  * anything other than exact for IP blocks, and this significantly improves performance
  *
  * @author grunny
  */
 protected static function blockCheckIP(User $user, $text, $writeStats = true)
 {
     global $wgMemc, $wgExternalSharedDB;
     wfProfileIn(__METHOD__);
     PhalanxShadowing::setType(Phalanx::TYPE_USER);
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     $moduleId = Phalanx::TYPE_USER;
     $timestampNow = wfTimestampNow();
     $ipAddr = IP::toHex($text);
     $row = $dbr->selectRow('phalanx', '*', array("p_type & {$moduleId} = {$moduleId}", "p_lang IS NULL", 'p_ip_hex' => $ipAddr, "p_expire IS NULL OR p_expire > {$dbr->addQuotes($timestampNow)}"), __METHOD__);
     if ($row !== false) {
         $blockData = array('id' => $row->p_id, 'author_id' => $row->p_author_id, 'text' => $row->p_text, 'type' => $row->p_type, 'timestamp' => $row->p_timestamp, 'expire' => $row->p_expire, 'exact' => $row->p_exact, 'regex' => $row->p_regex, 'case' => $row->p_case, 'reason' => $row->p_reason, 'lang' => $row->p_lang);
         Wikia::log(__METHOD__, __LINE__, "Block '{$blockData['text']}' blocked '{$text}'.");
         if ($writeStats) {
             Phalanx::addStats($blockData['id'], $blockData['type']);
         }
         self::setUserData($user, $blockData, $text, true);
         $cachedState = array('timestamp' => wfTimestampNow(), 'block' => $blockData, 'return' => false);
         $wgMemc->set(self::getCacheKey($user), $cachedState);
         PhalanxShadowing::check($user->getName(), $blockData['id']);
         wfProfileOut(__METHOD__);
         return false;
     }
     PhalanxShadowing::check($user->getName(), 0);
     wfProfileOut(__METHOD__);
     return true;
 }