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