https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102029

Revision: 102029
Author:   btongminh
Date:     2011-11-04 18:55:17 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Follow-up r101835, basic functionality in SpecialVipsTest. Needs some polishing

Modified Paths:
--------------
    trunk/extensions/VipsScaler/SpecialVipsTest.php
    trunk/extensions/VipsScaler/VipsScaler_body.php

Modified: trunk/extensions/VipsScaler/SpecialVipsTest.php
===================================================================
--- trunk/extensions/VipsScaler/SpecialVipsTest.php     2011-11-04 18:50:39 UTC 
(rev 102028)
+++ trunk/extensions/VipsScaler/SpecialVipsTest.php     2011-11-04 18:55:17 UTC 
(rev 102029)
@@ -75,8 +75,7 @@
                }
 
                $params = array( 'width' => $width );
-               // RENDER_FORCE requires MediaWiki core r101833
-               $thumb = $file->transform( $params, File::RENDER_NOW | 
File::RENDER_FORCE );
+               $thumb = $file->transform( $params );
                if ( !$thumb || $thumb->isError() ) {
                        $this->getOutput()->addWikiMsg( 
'vipsscaler-thumb-error' );
                        return;
@@ -88,6 +87,15 @@
                                'desc-link' => true,
                        ) )
                );
+               
+               $vipsThumbUrl = $this->getTitle()->getLocalUrl( array( 
+                       'file' => $file->getName(),
+                       'thumb' => $file->getHandler()->makeParamString( 
$params )  
+               ) );
+               
+               $this->getOutput()->addHTML(
+                       Html::element( 'img', array( 'src' => $vipsThumbUrl ) ) 
+               );
        }
 
        /**
@@ -98,6 +106,7 @@
                $form->setWrapperLegend( wfMsg( 'vipsscaler-form-legend' ) );
                $form->setSubmitText( wfMsg( 'vipsscaler-form-submit' ) );
                $form->setSubmitCallback( array( __CLASS__, 'processForm' ) );
+               $form->setMethod( 'get' );
 
                // Looks like HTMLForm does not actually show the form if 
submission
                // was correct. So we have to show it again.
@@ -188,6 +197,7 @@
                if ( !$handler->normaliseParams( $file, $params ) ) {
                        return $this->streamError( 500 );
                }
+               
 
                # Get the thumbnail
                if ( is_null( $wgVipsThumbnailerUrl ) ) {
@@ -196,6 +206,7 @@
 
                        $dstPath = VipsCommand::makeTemp( strrchr( 
$file->getName(), '.' ) );
                        $dstUrl = '';
+                       wfDebug( __METHOD__ . ": Creating vips thumbnail at 
$dstPath\n" );
 
                        $scalerParams = array(
                                # The size to which the image will be resized
@@ -220,8 +231,13 @@
 
                        # Call the hook
                        $mto = null;
-                       if ( VipsScaler::onTransform( $handler, $file, $params, 
$mto ) ) {
-                               StreamFile::stream( $dstPath );
+                       VipsScaler::doTransform( $handler, $file, 
$scalerParams, array(), $mto );
+                       if ( $mto && !$mto->isError() ) {
+                               wfDebug( __METHOD__ . ": streaming 
thumbnail...\n" );
+                               
+                               $this->getOutput()->disable();
+                               header( "Content-Type: 
{$scalerParams['mimeType']}" );
+                               readfile( $dstPath );
                        } else {
                                $this->streamError( 500 );
                        }
@@ -239,6 +255,8 @@
                                'file' => $file->getName(),
                                'thumb' => $handler->makeParamString( $params ) 
. '-' . $file->getName()
                        ) );
+                       wfDebug( __METHOD__ . ": Getting vips thumb from remove 
url $url\n" );
+                       
                        $options = array( 'method' => 'GET' );
                        if ( $wgVipsThumbnailerProxy ) {
                                $options['proxy'] = $wgVipsThumbnailerProxy;
@@ -261,7 +279,16 @@
        }
 
        protected function streamError( $code ) {
-
+               $this->getOutput()->disable();
+               
+               if ( $code == 404 ) {
+                       $msg = 'Not Found';
+               } elseif ( $code == 500 ) {
+                       $msg = 'Internal Server Error';
+               }
+               header( "HTTP/1.0 $code $msg" );
+               echo "<h1>$msg</h1>\r\n";
+               
        }
 
 }

Modified: trunk/extensions/VipsScaler/VipsScaler_body.php
===================================================================
--- trunk/extensions/VipsScaler/VipsScaler_body.php     2011-11-04 18:50:39 UTC 
(rev 102028)
+++ trunk/extensions/VipsScaler/VipsScaler_body.php     2011-11-04 18:55:17 UTC 
(rev 102029)
@@ -43,9 +43,26 @@
                # Check $wgVipsConditions
                $options = self::getHandlerOptions( $handler, $file, $params );
                if ( !$options ) {
+                       wfDebug( "...\n" );
                        return true;
                }
 
+               return self::doTransform( $handler, $file, $params, $options, 
$mto );
+       }
+       
+       /**
+        * Performs a transform with VIPS
+        * 
+        * @see VipsScaler::onTransform
+        * 
+        * @param BitmapHandler $handler
+        * @param File $file
+        * @param array $params
+        * @param array $options
+        * @param MediaTransformOutput &$mto
+        * @return bool
+        */
+       public static function doTransform( $handler, $file, $params, $options, 
&$mto ) {
                wfDebug( __METHOD__ . ': scaling ' . $file->getName() . " using 
vips\n" );
 
                $vipsCommands = self::makeCommands( $handler, $file, $params, 
$options );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to