Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/321405

Change subject: Fix MediaTransformError message handling
......................................................................

Fix MediaTransformError message handling

Give access to the raw Message instead of only to the HTML or text in
the RequestContext language.

Pass Message objects instead of strings from calling ->text() as the
parameters of Messages so if the outer Message's language is changed
things get parsed sensibly.

Change-Id: Ibd6c1217b6fed839c888b66e02900f8e21ed3e6b
---
M includes/filerepo/file/File.php
M includes/media/Bitmap.php
M includes/media/DjVu.php
M includes/media/Jpeg.php
M includes/media/MediaTransformOutput.php
M includes/media/SVG.php
M includes/media/TransformationalImageHandler.php
7 files changed, 29 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/05/321405/1

diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php
index c1d5573..9188cd9 100644
--- a/includes/filerepo/file/File.php
+++ b/includes/filerepo/file/File.php
@@ -1018,7 +1018,7 @@
                        return $handler->getTransform( $this, $thumbPath, 
$thumbUrl, $params );
                } else {
                        return new MediaTransformError( 'thumbnail_error',
-                               $params['width'], 0, wfMessage( 
'thumbnail-dest-create' )->text() );
+                               $params['width'], 0, wfMessage( 
'thumbnail-dest-create' ) );
                }
        }
 
diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php
index c86eabd..ac0564d 100644
--- a/includes/media/Bitmap.php
+++ b/includes/media/Bitmap.php
@@ -541,7 +541,7 @@
         * @param array $params Rotate parameters.
         *   'rotation' clockwise rotation in degrees, allowed are multiples of 
90
         * @since 1.21
-        * @return bool
+        * @return bool|MediaTransformError
         */
        public function rotate( $file, $params ) {
                global $wgImageMagickConvertCommand;
diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php
index 18f75ec..a852215 100644
--- a/includes/media/DjVu.php
+++ b/includes/media/DjVu.php
@@ -170,7 +170,7 @@
                                'thumbnail_error',
                                $width,
                                $height,
-                               wfMessage( 'thumbnail_dest_directory' )->text()
+                               wfMessage( 'thumbnail_dest_directory' )
                        );
                }
 
@@ -197,7 +197,7 @@
 
                        return new MediaTransformError( 'thumbnail_error',
                                $params['width'], $params['height'],
-                               wfMessage( 'filemissing' )->text()
+                               wfMessage( 'filemissing' )
                        );
                }
 
diff --git a/includes/media/Jpeg.php b/includes/media/Jpeg.php
index b8b6f6c..6c857a8 100644
--- a/includes/media/Jpeg.php
+++ b/includes/media/Jpeg.php
@@ -130,7 +130,7 @@
         * @param array $params Rotate parameters.
         *    'rotation' clockwise rotation in degrees, allowed are multiples 
of 90
         * @since 1.21
-        * @return bool
+        * @return bool|MediaTransformError
         */
        public function rotate( $file, $params ) {
                global $wgJpegTran;
diff --git a/includes/media/MediaTransformOutput.php 
b/includes/media/MediaTransformOutput.php
index b3a555a..5a4497e 100644
--- a/includes/media/MediaTransformOutput.php
+++ b/includes/media/MediaTransformOutput.php
@@ -439,19 +439,12 @@
  * @ingroup Media
  */
 class MediaTransformError extends MediaTransformOutput {
-       /** @var string HTML formatted version of the error */
-       private $htmlMsg;
-
-       /** @var string Plain text formatted version of the error */
-       private $textMsg;
+       /** @var Message */
+       private $msg;
 
        function __construct( $msg, $width, $height /*, ... */ ) {
                $args = array_slice( func_get_args(), 3 );
-               $htmlArgs = array_map( 'htmlspecialchars', $args );
-               $htmlArgs = array_map( 'nl2br', $htmlArgs );
-
-               $this->htmlMsg = wfMessage( $msg )->rawParams( $htmlArgs 
)->escaped();
-               $this->textMsg = wfMessage( $msg )->rawParams( $htmlArgs 
)->text();
+               $this->msg = wfMessage( $msg )->params( $args );
                $this->width = intval( $width );
                $this->height = intval( $height );
                $this->url = false;
@@ -461,16 +454,20 @@
        function toHtml( $options = [] ) {
                return "<div class=\"MediaTransformError\" style=\"" .
                        "width: {$this->width}px; height: {$this->height}px; 
display:inline-block;\">" .
-                       $this->htmlMsg .
+                       $this->getHtmlMsg() .
                        "</div>";
        }
 
        function toText() {
-               return $this->textMsg;
+               return $this->msg->text();
        }
 
        function getHtmlMsg() {
-               return $this->htmlMsg;
+               return $this->msg->escaped();
+       }
+
+       function getMsg() {
+               return $this->msg;
        }
 
        function isError() {
@@ -488,7 +485,8 @@
                parent::__construct( 'thumbnail_error',
                        max( isset( $params['width'] ) ? $params['width'] : 0, 
120 ),
                        max( isset( $params['height'] ) ? $params['height'] : 
0, 120 ),
-                       wfMessage( 'thumbnail_invalid_params' )->text() );
+                       wfMessage( 'thumbnail_invalid_params' )
+               );
        }
 }
 
@@ -501,14 +499,14 @@
 class TransformTooBigImageAreaError extends MediaTransformError {
        function __construct( $params, $maxImageArea ) {
                $msg = wfMessage( 'thumbnail_toobigimagearea' );
+               $msg->rawParams(
+                       $msg->getLanguage()->formatComputingNumbers( 
$maxImageArea, 1000, "size-$1pixel" )
+               );
 
                parent::__construct( 'thumbnail_error',
                        max( isset( $params['width'] ) ? $params['width'] : 0, 
120 ),
                        max( isset( $params['height'] ) ? $params['height'] : 
0, 120 ),
-                       $msg->rawParams(
-                               $msg->getLanguage()->formatComputingNumbers(
-                                       $maxImageArea, 1000, "size-$1pixel" )
-                               )->text()
-                       );
+                       $msg
+               );
        }
 }
