media: Ensure there ie enough data to extract software version
authorSébastien Santoro <dereckson@espace-win.org>
Thu, 12 Oct 2017 23:54:29 +0000 (23:54 +0000)
committerUmherirrender <umherirrender_de.wp@web.de>
Wed, 6 Dec 2017 21:16:17 +0000 (21:16 +0000)
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

includes/media/FormatMetadata.php
tests/phpunit/includes/media/FormatMetadataTest.php

index 6661965..b008a22 100644 (file)
@@ -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 );
                                                }
index e9fc84e..16ae193 100644 (file)
@@ -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' => '<ul class="metadata-langlist">'.
+                                               '<li class="mw-metadata-lang-default">'.
+                                                       '<span class="mw-metadata-lang-value">paint.net 4.0.12</span>'.
+                                               "</li>\n".
+                                       '</ul>'
+                               ],
+                       ],
+                       [
+                               // https://phabricator.wikimedia.org/T178130
+                               // WebMHandler.php turns both 'muxingapp' & 'writingapp' to 'Software'
+                               [ 'Software' => [ [ 'Lavf57.25.100' ], [ 'Lavf57.25.100' ] ] ],
+                               [ 'Software' => "<ul><li>Lavf57.25.100</li>\n<li>Lavf57.25.100</li></ul>" ],
+                       ],
+               ];
+       }
 }