Merge "ResourceLoaderImage: Allow shorthand syntax"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 6 Apr 2015 06:22:49 +0000 (06:22 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 6 Apr 2015 06:22:49 +0000 (06:22 +0000)
includes/resourceloader/ResourceLoaderImage.php
tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php

index d14b7a8..12d1e82 100644 (file)
@@ -53,6 +53,20 @@ class ResourceLoaderImage {
                $this->basePath = $basePath;
                $this->variants = $variants;
 
+               // Expand shorthands:
+               // array( "en,de,fr" => "foo.svg" ) → array( "en" => "foo.svg", "de" => "foo.svg", "fr" => "foo.svg" )
+               if ( is_array( $this->descriptor ) && isset( $this->descriptor['lang'] ) ) {
+                       foreach ( array_keys( $this->descriptor['lang'] ) as $langList ) {
+                               if ( strpos( $langList, ',' ) !== false ) {
+                                       $this->descriptor['lang'] += array_fill_keys(
+                                               explode( ',', $langList ),
+                                               $this->descriptor['lang'][ $langList ]
+                                       );
+                                       unset( $this->descriptor['lang'][ $langList ] );
+                               }
+                       }
+               }
+
                // Ensure that all files have common extension.
                $extensions = array();
                $descriptor = (array)$descriptor;
index 8410663..d0bc210 100644 (file)
@@ -31,7 +31,7 @@ class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase {
                                'default' => 'bold-a.svg',
                                'lang' => array(
                                        'en' => 'bold-b.svg',
-                                       'de' => 'bold-f.svg',
+                                       'ar,de' => 'bold-f.svg',
                                )
                        ),
                )
index 404ae9d..758cfe1 100644 (file)
@@ -33,6 +33,7 @@ class ResourceLoaderImageTest extends ResourceLoaderTestCase {
                        array( 'help', 'he', 'help-ltr.svg' ),
                        array( 'bold', 'en', 'bold-b.svg' ),
                        array( 'bold', 'de', 'bold-f.svg' ),
+                       array( 'bold', 'ar', 'bold-f.svg' ),
                        array( 'bold', 'fr', 'bold-a.svg' ),
                        array( 'bold', 'he', 'bold-a.svg' ),
                );