Exemplo n.º 1
0
function wfRegexBlockCheck($current_user)
{
    global $wgRequest;
    wfProfileIn(__METHOD__);
    $userGroups = $current_user->getGroups();
    if (empty($userGroups)) {
        $userGroups = array();
    }
    if (in_array('staff', $userGroups)) {
        // Staff users should not be blocked in any case
        wfProfileOut(__METHOD__);
        return true;
    }
    $ip_to_check = $wgRequest->getIP();
    /* First check cache */
    $blocked = wfRegexBlockIsBlockedCheck($current_user, $ip_to_check);
    if ($blocked) {
        wfProfileOut(__METHOD__);
        return true;
    }
    $blockers_array = wfRegexBlockGetBlockers();
    $block_data = wfGetRegexBlockedData($current_user, $blockers_array);
    /* check user for each blocker */
    foreach ($blockers_array as $blocker) {
        $blocker_block_data = isset($block_data[$blocker]) ? $block_data[$blocker] : null;
        wfGetRegexBlocked($blocker, $blocker_block_data, $current_user, $ip_to_check);
    }
    wfProfileOut(__METHOD__);
    return true;
}
 public function fetchBlockers()
 {
     $blockers_array = array();
     wfProfileIn(__METHOD__);
     if (function_exists('wfRegexBlockGetBlockers')) {
         $blockers_array = wfRegexBlockGetBlockers();
     } else {
         global $wgMemc, $wgExternalSharedDB;
         $key = self::getMemcKey("blockers");
         $cached = $wgMemc->get($key);
         if (!is_array($cached)) {
             /* get from database */
             $dbr = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
             $oRes = $dbr->select($this->mTable, array("blckby_blocker"), array("blckby_blocker <> ''"), __METHOD__, array("GROUP BY" => "blckby_blocker"));
             while ($oRow = $dbr->fetchObject($oRes)) {
                 $blockers_array[] = $oRow->blckby_blocker;
             }
             $dbr->freeResult($oRes);
             $wgMemc->set($key, $blockers_array, REGEXBLOCK_EXPIRE);
         } else {
             /* get from cache */
             $blockers_array = $cached;
         }
     }
     wfProfileOut(__METHOD__);
     return $blockers_array;
 }