Deferred File::getLocalRef() in BitmapHandler and altered MediaTransformOutput to...
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 1 Feb 2012 04:44:08 +0000 (04:44 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 1 Feb 2012 04:44:08 +0000 (04:44 +0000)
includes/media/Bitmap.php
includes/media/MediaTransformOutput.php

index 604e944..619485c 100644 (file)
@@ -125,7 +125,6 @@ class BitmapHandler extends ImageHandler {
                        'srcWidth' => $image->getWidth(),
                        'srcHeight' => $image->getHeight(),
                        'mimeType' => $image->getMimeType(),
-                       'srcPath' => $image->getLocalRefPath(),
                        'dstPath' => $dstPath,
                        'dstUrl' => $dstUrl,
                );
@@ -163,6 +162,9 @@ class BitmapHandler extends ImageHandler {
                        return $this->getClientScalingThumbnailImage( $image, $scalerParams );
                }
 
+               # Transform functions and binaries need a FS source file
+               $scalerParams['srcPath'] = $image->getLocalRefPath();
+
                # Try a hook
                $mto = null;
                wfRunHooks( 'BitmapHandlerTransform', array( $this, $image, &$scalerParams, &$mto ) );
@@ -248,7 +250,7 @@ class BitmapHandler extends ImageHandler {
         */
        protected function getClientScalingThumbnailImage( $image, $params ) {
                return new ThumbnailImage( $image, $image->getURL(),
-                               $params['clientWidth'], $params['clientHeight'], $params['srcPath'] );
+                       $params['clientWidth'], $params['clientHeight'], null );
        }
 
        /**
index de6b1c0..fcfb2f4 100644 (file)
@@ -86,35 +86,43 @@ abstract class MediaTransformOutput {
        }
 
        /**
-        * Check if an output thumbnail file was actually made.
+        * Check if an output thumbnail file actually exists.
         * This will return false if there was an error, the
-        * thumnail is to be handled client-side only, or if
+        * thumbnail is to be handled client-side only, or if
         * transformation was deferred via TRANSFORM_LATER.
-        *
+        * 
         * @return Bool
         */
        public function hasFile() {
-               // If TRANSFORM_LATER, $this->path will be false
-               return ( !$this->isError() && $this->path );
+               // If TRANSFORM_LATER, $this->path will be false.
+               // Note: a null path means "use the source file".
+               return ( !$this->isError() && ( $this->path || $this->path === null ) );
        }
 
        /**
-        * Check if the output thumbnail file is the same as the source.
+        * Check if the output thumbnail is the same as the source.
         * This can occur if the requested width was bigger than the source.
         *
         * @return Bool
         */
        public function fileIsSource() {
-               return ( !$this->isError() && $this->path === $this->file->getLocalRefPath() );
+               return ( !$this->isError() && $this->path === null );
        }
 
        /**
-        * Get the path of a file system copy of the thumbnail
+        * Get the path of a file system copy of the thumbnail.
+        * Callers should never write to this path.
         *
         * @return string|false Returns false if there isn't one
         */
        public function getLocalCopyPath() {
-               return $this->path;
+               if ( $this->isError() ) {
+                       return false;
+               } elseif ( $this->path === null ) {
+                       return $this->file->getLocalRefPath();
+               } else {
+                       return $this->path; // may return false
+               }
        }
 
        /**
@@ -124,7 +132,7 @@ abstract class MediaTransformOutput {
         * @return Bool success
         */
        public function streamFile( $headers = array() ) {
-               return $this->path && StreamFile::stream( $this->path, $headers );
+               return $this->path && StreamFile::stream( $this->getLocalCopyPath(), $headers );
        }
 
        /**
@@ -170,13 +178,16 @@ abstract class MediaTransformOutput {
  * @ingroup Media
  */
 class ThumbnailImage extends MediaTransformOutput {
-
        /**
+        * Get a thumbnail object from a file and parameters.
+        * If $path is set to null, the output file is treated as a source copy.
+        * If $path is set to false, no output file will be created.
+        * 
         * @param $file File object
         * @param $url String: URL path to the thumb
         * @param $width Integer: file's width
         * @param $height Integer: file's height
-        * @param $path String: filesystem path to the thumb
+        * @param $path String|false|null: filesystem path to the thumb
         * @param $page Integer: page number, for multipage files
         * @private
         */