From: Sébastien Santoro Date: Thu, 12 Oct 2017 23:54:29 +0000 (+0000) Subject: media: Ensure there ie enough data to extract software version X-Git-Tag: 1.31.0-rc.0~1267 X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=241e741377818c2c16c930d26ceaf61dff607056 media: Ensure there ie enough data to extract software version The Software EXIF / other metadata field was expected to contain the software name followed by the version number. There are occurences in Wikimedia production logs of errors showing that's not always the case. Bug: T178130 Change-Id: I4187a41b5fd8d7b5574ab50523668d8feb11bccc --- diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index 666196585a..b008a22688 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -740,8 +740,13 @@ class FormatMetadata extends ContextSource { case 'Software': if ( is_array( $val ) ) { - // if its a software, version array. - $val = $this->msg( 'exif-software-version-value', $val[0], $val[1] )->text(); + if ( count( $val ) > 1 ) { + // if its a software, version array. + $val = $this->msg( 'exif-software-version-value', $val[0], $val[1] )->text(); + } else { + // https://phabricator.wikimedia.org/T178130 + $val = $this->exifMsg( $tag, '', $val[0] ); + } } else { $val = $this->exifMsg( $tag, '', $val ); } diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php index e9fc84e77b..16ae1937b3 100644 --- a/tests/phpunit/includes/media/FormatMetadataTest.php +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -95,4 +95,50 @@ class FormatMetadataTest extends MediaWikiMediaTestCase { ], ]; } + + /** + * @param mixed $input + * @param mixed $output + * @dataProvider provideGetFormattedData + * @covers FormatMetadata::getFormattedData + */ + public function testGetFormattedData( $input, $output ) { + $this->assertEquals( $output, FormatMetadata::getFormattedData( $input ) ); + } + + public function provideGetFormattedData() { + return [ + [ + [ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ], + [ 'Software' => 'Adobe Photoshop CS6 (Macintosh)' ], + ], + [ + [ 'Software' => [ 'FotoWare FotoStation' ] ], + [ 'Software' => 'FotoWare FotoStation' ], + ], + [ + [ 'Software' => [ [ 'Capture One PRO', '3.7.7' ] ] ], + [ 'Software' => 'Capture One PRO (Version 3.7.7)' ], + ], + [ + [ 'Software' => [ [ 'FotoWare ColorFactory', '' ] ] ], + [ 'Software' => 'FotoWare ColorFactory (Version )' ], + ], + [ + [ 'Software' => [ 'x-default' => 'paint.net 4.0.12', '_type' => 'lang' ] ], + [ 'Software' => '' + ], + ], + [ + // https://phabricator.wikimedia.org/T178130 + // WebMHandler.php turns both 'muxingapp' & 'writingapp' to 'Software' + [ 'Software' => [ [ 'Lavf57.25.100' ], [ 'Lavf57.25.100' ] ] ], + [ 'Software' => "" ], + ], + ]; + } }