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 Xml::element( 'input', array(
44 'name' => 'wpCaptchaWord',
45 'id' => 'wpCaptchaWord',
46 'tabindex' => 1 ) ) . // tab in before the edit textarea
48 Xml::element( 'input', array(
50 'name' => 'wpCaptchaId',
51 'id' => 'wpCaptchaId',
52 'value' => $index ) );
55 function getMessage( $action ) {
56 $name = 'questycaptcha-' . $action;
57 $text = wfMsg( $name );
58 # Obtain a more tailored message, if possible, otherwise, fall back to
59 # the default for edits
60 return wfEmptyMsg( $name, $text ) ? wfMsg( 'questycaptcha-edit' ) : $text;
65 $wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
66 $wgOut->addWikiText( wfMsg( 'questycaptchahelp-text' ) );
67 if ( $this->storage->cookiesNeeded() ) {
68 $wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );