Get rid of the last (I think) php4-style calls to wfGetDB()
[toast/cookiecaptcha.git] / QuestyCaptcha.class.php
1 <?php
2
3 /**
4  * QuestyCaptcha class
5  *
6  * @author Benjamin Lees <emufarmers@gmail.com>
7  * @addtogroup extensions
8  */
9
10 class QuestyCaptcha extends SimpleCaptcha {
11
12         /** Validate a captcha response */
13         function keyMatch( $answer, $info ) {
14                 return strtolower( $answer ) == strtolower( $info['answer'] );
15         }
16
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'];
24         }
25
26         function getCaptcha() {
27                 global $wgCaptchaQuestions;
28                 return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
29         }
30
31         function getForm() {
32                 $captcha = $this->getCaptcha();
33                 if ( !$captcha ) {
34                         die( "No questions found; set some in LocalSettings.php using the format from QuestyCaptcha.php." );
35                 }
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
42                         "</p>\n" .
43                         Xml::element( 'input', array(
44                                 'type'  => 'hidden',
45                                 'name'  => 'wpCaptchaId',
46                                 'id'    => 'wpCaptchaId',
47                                 'value' => $index ) );
48         }
49
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;
56         }
57
58         function showHelp() {
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' ) );
64                 }
65         }
66 }