コード例 #1
0
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);
        }
    }
}
コード例 #2
0
ファイル: RegexBlockCore.php プロジェクト: Tjorriemorrie/app
function wfGetRegexBlocked($blocker, $blocker_block_data, $user, $user_ip)
{
    wfProfileIn(__METHOD__);
    if ($blocker_block_data == null) {
        // no data for given blocker, aborting..
        wfProfileOut(__METHOD__);
        return false;
    }
    $ips = isset($blocker_block_data["ips"]) ? $blocker_block_data["ips"] : null;
    $names = isset($blocker_block_data["regex"]) ? $blocker_block_data["regex"] : null;
    $exact = isset($blocker_block_data["exact"]) ? $blocker_block_data["exact"] : null;
    // backward compatibility ;)
    $result = $blocker_block_data;
    /* check ips */
    if (!empty($ips) && in_array($user_ip, $ips)) {
        $result["ips"]['matches'] = array($user_ip);
        wfDebugLog('RegexBlock', "Found some ips to block: " . implode(",", $result["ips"]['matches']) . "\n");
    }
    /* check regexes */
    if (!empty($result["regex"]) && is_array($result["regex"])) {
        $result["regex"]['matches'] = wfRegexBlockPerformMatch($result["regex"], $user->getName());
        if (!empty($result["regex"]['matches'])) {
            wfDebugLog('RegexBlock', "Found some regexes to block: " . implode(",", $result["regex"]['matches']) . "\n");
        }
    }
    /* check names of user */
    $exact = is_array($exact) ? $exact : array($exact);
    if (!empty($exact) && in_array($user->getName(), $exact)) {
        $key = array_search($user->getName(), $exact);
        $result["exact"]['matches'] = array($exact[$key]);
        wfDebugLog('RegexBlock', "Found some users to block: " . implode(",", $result["exact"]['matches']) . "\n");
    }
    unset($ips);
    unset($names);
    unset($exact);
    /* run expire checks for all matched values
    	   this is only for determining validity of this block, so
    	   a first successful match means the block is applied
    	*/
    $valid = false;
    foreach ($result as $key => $value) {
        $is_ip = "ips" == $key ? 1 : 0;
        $is_regex = "regex" == $key ? 1 : 0;
        /* check if this block hasn't expired already  */
        if (!empty($result[$key]['matches'])) {
            $valid = wfRegexBlockExpireCheck($user, $result[$key]['matches'], $is_ip, $is_regex);
            if (is_array($valid)) {
                break;
            }
        }
    }
    if (is_array($valid)) {
        wfRegexBlockSetUserData($user, $user_ip, $blocker, $valid);
    }
    wfProfileOut(__METHOD__);
    return true;
}