6 * @author Benjamin Lees <emufarmers@gmail.com>
7 * @addtogroup extensions
10 class QuestyCaptcha extends SimpleCaptcha {
12 /** Validate a captcha response */
13 function keyMatch( $answer, $info ) {
14 return strtolower( $answer ) == strtolower( $info['answer'] );
17 function addCaptchaAPI( &$resultArr ) {
18 $captcha = $this->getCaptcha();
19 $index = $this->storeCaptcha( $captcha );
20 $resultArr['captcha']['type'] = 'question';
21 $resultArr['captcha']['mime'] = 'text/plain';
22 $resultArr['captcha']['id'] = $index;
23 $resultArr['captcha']['question'] = $captcha['question'];
26 function getCaptcha() {
27 global $wgCaptchaQuestions;
28 return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
32 $captcha = $this->getCaptcha();
34 die( "No questions found; set some in LocalSettings.php using the format from QuestyCaptcha.php." );
36 $index = $this->storeCaptcha( $captcha );
37 return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
38 Xml::element( 'input', array(
39 'name' => 'wpCaptchaWord',
40 'id' => 'wpCaptchaWord',
41 'tabindex' => 1 ) ) . // tab in before the edit textarea
43 Xml::element( 'input', array(
45 'name' => 'wpCaptchaId',
46 'id' => 'wpCaptchaId',
47 'value' => $index ) );
50 function getMessage( $action ) {
51 $name = 'questycaptcha-' . $action;
52 $text = wfMsg( $name );
53 # Obtain a more tailored message, if possible, otherwise, fall back to
54 # the default for edits
55 return wfEmptyMsg( $name, $text ) ? wfMsg( 'questycaptcha-edit' ) : $text;
59 global $wgOut, $ceAllowConfirmedEmail;
60 $wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
61 $wgOut->addWikiText( wfMsg( 'questycaptchahelp-text' ) );
62 if ( $this->storage->cookiesNeeded() ) {
63 $wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );