From 3a5762f8e063b1a8cc65bbaf2d61ab1bdbbd45ff Mon Sep 17 00:00:00 2001 From: Russ Nelson Date: Wed, 7 Sep 2011 22:57:05 +0000 Subject: [PATCH] split out the inside of File::transform() to avoid copying all of transform for SwiftMedia --- includes/filerepo/File.php | 76 +++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 891a1e4e7f..cfa9fcb0d9 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -667,6 +667,51 @@ abstract class File { return $thumb->getUrl(); } + /** + * Do the work of a transform (from an original into a thumb). + * Contains filesystem-specific functions. + * + * @param $thumbName string: the name of the thumbnail file. + * @param $thumbUrl string: the URL of the thumbnail file. + * @param $params Array: an associative array of handler-specific parameters. + * Typical keys are width, height and page. + * + * @return MediaTransformOutput | false + */ + protected function maybeDoTransform( $thumbName, $thumbUrl, $params ) { + global $wgIgnoreImageErrors, $wgThumbnailEpoch; + + $thumbPath = $this->getThumbPath( $thumbName ); + if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) { + return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); + } + + wfDebug( __METHOD__.": Doing stat for $thumbPath\n" ); + $this->migrateThumbFile( $thumbName ); + if ( file_exists( $thumbPath )) { + $thumbTime = filemtime( $thumbPath ); + if ( $thumbTime !== FALSE && + gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) { + + return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); + } + } + $thumb = $this->handler->doTransform( $this, $thumbPath, $thumbUrl, $params ); + + // Ignore errors if requested + if ( !$thumb ) { + $thumb = null; + } elseif ( $thumb->isError() ) { + $this->lastError = $thumb->toText(); + if ( $wgIgnoreImageErrors && !($flags & self::RENDER_NOW) ) { + $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); + } + } + + return $thumb; + } + + /** * Transform a media file * @@ -676,7 +721,7 @@ abstract class File { * @return MediaTransformOutput | false */ function transform( $params, $flags = 0 ) { - global $wgUseSquid, $wgIgnoreImageErrors, $wgThumbnailEpoch, $wgServer; + global $wgUseSquid, $wgServer; wfProfileIn( __METHOD__ ); do { @@ -704,36 +749,9 @@ abstract class File { $normalisedParams = $params; $this->handler->normaliseParams( $this, $normalisedParams ); $thumbName = $this->thumbName( $normalisedParams ); - $thumbPath = $this->getThumbPath( $thumbName ); $thumbUrl = $this->getThumbUrl( $thumbName ); - if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) { - $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); - break; - } - - wfDebug( __METHOD__.": Doing stat for $thumbPath\n" ); - $this->migrateThumbFile( $thumbName ); - if ( file_exists( $thumbPath )) { - $thumbTime = filemtime( $thumbPath ); - if ( $thumbTime !== FALSE && - gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) { - - $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); - break; - } - } - $thumb = $this->handler->doTransform( $this, $thumbPath, $thumbUrl, $params ); - - // Ignore errors if requested - if ( !$thumb ) { - $thumb = null; - } elseif ( $thumb->isError() ) { - $this->lastError = $thumb->toText(); - if ( $wgIgnoreImageErrors && !($flags & self::RENDER_NOW) ) { - $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); - } - } + $thumb = $this->maybeDoTransform( $thumbName, $thumbUrl, $params ); // Purge. Useful in the event of Core -> Squid connection failure or squid // purge collisions from elsewhere during failure. Don't keep triggering for -- 2.20.1