Don't check badlogin attempts in memcached if we are not configured to show captchas...
[toast/cookiecaptcha.git] / QuestyCaptcha.class.php
old mode 100755 (executable)
new mode 100644 (file)
index 385edab..8e87db3
@@ -3,18 +3,23 @@
 /**
  * QuestyCaptcha class
  *
+ * @file
  * @author Benjamin Lees <emufarmers@gmail.com>
- * @addtogroup extensions
+ * @ingroup Extensions
  */
 
 class QuestyCaptcha extends SimpleCaptcha {
 
        /** Validate a captcha response */
        function keyMatch( $answer, $info ) {
-               return strtolower( $answer ) == strtolower( $info['answer'] );
+               if ( is_array( $info['answer'] ) ) {
+                       return in_array( strtolower( $answer ), $info['answer'] );
+               } else {
+                       return strtolower( $answer ) == strtolower( $info['answer'] );
+               }
        }
 
-       function addCaptchaAPI(&$resultArr) {
+       function addCaptchaAPI( &$resultArr ) {
                $captcha = $this->getCaptcha();
                $index = $this->storeCaptcha( $captcha );
                $resultArr['captcha']['type'] = 'question';
@@ -22,22 +27,23 @@ class QuestyCaptcha extends SimpleCaptcha {
                $resultArr['captcha']['id'] = $index;
                $resultArr['captcha']['question'] = $captcha['question'];
        }
-       
+
        function getCaptcha() {
                global $wgCaptchaQuestions;
-               return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions )-1 )]; //pick a question, any question
+               return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
        }
-       
+
        function getForm() {
                $captcha = $this->getCaptcha();
-               if(!$captcha) {
+               if ( !$captcha ) {
                        die( "No questions found; set some in LocalSettings.php using the format from QuestyCaptcha.php." );
                }
                $index = $this->storeCaptcha( $captcha );
                return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
-                       Xml::element( 'input', array(
+                       Html::element( 'input', array(
                                'name' => 'wpCaptchaWord',
                                'id'   => 'wpCaptchaWord',
+                               'required',
                                'tabindex' => 1 ) ) . // tab in before the edit textarea
                        "</p>\n" .
                        Xml::element( 'input', array(
@@ -46,7 +52,7 @@ class QuestyCaptcha extends SimpleCaptcha {
                                'id'    => 'wpCaptchaId',
                                'value' => $index ) );
        }
-       
+
        function getMessage( $action ) {
                $name = 'questycaptcha-' . $action;
                $text = wfMsg( $name );
@@ -54,14 +60,13 @@ class QuestyCaptcha extends SimpleCaptcha {
                # the default for edits
                return wfEmptyMsg( $name, $text ) ? wfMsg( 'questycaptcha-edit' ) : $text;
        }
-       
+
        function showHelp() {
-               global $wgOut, $ceAllowConfirmedEmail;
+               global $wgOut;
                $wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
                $wgOut->addWikiText( wfMsg( 'questycaptchahelp-text' ) );
-               if ( $this->storage->cookiesNeeded() ) {
+               if ( CaptchaStore::get()->cookiesNeeded() ) {
                        $wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );
                }
        }
-
-}
\ No newline at end of file
+}