2009-07-19 04:15:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* QuestyCaptcha class
|
|
|
|
*
|
2010-06-06 15:12:22 +00:00
|
|
|
* @file
|
2009-07-19 04:15:55 +00:00
|
|
|
* @author Benjamin Lees <emufarmers@gmail.com>
|
2010-06-06 15:12:22 +00:00
|
|
|
* @ingroup Extensions
|
2009-07-19 04:15:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class QuestyCaptcha extends SimpleCaptcha {
|
|
|
|
|
|
|
|
/** Validate a captcha response */
|
|
|
|
function keyMatch( $answer, $info ) {
|
2011-02-08 23:39:17 +00:00
|
|
|
if ( is_array( $info['answer'] ) ) {
|
|
|
|
return in_array( strtolower( $answer ), $info['answer'] );
|
|
|
|
} else {
|
|
|
|
return strtolower( $answer ) == strtolower( $info['answer'] );
|
|
|
|
}
|
2009-07-19 04:15:55 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
function addCaptchaAPI( &$resultArr ) {
|
2009-07-19 04:15:55 +00:00
|
|
|
$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'];
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2009-07-19 04:15:55 +00:00
|
|
|
function getCaptcha() {
|
|
|
|
global $wgCaptchaQuestions;
|
2009-07-19 15:13:01 +00:00
|
|
|
return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
|
2009-07-19 04:15:55 +00:00
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2009-07-19 04:15:55 +00:00
|
|
|
function getForm() {
|
|
|
|
$captcha = $this->getCaptcha();
|
2009-07-19 15:13:01 +00:00
|
|
|
if ( !$captcha ) {
|
2009-07-19 04:15:55 +00:00
|
|
|
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> " .
|
2011-10-21 14:59:16 +00:00
|
|
|
Html::element( 'input', array(
|
2009-07-19 04:15:55 +00:00
|
|
|
'name' => 'wpCaptchaWord',
|
|
|
|
'id' => 'wpCaptchaWord',
|
2011-10-21 14:59:16 +00:00
|
|
|
'required',
|
2009-07-19 04:15:55 +00:00
|
|
|
'tabindex' => 1 ) ) . // tab in before the edit textarea
|
|
|
|
"</p>\n" .
|
|
|
|
Xml::element( 'input', array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'wpCaptchaId',
|
|
|
|
'id' => 'wpCaptchaId',
|
|
|
|
'value' => $index ) );
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2009-07-19 04:15:55 +00:00
|
|
|
function getMessage( $action ) {
|
|
|
|
$name = 'questycaptcha-' . $action;
|
|
|
|
$text = wfMsg( $name );
|
|
|
|
# Obtain a more tailored message, if possible, otherwise, fall back to
|
|
|
|
# the default for edits
|
|
|
|
return wfEmptyMsg( $name, $text ) ? wfMsg( 'questycaptcha-edit' ) : $text;
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
2009-07-19 04:15:55 +00:00
|
|
|
function showHelp() {
|
2010-07-26 21:42:17 +00:00
|
|
|
global $wgOut;
|
2009-07-19 04:15:55 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
|
|
|
|
$wgOut->addWikiText( wfMsg( 'questycaptchahelp-text' ) );
|
2011-12-01 16:24:49 +00:00
|
|
|
if ( CaptchaStore::get()->cookiesNeeded() ) {
|
2009-07-19 04:15:55 +00:00
|
|
|
$wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );
|
|
|
|
}
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
}
|