From 0bb3d2a499a37c348eab1df11a6229a2aa19ecf8 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Tue, 1 Apr 2014 15:28:46 +0100 Subject: [PATCH] Make ResourceLoaderFileModule#getAllStyleFiles include all skin styles * Add the ResourceLoaderFileModule#getAllSkinStyleFiles method, which returns all of the skinStyles files for a given module * The LessFileCompilationTest and checkLess.php script, which use the #getAllStyleFile method, now validate all LESS style files Bug: 63343 Change-Id: Ib2eb5761919c648aea4ae58f8d0531799fe7982b --- RELEASE-NOTES-1.24 | 2 + .../ResourceLoaderFileModule.php | 59 ++++++++++++++++--- .../ResourceLoaderModuleTest.php | 46 +++++++++++++++ 3 files changed, 98 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 7258392205..72edd7665d 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -157,6 +157,8 @@ changes to languages because of Bugzilla reports. * The skin autodiscovery mechanism has been deprecated and will be removed in MediaWiki 1.25. See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for migration guide for creators and users of custom skins that relied on it. +* ResourceLoaderFileModule#getAllStyleFiles now returns all style files and all + skin style files used by the module. ==== Renamed classes ==== * CLDRPluralRuleConverter_Expression to CLDRPluralRuleConverterExpression diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 190801c2b0..3a6d5d28dc 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -681,20 +681,61 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { } /** - * Returns all style files used by this module + * Gets a list of file paths for all skin styles in the module used by + * the skin. + * + * @param string $skinName The name of the skin + * @return array A list of file paths collated by media type + */ + protected function getSkinStyleFiles( $skinName ) { + return self::collateFilePathListByOption( + self::tryForKey( $this->skinStyles, $skinName ), + 'media', + 'all' + ); + } + + /** + * Gets a list of file paths for all skin style files in the module, + * for all available skins. + * + * @return array A list of file paths collated by media type + */ + protected function getAllSkinStyleFiles() { + $styleFiles = array(); + $internalSkinNames = array_keys( Skin::getSkinNames() ); + $internalSkinNames[] = 'default'; + + foreach ( $internalSkinNames as $internalSkinName ) { + $styleFiles = array_merge_recursive( + $styleFiles, + $this->getSkinStyleFiles( $internalSkinName ) + ); + } + + return $styleFiles; + } + + /** + * Returns all style files and all skin style files used by this module. + * * @return array */ public function getAllStyleFiles() { - $files = array(); - foreach ( (array)$this->styles as $key => $value ) { - if ( is_array( $value ) ) { - $path = $key; - } else { - $path = $value; + $collatedStyleFiles = array_merge_recursive( + self::collateFilePathListByOption( $this->styles, 'media', 'all' ), + $this->getAllSkinStyleFiles() + ); + + $result = array(); + + foreach ( $collatedStyleFiles as $media => $styleFiles ) { + foreach ( $styleFiles as $styleFile ) { + $result[] = $this->getLocalPath( $styleFile ); } - $files[] = $this->getLocalPath( $path ); } - return $files; + + return $result; } /** diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index b25e9b061a..fa22d34f3d 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -2,6 +2,52 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { + /** + * @covers ResourceLoaderFileModule::getAllSkinStyleFiles + */ + public function testGetAllSkinStyleFiles() { + $context = self::getResourceLoaderContext(); + + $baseParams = array( + 'scripts' => array( + 'foo.js', + 'bar.js', + ), + 'styles' => array( + 'foo.css', + 'bar.css' => array( 'media' => 'print' ), + 'screen.less' => array( 'media' => 'screen' ), + 'screen-query.css' => array( 'media' => 'screen and (min-width: 400px)' ), + ), + 'skinStyles' => array( + 'default' => 'quux-fallback.less', + 'vector' => array( + 'baz-vector.css', + 'quux-vector.less', + ), + ), + 'messages' => array( + 'hello', + 'world', + ), + ); + + $module = new ResourceLoaderFileModule( $baseParams ); + + $this->assertEquals( + array( + 'foo.css', + 'baz-vector.css', + 'quux-vector.less', + 'quux-fallback.less', + 'bar.css', + 'screen.less', + 'screen-query.css', + ), + array_map( 'basename', $module->getAllStyleFiles() ) + ); + } + /** * @covers ResourceLoaderModule::getDefinitionSummary * @covers ResourceLoaderFileModule::getDefinitionSummary -- 2.20.1