X-Git-Url: https://git.toastfreeware.priv.at/toast/cookiecaptcha.git/blobdiff_plain/57a4a3972e8e39f2a5c308ecffa25c67e4a2e1f2..3c4fb15ef913ba30a0b2102ad797f5dfc9883fa8:/ConfirmEdit_body.php diff --git a/ConfirmEdit_body.php b/ConfirmEdit_body.php index 1f93ecf..2d21246 100644 --- a/ConfirmEdit_body.php +++ b/ConfirmEdit_body.php @@ -213,6 +213,22 @@ class SimpleCaptcha { return intval( $wgMemc->get( $this->badLoginKey() ) ) >= $wgCaptchaBadLoginAttempts; } + /** + * Check if the IP is allowed to skip captchas + */ + function isIPWhitelisted() { + global $wgCaptchaWhitelistIP; + if( $wgCaptchaWhitelistIP ) { + $ip = wfGetIp(); + foreach ( $wgCaptchaWhitelistIP as $range ) { + if ( IP::isInRange( $ip, $range ) ) { + return true; + } + } + } + return false; + } + /** * Internal cache key for badlogin checks. * @return string @@ -268,15 +284,8 @@ class SimpleCaptcha { wfDebug( "ConfirmEdit: user group allows skipping captcha\n" ); return false; } - global $wgCaptchaWhitelistIP; - if( !empty( $wgCaptchaWhitelistIP ) ) { - $ip = wfGetIp(); - foreach ( $wgCaptchaWhitelistIP as $range ) { - if ( IP::isInRange( $ip, $range ) ) { - return false; - } - } - } + if( $this->isIPWhitelisted() ) + return false; global $wgEmailAuthentication, $ceAllowConfirmedEmail; @@ -340,7 +349,7 @@ class SimpleCaptcha { } global $wgCaptchaRegexes; - if( !empty( $wgCaptchaRegexes ) ) { + if( $wgCaptchaRegexes ) { // Custom regex checks $oldtext = $this->loadText( $editPage, $section ); @@ -480,7 +489,7 @@ class SimpleCaptcha { * @return bool true to continue saving, false to abort and show a captcha form */ function confirmEdit( &$editPage, $newtext, $section, $merged = false ) { - if( defined('API') ) { + if( defined('MW_API') ) { # API mode # The CAPTCHA was already checked and approved return true; @@ -523,6 +532,9 @@ class SimpleCaptcha { wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" ); return true; } + if( $this->isIPWhitelisted() ) + return true; + $this->trigger = "new account '" . $u->getName() . "'"; if( !$this->passCaptcha() ) { $message = wfMsg( 'captcha-createaccount-fail' ); @@ -540,6 +552,9 @@ class SimpleCaptcha { */ function confirmUserLogin( $u, $pass, &$retval ) { if( $this->isBadLoginTriggered() ) { + if( $this->isIPWhitelisted() ) + return true; + $this->trigger = "post-badlogin login '" . $u->getName() . "'"; if( !$this->passCaptcha() ) { $message = wfMsg( 'captcha-badlogin-fail' );