From: Bartosz Dziewoński Date: Thu, 2 Apr 2015 17:54:07 +0000 (+0200) Subject: ResourceLoaderImage: Allow shorthand syntax X-Git-Tag: 1.31.0-rc.0~11839^2 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_add%27%29%20%7D%7D?a=commitdiff_plain;h=a3e6df16903a35590a98b3f071a16f9da75d00e4;p=lhc%2Fweb%2Fwiklou.git ResourceLoaderImage: Allow shorthand syntax array( "en,de,fr" => "foo.svg" ) now means the same as array( "en" => "foo.svg", "de" => "foo.svg", "fr" => "foo.svg" ). Bug: T76539 Change-Id: I0bf82e06be3c5f94b6ac88bbc0437b5229ceb284 --- diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php index d14b7a8901..12d1e8279e 100644 --- a/includes/resourceloader/ResourceLoaderImage.php +++ b/includes/resourceloader/ResourceLoaderImage.php @@ -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; diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php index 841066342d..d0bc210b8f 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php @@ -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', ) ), ) diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php index 404ae9db32..758cfe190a 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderImageTest.php @@ -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' ), );