From: Aaron Schulz Date: Wed, 1 Feb 2012 04:44:08 +0000 (+0000) Subject: Deferred File::getLocalRef() in BitmapHandler and altered MediaTransformOutput to... X-Git-Tag: 1.31.0-rc.0~24984 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=436e730336ec5dca641d7c3c094ba563966c6d35;p=lhc%2Fweb%2Fwiklou.git Deferred File::getLocalRef() in BitmapHandler and altered MediaTransformOutput to compensate. They were getting called on every getTransform() call, which are triggered by just looking at pages with files (like Special:ListFiles). This made page loads very slow for non-FS backends. --- diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index 604e94459f..619485ccf2 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -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 ); } /** diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php index de6b1c0525..fcfb2f45b4 100644 --- a/includes/media/MediaTransformOutput.php +++ b/includes/media/MediaTransformOutput.php @@ -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 */