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
This commit is contained in:
Gergő Tisza 2016-05-17 17:55:28 +00:00
parent f5af433e26
commit f97212acbf
3 changed files with 26 additions and 7 deletions

View file

@ -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 ];
}
/**

View file

@ -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 ];
}
/**

View file

@ -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.