Adding elements to $wgSpecialPages must be done before SpecialPage::initList()
[toast/cookiecaptcha.git] / FancyCaptcha.php
index 4a6b438e4ce3ced0161fb1915ec40ec0317f69a1..c21afb8c854775c82add2f4b2f6b60467e145501 100644 (file)
@@ -51,7 +51,7 @@ class FancyCaptcha extends SimpleCaptcha {
                $answerHash = substr( md5( $digest ), 0, 16 );
                
                if( $answerHash == $info['hash'] ) {
-                       wfDebug( "FancyCaptcha: answer hash matches expected $hash\n" );
+                       wfDebug( "FancyCaptcha: answer hash matches expected {$info['hash']}\n" );
                        return true;
                } else {
                        wfDebug( "FancyCaptcha: answer hashes to $answerHash, expected {$info['hash']}\n" );
@@ -62,7 +62,7 @@ class FancyCaptcha extends SimpleCaptcha {
        /**
         * Insert the captcha prompt into the edit form.
         */
-       function formCallback( &$out ) {
+       function getForm() {
                $info = $this->pickImage();
                if( !$info ) {
                        die( "out of captcha images; this shouldn't happen" );
@@ -77,9 +77,7 @@ class FancyCaptcha extends SimpleCaptcha {
                
                $title = Title::makeTitle( NS_SPECIAL, 'Captcha/image' );
                
-               $out->addWikiText( wfMsg( "captcha-short" ) );
-               
-               $out->addHTML( "<p>" . 
+               return "<p>" . 
                        wfElement( 'img', array(
                                'src'    => $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) ),
                                'width'  => $info['width'],
@@ -96,7 +94,7 @@ class FancyCaptcha extends SimpleCaptcha {
                                'name' => 'wpCaptchaWord',
                                'id'   => 'wpCaptchaWord',
                                'tabindex' => 1 ) ) . // tab in before the edit textarea
-                       "</p>\n" );
+                       "</p>\n";
        }
        
        /**
@@ -106,10 +104,9 @@ class FancyCaptcha extends SimpleCaptcha {
         */
        function pickImage() {
                global $wgCaptchaDirectory;
-               $pick = mt_rand( 0, $this->countFiles( $wgCaptchaDirectory ) );
+               $n = mt_rand( 0, $this->countFiles( $wgCaptchaDirectory ) );
                $dir = opendir( $wgCaptchaDirectory );
                
-               $n = mt_rand( 0, 16 );
                $count = 0;
                
                $entry = readdir( $dir );
@@ -164,7 +161,7 @@ class FancyCaptcha extends SimpleCaptcha {
                        }
                        
                        $info['viewed'] = wfTimestamp();
-                       $this->storeCaptcha( $info, $info['index'] );
+                       $this->storeCaptcha( $info );
                        
                        $salt = $info['salt'];
                        $hash = $info['hash'];