function wfRegexBlockCheck($current_user)
{
    global $wgMemc, $wgSharedDB;
    if (!wfSimplifiedRegexCheckSharedDB()) {
        return;
    }
    $ip_to_check = wfGetIP();
    $key = "{$wgSharedDB}:regexBlockCore:blockers";
    $cached = $wgMemc->get($key);
    if (!is_array($cached)) {
        /* get from database */
        $blockers_array = array();
        $dbr =& wfGetDB(DB_SLAVE);
        $query = "SELECT blckby_blocker FROM " . wfRegexBlockGetTable() . " GROUP BY blckby_blocker";
        $res = $dbr->query($query);
        while ($row = $dbr->fetchObject($res)) {
            wfGetRegexBlocked($row->blckby_blocker, $current_user, $ip_to_check);
            array_push($blockers_array, $row->blckby_blocker);
        }
        $dbr->freeResult($res);
        $wgMemc->set($key, $blockers_array, REGEXBLOCK_EXPIRE);
    } else {
        /* get from cache */
        foreach ($cached as $blocker) {
            wfGetRegexBlocked($blocker, $current_user, $ip_to_check);
        }
    }
    return true;
}
예제 #2
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;
}