diff options
author | Derk-Jan Hartman <hartman.wiki@gmail.com> | 2023-02-09 21:32:15 +0100 |
---|---|---|
committer | Krinkle <krinkle@fastmail.com> | 2023-02-10 00:22:20 +0000 |
commit | 8ed1cf88aa61e6bfa6baabebc8a34aebec3ee105 (patch) | |
tree | 3235f3c32e1a1308375068cd3522da39d75cd66a /includes/media | |
parent | c4070cbb5603c14fb8c08cc957c35e8450ef8575 (diff) | |
download | mediawikicore-8ed1cf88aa61e6bfa6baabebc8a34aebec3ee105.tar.gz mediawikicore-8ed1cf88aa61e6bfa6baabebc8a34aebec3ee105.zip |
media: Remove unneeded complexity in BitmapHandler command replacement
Bug: T308394
Change-Id: I207b24473e761ac3fdd53d002ba8ce44f4d2dac3
Diffstat (limited to 'includes/media')
-rw-r--r-- | includes/media/BitmapHandler.php | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/includes/media/BitmapHandler.php b/includes/media/BitmapHandler.php index 057464be58b7..67c30b1697a6 100644 --- a/includes/media/BitmapHandler.php +++ b/includes/media/BitmapHandler.php @@ -388,23 +388,20 @@ class BitmapHandler extends TransformationalImageHandler { ->get( MainConfigNames::CustomConvertCommand ); // Variables: %s %d %w %h - $matchLookupTable = [ - '%d' => Shell::escape( $params['dstPath'] ), - '%s' => Shell::escape( $params['srcPath'] ), - '%w' => Shell::escape( $params['physicalWidth'] ), - '%h' => Shell::escape( $params['physicalHeight'] ), - ]; + $src = Shell::escape( $params['srcPath'] ); + $dst = Shell::escape( $params['dstPath'] ); + $w = Shell::escape( $params['physicalWidth'] ); + $h = Shell::escape( $params['physicalHeight'] ); // Find all variables in the original command at once, // so that replacement values cannot inject variable placeholders $cmd = preg_replace_callback( '/%[dswh]/', - static function ( $m ) use ( &$matchLookupTable ) { - if ( !isset( $matchLookupTable[$m[0]] ) ) { - return $m[0]; - } - // We only want to replace each of the variables once - $replacement = $matchLookupTable[$m[0]]; - unset( $matchLookupTable[$m[0]] ); - return $replacement; + static function ( $m ) use ( $src, $dst, $w, $h ) { + return [ + '%s' => $src, + '%d' => $dst, + '%w' => $w, + '%h' => $h, + ][$m[0]]; }, $customConvertCommand ); |