From f97212acbfcbc43c4c13cff0c22598e3b7dc7871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Tisza?= Date: Tue, 17 May 2016 17:55:28 +0000 Subject: [PATCH] Expose equivalent functionality for passCaptcha passCaptcha was made protected in I0da671a546700110d789b79a3089460abd9cce3b, but some other extensions used it, provide passCaptchaFromRequest as a replacement. Bug: T135477 Change-Id: I47b2e2fbe3e063cd86e8a2d6bc17ca939472dbe1 --- ReCaptcha/ReCaptcha.class.php | 5 ++-- .../ReCaptchaNoCaptcha.class.php | 4 ++-- SimpleCaptcha/Captcha.php | 24 +++++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) 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.