Make ResourceLoaderFileModule#getAllStyleFiles include all skin styles
authorSam Smith <git@samsmith.io>
Tue, 1 Apr 2014 14:28:46 +0000 (15:28 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 17 Jun 2014 19:38:58 +0000 (19:38 +0000)
* 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
includes/resourceloader/ResourceLoaderFileModule.php
tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php

index 7258392..72edd76 100644 (file)
@@ -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
index 190801c..3a6d5d2 100644 (file)
@@ -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;
        }
 
        /**
index b25e9b0..fa22d34 100644 (file)
@@ -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