Ejemplo 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;
}
function wfGetRegexBlocked($blocker, $user, $user_ip)
{
    global $wgContactLink;
    $names = wfGetRegexBlockedData($blocker, $user, REGEXBLOCK_MODE_NAMES);
    $ips = wfGetRegexBlockedData($blocker, $user, REGEXBLOCK_MODE_IPS);
    $username = $user->getName();
    $matched_name = preg_match('/' . $names . '/i', $user->getName(), $matches);
    $matched_ip = preg_match('/' . $ips . '/i', $user_ip, $ip_matches);
    if ($matched_name && $names != "" || $matched_ip && $ips != "") {
        /* check if this block hasn't expired already  */
        if ($matched_ip && $ips != "") {
            $valid = wfRegexBlockExpireCheck($user, null, $ip_matches);
        } else {
            $valid = wfRegexBlockExpireCheck($user, $matches, null);
        }
        if (is_array($valid)) {
            $user->mBlockedby = $blocker;
            if ($valid['reason'] != "") {
                /* a reason was given, display it */
                $user->mBlockreason = $valid['reason'];
            } else {
                /* display generic reasons */
                if ($matched_ip && $ips != "") {
                    /* we blocked by IP */
                    $user->mBlockreason = wfMsgHtml('regexblock-reason-ip', $wgContactLink);
                } else {
                    if ($valid['exact'] == 1) {
                        /* we blocked by username exact match */
                        $user->mBlockreason = wfMsgHtml('regexblock-reason-name', $wgContactLink);
                    } else {
                        /* we blocked by regex match */
                        $user->mBlockreason = wfMsgHtml('regexblock-reason-regex', $wgContactLink);
                    }
                }
            }
            /* account creation check goes through the same hook... */
            if ($valid['create'] == 1) {
                $user->mBlock->mCreateAccount = 1;
            }
            wfRegexBlockUpdateStats($username, $user_ip, $blocker);
        }
    }
}