generalize BitmapHandler::logErrorForExternalProcess
authorAntoine Musso <hashar@free.fr>
Wed, 4 Dec 2013 16:28:12 +0000 (17:28 +0100)
committerAntoine Musso <hashar@free.fr>
Fri, 6 Dec 2013 17:21:58 +0000 (18:21 +0100)
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
includes/media/DjVu.php
includes/media/MediaHandler.php
includes/media/SVG.php

index 6f7130d..804393a 100644 (file)
@@ -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'
         *
index fe3313a..ae46b2e 100644 (file)
@@ -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(
index f55e508..562de13 100644 (file)
@@ -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 ) );
+       }
+
 }
index d06acd8..fef67f8 100644 (file)
@@ -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 );
                }