From 96ddd951fb7047607fc7347d18e28588ec974c5c Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 4 Dec 2013 17:28:12 +0100 Subject: [PATCH] generalize BitmapHandler::logErrorForExternalProcess BitmapHandler::logErrorForExternalProcess is a wrapper around wfDebugLog( 'thumbnail' ). It got copy pasted from some other class at one point. This patch move the method up to general class MediaHandler and makes other child class uses it. The method will thus be available to extensions such as TimedMediaHandler. The reason I am doing that is that trim($err) generates a copy of $err which causes a memory allocation fatal error whenever $err is larger than the remaining memory allocatable. The patch will let us fix the bug by only altering one part of the code. bug: 57985 Change-Id: I5657f07d6e2cca05d53f2a5c30ec23622c171343 --- includes/media/Bitmap.php | 13 ------------- includes/media/DjVu.php | 5 +---- includes/media/MediaHandler.php | 17 +++++++++++++++++ includes/media/SVG.php | 4 +--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index 6f7130d456..804393a241 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -495,19 +495,6 @@ class BitmapHandler extends ImageHandler { return false; # No error } - /** - * Log an error that occurred in an external process - * - * @param $retval int - * @param $err int - * @param $cmd string - */ - protected function logErrorForExternalProcess( $retval, $err, $cmd ) { - wfDebugLog( 'thumbnail', - sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"', - wfHostname(), $retval, trim( $err ), $cmd ) ); - } - /** * Get a MediaTransformError with error 'thumbnail_error' * diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index fe3313a4e8..ae46b2e855 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -195,10 +195,7 @@ class DjVuHandler extends ImageHandler { $removed = $this->removeBadFile( $dstPath, $retval ); if ( $retval != 0 || $removed ) { - wfDebugLog( 'thumbnail', - sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"', - wfHostname(), $retval, trim( $err ), $cmd ) ); - + $this->logErrorForExternalProcess( $retval, $err, $cmd ); return new MediaTransformError( 'thumbnail_error', $width, $height, $err ); } else { $params = array( diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php index f55e508cb1..562de13cb2 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -703,4 +703,21 @@ abstract class MediaHandler { public function getRotation( $file ) { return 0; } + + /** + * Log an error that occurred in an external process + * + * Moved from BitmapHandler to MediaHandler with MediaWiki 1.23 + * + * @since 1.23 + * @param $retval int + * @param $err int + * @param $cmd string + */ + protected function logErrorForExternalProcess( $retval, $err, $cmd ) { + wfDebugLog( 'thumbnail', + sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"', + wfHostname(), $retval, trim( $err ), $cmd ) ); + } + } diff --git a/includes/media/SVG.php b/includes/media/SVG.php index d06acd87b1..fef67f8df7 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -208,9 +208,7 @@ class SvgHandler extends ImageHandler { } $removed = $this->removeBadFile( $dstPath, $retval ); if ( $retval != 0 || $removed ) { - wfDebugLog( 'thumbnail', sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"', - wfHostname(), $retval, trim( $err ), $cmd ) ); - + $this->logErrorForExternalProcess( $retval, $err, $cmd ); return new MediaTransformError( 'thumbnail_error', $width, $height, $err ); } -- 2.20.1