diff --git a/ReCaptcha/ReCaptcha.class.php b/ReCaptcha/ReCaptcha.class.php index 9e6cffb7e..e92791aac 100644 --- a/ReCaptcha/ReCaptcha.class.php +++ b/ReCaptcha/ReCaptcha.class.php @@ -27,13 +27,12 @@ class ReCaptcha extends SimpleCaptcha { recaptcha_get_html( $wgReCaptchaPublicKey, $this->recaptcha_error, $useHttps ); } - function passCaptchaLimitedFromRequest( WebRequest $request, User $user ) { + protected function getCaptchaParamsFromRequest( WebRequest $request ) { // API is hardwired to return captchaId and captchaWord, // so use that if the standard two are empty $challenge = $request->getVal( 'recaptcha_challenge_field', $request->getVal( 'captchaId' ) ); $response = $request->getVal( 'recaptcha_response_field', $request->getVal( 'captchaWord' ) ); - - return $this->passCaptchaLimited( $challenge, $response, $user ); + return [ $challenge, $response ]; } /** diff --git a/ReCaptchaNoCaptcha/ReCaptchaNoCaptcha.class.php b/ReCaptchaNoCaptcha/ReCaptchaNoCaptcha.class.php index 759c5dacc..1d9130bf4 100644 --- a/ReCaptchaNoCaptcha/ReCaptchaNoCaptcha.class.php +++ b/ReCaptchaNoCaptcha/ReCaptchaNoCaptcha.class.php @@ -70,11 +70,11 @@ HTML; wfDebugLog( 'captcha', 'Unable to validate response: ' . $error ); } - public function passCaptchaLimitedFromRequest( WebRequest $request, User $user ) { + protected function getCaptchaParamsFromRequest( WebRequest $request ) { $index = 'not used'; // ReCaptchaNoCaptcha combines captcha ID + solution into a single value // API is hardwired to return captchaWord, so use that if the standard isempty $response = $request->getVal( 'g-recaptcha-response', $request->getVal( 'captchaWord' ) ); - return $this->passCaptchaLimited( $index, $response, $user ); + return [ $index, $response ]; } /** diff --git a/SimpleCaptcha/Captcha.php b/SimpleCaptcha/Captcha.php index 9b58259bb..63ed6d619 100755 --- a/SimpleCaptcha/Captcha.php +++ b/SimpleCaptcha/Captcha.php @@ -1059,10 +1059,18 @@ class SimpleCaptcha { * @return bool */ public function passCaptchaLimitedFromRequest( WebRequest $request, User $user ) { + list( $index, $word ) = $this->getCaptchaParamsFromRequest( $request ); + return $this->passCaptchaLimited( $index, $word, $user ); + } + + /** + * @param WebRequest $request + * @return array [ captcha ID, captcha solution ] + */ + protected function getCaptchaParamsFromRequest( WebRequest $request ) { $index = $request->getVal( 'wpCaptchaId' ); $word = $request->getVal( 'wpCaptchaWord' ); - - return $this->passCaptchaLimited( $index, $word, $user ); + return [ $index, $word ]; } /** @@ -1092,6 +1100,18 @@ class SimpleCaptcha { return false; } + /** + * Given a required captcha run, test form input for correct + * input on the open session. + * @param WebRequest $request + * @param User $user + * @return bool if passed, false if failed or new session + */ + public function passCaptchaFromRequest( WebRequest $request, User $user ) { + list( $index, $word ) = $this->getCaptchaParamsFromRequest( $request ); + return $this->passCaptcha( $index, $word, $user ); + } + /** * Given a required captcha run, test form input for correct * input on the open session.