7 * @author Benjamin Lees <emufarmers@gmail.com>
11 class QuestyCaptcha extends SimpleCaptcha {
13 /** Validate a captcha response */
14 function keyMatch( $answer, $info ) {
15 if ( is_array( $info['answer'] ) ) {
16 return in_array( strtolower( $answer ), $info['answer'] );
18 return strtolower( $answer ) == strtolower( $info['answer'] );
22 function addCaptchaAPI( &$resultArr ) {
23 $captcha = $this->getCaptcha();
24 $index = $this->storeCaptcha( $captcha );
25 $resultArr['captcha']['type'] = 'question';
26 $resultArr['captcha']['mime'] = 'text/plain';
27 $resultArr['captcha']['id'] = $index;
28 $resultArr['captcha']['question'] = $captcha['question'];
31 function getCaptcha() {
32 global $wgCaptchaQuestions;
33 return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
37 $captcha = $this->getCaptcha();
39 die( "No questions found; set some in LocalSettings.php using the format from QuestyCaptcha.php." );
41 $index = $this->storeCaptcha( $captcha );
42 return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
43 Html::element( 'input', array(
44 'name' => 'wpCaptchaWord',
45 'id' => 'wpCaptchaWord',
47 'tabindex' => 1 ) ) . // tab in before the edit textarea
49 Xml::element( 'input', array(
51 'name' => 'wpCaptchaId',
52 'id' => 'wpCaptchaId',
53 'value' => $index ) );
56 function getMessage( $action ) {
57 $name = 'questycaptcha-' . $action;
58 $text = wfMsg( $name );
59 # Obtain a more tailored message, if possible, otherwise, fall back to
60 # the default for edits
61 return wfEmptyMsg( $name, $text ) ? wfMsg( 'questycaptcha-edit' ) : $text;
66 $wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
67 $wgOut->addWikiText( wfMsg( 'questycaptchahelp-text' ) );
68 if ( $this->storage->cookiesNeeded() ) {
69 $wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );