mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-12 01:11:15 +00:00
804903b4a7
This broke account creation for apps.
< anomie>bd808: Very likely $wgRequest !==
$loginForm->getContext()->getRequest() in SimpleCaptcha::addNewAccountApiForm(), so when it
uses $wgRequest to check later on it doesn't see the parameter renames made by that hook
function.
This reverts commit 23c6f2f04f
.
Change-Id: I793e7a987944d14c3be0eba4c4361793183a62b9
83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* QuestyCaptcha class
|
|
*
|
|
* @file
|
|
* @author Benjamin Lees <emufarmers@gmail.com>
|
|
* @ingroup Extensions
|
|
*/
|
|
|
|
class QuestyCaptcha extends SimpleCaptcha {
|
|
|
|
/** Validate a captcha response */
|
|
function keyMatch( $answer, $info ) {
|
|
if ( is_array( $info['answer'] ) ) {
|
|
return in_array( strtolower( $answer ), $info['answer'] );
|
|
} else {
|
|
return strtolower( $answer ) == strtolower( $info['answer'] );
|
|
}
|
|
}
|
|
|
|
function addCaptchaAPI( &$resultArr ) {
|
|
$captcha = $this->getCaptcha();
|
|
$index = $this->storeCaptcha( $captcha );
|
|
$resultArr['captcha']['type'] = 'question';
|
|
$resultArr['captcha']['mime'] = 'text/plain';
|
|
$resultArr['captcha']['id'] = $index;
|
|
$resultArr['captcha']['question'] = $captcha['question'];
|
|
}
|
|
|
|
function getCaptcha() {
|
|
global $wgCaptchaQuestions;
|
|
|
|
//Backwards compatibility
|
|
if ( $wgCaptchaQuestions === array_values( $wgCaptchaQuestions ) ) {
|
|
return $wgCaptchaQuestions[ mt_rand( 0, count( $wgCaptchaQuestions ) - 1 ) ];
|
|
}
|
|
|
|
$question = array_rand( $wgCaptchaQuestions, 1 );
|
|
$answer = $wgCaptchaQuestions[ $question ];
|
|
return array( 'question' => $question, 'answer' => $answer );
|
|
}
|
|
|
|
function getForm() {
|
|
$captcha = $this->getCaptcha();
|
|
if ( !$captcha ) {
|
|
die( "No questions found; set some in LocalSettings.php using the format from QuestyCaptcha.php." );
|
|
}
|
|
$index = $this->storeCaptcha( $captcha );
|
|
return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
|
|
Html::element( 'input', array(
|
|
'name' => 'wpCaptchaWord',
|
|
'id' => 'wpCaptchaWord',
|
|
'class' => 'mw-ui-input',
|
|
'required',
|
|
'autocomplete' => 'off',
|
|
'tabindex' => 1 ) ) . // tab in before the edit textarea
|
|
"</p>\n" .
|
|
Xml::element( 'input', array(
|
|
'type' => 'hidden',
|
|
'name' => 'wpCaptchaId',
|
|
'id' => 'wpCaptchaId',
|
|
'value' => $index ) );
|
|
}
|
|
|
|
function getMessage( $action ) {
|
|
$name = 'questycaptcha-' . $action;
|
|
$text = wfMessage( $name )->text();
|
|
# Obtain a more tailored message, if possible, otherwise, fall back to
|
|
# the default for edits
|
|
return wfMessage( $name, $text )->isDisabled() ? wfMessage( 'questycaptcha-edit' )->text() : $text;
|
|
}
|
|
|
|
function showHelp() {
|
|
global $wgOut;
|
|
$wgOut->setPageTitle( wfMessage( 'captchahelp-title' )->text() );
|
|
$wgOut->addWikiMsg( 'questycaptchahelp-text' );
|
|
if ( CaptchaStore::get()->cookiesNeeded() ) {
|
|
$wgOut->addWikiMsg( 'captchahelp-cookies-needed' );
|
|
}
|
|
}
|
|
}
|