]> ToastFreeware Gitweb - toast/cookiecaptcha.git/blobdiff - MathCaptcha.class.php
Localisation updates for extension messages from translatewiki.net (2009-07-03 23...
[toast/cookiecaptcha.git] / MathCaptcha.class.php
index 01d63915035bb20c2d1fff645218e3380b31d80c..9348d873b28b68251ea452a0b2428650a5b3b04c 100644 (file)
@@ -3,8 +3,17 @@
 class MathCaptcha extends SimpleCaptcha {
 
        /** Validate a captcha response */
-       function keyMatch( $req, $info ) {
-               return (int)$req->getVal( 'wpCaptchaAnswer' ) == (int)$info['answer'];
+       function keyMatch( $answer, $info ) {
+               return (int)$answer == (int)$info['answer'];
+       }
+
+       function addCaptchaAPI(&$resultArr) {
+               list( $sum, $answer ) = $this->pickSum();
+               $index = $this->storeCaptcha( array('answer' => $answer ) );
+               $resultArr['captcha']['type'] = 'math';
+               $resultArr['captcha']['mime'] = 'text/tex';
+               $resultArr['captcha']['id'] = $index;
+               $resultArr['captcha']['question'] = $sum;
        }
        
        /** Produce a nice little form */
@@ -13,8 +22,8 @@ class MathCaptcha extends SimpleCaptcha {
                $index = $this->storeCaptcha( array( 'answer' => $answer ) );
                
                $form = '<table><tr><td>' . $this->fetchMath( $sum ) . '</td>';
-               $form .= '<td>' . wfInput( 'wpCaptchaAnswer', false, false, array( 'tabindex' => '1' ) ) . '</td></tr></table>';
-               $form .= wfHidden( 'wpCaptchaId', $index );
+               $form .= '<td>' . Xml::input( 'wpCaptchaWord', false, false, array( 'tabindex' => '1' ) ) . '</td></tr></table>';
+               $form .= Xml::hidden( 'wpCaptchaId', $index );
                return $form;
        }
        
@@ -33,7 +42,7 @@ class MathCaptcha extends SimpleCaptcha {
                $math = new MathRenderer( $sum );
                $math->setOutputMode( MW_MATH_PNG );
                $html = $math->render();
-               return preg_replace( '/alt=".*"/', '', $html );
+               return preg_replace( '/alt=".*?"/', '', $html );
        }
 
 }