From 875a597e7f153d97e54ba3cf42e6ceffd0f2da54 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 21 Dec 2013 19:08:28 -0800 Subject: [PATCH] Move BitmapHandler::canRotate() call out of Setup.php * This was wasting 5ms on every request hit on test wiki Change-Id: Ie7a5aa27593ab8e0d52fb00218345d1789da61a1 --- includes/Setup.php | 7 ------- includes/media/Bitmap.php | 15 +++++++++++++++ includes/media/ExifBitmap.php | 6 ++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/Setup.php b/includes/Setup.php index 17d544665e..531d1a46e3 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -248,13 +248,6 @@ foreach ( $wgForeignFileRepos as &$repo ) { } unset( $repo ); // no global pollution; destroy reference -if ( is_null( $wgEnableAutoRotation ) ) { - wfProfileIn( $fname . '-defaults-rotation' ); - // Only enable auto-rotation when the bitmap handler can rotate - $wgEnableAutoRotation = BitmapHandler::canRotate(); - wfProfileOut( $fname . '-defaults-rotation' ); -} - if ( $wgRCFilterByAge ) { # # Trim down $wgRCLinkDays so that it only lists links which are valid # # as determined by $wgRCMaxAge. diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index eeb8078715..1be04a717b 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -753,6 +753,21 @@ class BitmapHandler extends ImageHandler { } } + /** + * @see $wgEnableAutoRotation + * @return bool Whether auto rotation is enabled + */ + public static function autoRotateEnabled() { + global $wgEnableAutoRotation; + + if ( $wgEnableAutoRotation === null ) { + // Only enable auto-rotation when the bitmap handler can rotate + $wgEnableAutoRotation = BitmapHandler::canRotate(); + } + + return $wgEnableAutoRotation; + } + /** * @param File $file * @param array $params Rotate parameters. diff --git a/includes/media/ExifBitmap.php b/includes/media/ExifBitmap.php index fe037b76f4..4bbafc1af6 100644 --- a/includes/media/ExifBitmap.php +++ b/includes/media/ExifBitmap.php @@ -169,12 +169,11 @@ class ExifBitmapHandler extends BitmapHandler { * @return array */ function getImageSize( $image, $path ) { - global $wgEnableAutoRotation; $gis = parent::getImageSize( $image, $path ); // Don't just call $image->getMetadata(); FSFile::getPropsFromPath() calls us with a bogus object. // This may mean we read EXIF data twice on initial upload. - if ( $wgEnableAutoRotation ) { + if ( BitmapHandler::autoRotateEnabled() ) { $meta = $this->getMetadata( $image, $path ); $rotation = $this->getRotationForExif( $meta ); } else { @@ -203,8 +202,7 @@ class ExifBitmapHandler extends BitmapHandler { * @return int 0, 90, 180 or 270 */ public function getRotation( $file ) { - global $wgEnableAutoRotation; - if ( !$wgEnableAutoRotation ) { + if ( !BitmapHandler::autoRotateEnabled() ) { return 0; } -- 2.20.1