]> ToastFreeware Gitweb - toast/cookiecaptcha.git/blobdiff - FancyCaptcha.class.php
(bug 16025) 'Call to undefined method SimpleCaptcha::showImage()'
[toast/cookiecaptcha.git] / FancyCaptcha.class.php
index fa968202b3a4f4156924ae5cacfd70d410edade4..0128417c09694ed87ecc5ae7a77986ad0989a2ec 100644 (file)
@@ -24,6 +24,20 @@ class FancyCaptcha extends SimpleCaptcha {
                }
        }
 
+       function addCaptchaAPI(&$resultArr) {
+               $info = $this->pickImage();
+               if( !$info ) {
+                       $resultArr['captcha']['error'] = 'Out of images';
+                       return;
+               }
+               $index = $this->storeCaptcha( $info );
+               $title = Title::makeTitle( NS_SPECIAL, 'Captcha/image' );
+               $resultArr['captcha']['type'] = 'image';
+               $resultArr['captcha']['mime'] = 'image/png';
+               $resultArr['captcha']['id'] = $index;
+               $resultArr['captcha']['url'] = $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) );             
+       }
+
        /**
         * Insert the captcha prompt into the edit form.
         */
@@ -43,19 +57,19 @@ class FancyCaptcha extends SimpleCaptcha {
                $title = Title::makeTitle( NS_SPECIAL, 'Captcha/image' );
 
                return "<p>" .
-                       wfElement( 'img', array(
+                       Xml::element( 'img', array(
                                'src'    => $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) ),
                                'width'  => $info['width'],
                                'height' => $info['height'],
                                'alt'    => '' ) ) .
                        "</p>\n" .
-                       wfElement( 'input', array(
+                       Xml::element( 'input', array(
                                'type'  => 'hidden',
                                'name'  => 'wpCaptchaId',
                                'id'    => 'wpCaptchaId',
                                'value' => $index ) ) .
                        "<p>" .
-                       wfElement( 'input', array(
+                       Xml::element( 'input', array(
                                'name' => 'wpCaptchaWord',
                                'id'   => 'wpCaptchaWord',
                                'tabindex' => 1 ) ) . // tab in before the edit textarea
@@ -158,10 +172,15 @@ class FancyCaptcha extends SimpleCaptcha {
 
                $info = $this->retrieveCaptcha();
                if( $info ) {
+                       /*
+                       // Be a little less restrictive for now; in at least some circumstances,
+                       // Konqueror tries to reload the image even if you haven't navigated
+                       // away from the page.
                        if( $info['viewed'] ) {
                                wfHttpError( 403, 'Access Forbidden', "Can't view captcha image a second time." );
                                return false;
                        }
+                       */
 
                        $info['viewed'] = wfTimestamp();
                        $this->storeCaptcha( $info );
@@ -173,6 +192,7 @@ class FancyCaptcha extends SimpleCaptcha {
                        if( file_exists( $file ) ) {
                                global $IP;
                                require_once "$IP/includes/StreamFile.php";
+                               header( "Cache-Control: private, s-maxage=0, max-age=3600" );
                                wfStreamFile( $file );
                                return true;
                        }