diff --git a/includes/media/SVG.php b/includes/media/SVG.php
index f3b33ac..0cea6d8 100644
--- a/includes/media/SVG.php
+++ b/includes/media/SVG.php
@@ -178,14 +178,14 @@
 
                $metadata = $this->unpackMetadata( $image->getMetadata() );
                if ( isset( $metadata['error'] ) ) { // sanity check
-                       $err = wfMessage( 'svg-long-error', 
$metadata['error']['message'] )->text();
+                       $err = wfMessage( 'svg-long-error', 
$metadata['error']['message'] );
 
                        return new MediaTransformError( 'thumbnail_error', 
$clientWidth, $clientHeight, $err );
                }
 
                if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) ) 
{
                        return new MediaTransformError( 'thumbnail_error', 
$clientWidth, $clientHeight,
-                               wfMessage( 'thumbnail_dest_directory' )->text() 
);
+                               wfMessage( 'thumbnail_dest_directory' ) );
                }
 
                $srcPath = $image->getLocalRefPath();
@@ -196,7 +196,7 @@
 
                        return new MediaTransformError( 'thumbnail_error',
                                $params['width'], $params['height'],
-                               wfMessage( 'filemissing' )->text()
+                               wfMessage( 'filemissing' )
                        );
                }
 
@@ -219,7 +219,7 @@
                                        wfHostname(), $lnPath, $srcPath ) );
                        return new MediaTransformError( 'thumbnail_error',
                                $params['width'], $params['height'],
-                               wfMessage( 'thumbnail-temp-create' )->text()
+                               wfMessage( 'thumbnail-temp-create' )
                        );
                }
 
diff --git a/includes/media/TransformationalImageHandler.php 
b/includes/media/TransformationalImageHandler.php
index e33c27e..60aec45 100644
--- a/includes/media/TransformationalImageHandler.php
+++ b/includes/media/TransformationalImageHandler.php
@@ -217,7 +217,7 @@
 
                        return new MediaTransformError( 'thumbnail_error',
                                $scalerParams['clientWidth'], 
$scalerParams['clientHeight'],
-                               wfMessage( 'filemissing' )->text()
+                               wfMessage( 'filemissing' )
                        );
                }
 
@@ -267,7 +267,7 @@
                        # Thumbnail was zero-byte and had to be removed
                        return new MediaTransformError( 'thumbnail_error',
                                $scalerParams['clientWidth'], 
$scalerParams['clientHeight'],
-                               wfMessage( 'unknown-error' )->text()
+                               wfMessage( 'unknown-error' )
                        );
                } elseif ( $mto ) {
                        return $mto;
@@ -565,7 +565,7 @@
         * @param array $params Rotate parameters.
         *   'rotation' clockwise rotation in degrees, allowed are multiples of 
90
         * @since 1.24 Is non-static. From 1.21 it was static
-        * @return bool
+        * @return bool|MediaTransformError
         */
        public function rotate( $file, $params ) {
                return new MediaTransformError( 'thumbnail_error', 0, 0,

-- 
To view, visit https://gerrit.wikimedia.org/r/321405
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd6c1217b6fed839c888b66e02900f8e21ed3e6b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to