MediaWiki  master
ResourceLoaderOOUIFileModule.php
Go to the documentation of this file.
1 <?php
30 
31  public function __construct( array $options = [] ) {
32  if ( isset( $options['themeScripts'] ) ) {
33  $skinScripts = $this->getSkinSpecific( $options['themeScripts'], 'scripts' );
34  if ( !isset( $options['skinScripts'] ) ) {
35  $options['skinScripts'] = [];
36  }
37  $this->extendSkinSpecific( $options['skinScripts'], $skinScripts );
38  }
39  if ( isset( $options['themeStyles'] ) ) {
40  $skinStyles = $this->getSkinSpecific( $options['themeStyles'], 'styles' );
41  if ( !isset( $options['skinStyles'] ) ) {
42  $options['skinStyles'] = [];
43  }
44  $this->extendSkinSpecific( $options['skinStyles'], $skinStyles );
45  }
46 
47  parent::__construct( $options );
48  }
49 
58  private function getSkinSpecific( $module, $which ) : array {
59  $themes = self::getSkinThemeMap();
60 
61  return array_combine(
62  array_keys( $themes ),
63  array_map( function ( $theme ) use ( $module, $which ) {
64  if ( $which === 'scripts' ) {
65  return $this->getThemeScriptsPath( $theme, $module );
66  } else {
67  return $this->getThemeStylesPath( $theme, $module );
68  }
69  }, array_values( $themes ) )
70  );
71  }
72 
80  private function extendSkinSpecific( array &$skinSpecific, array $extraSkinSpecific ) : void {
81  // For each skin where skinStyles/skinScripts are defined, add our ones at the beginning
82  foreach ( $skinSpecific as $skin => $files ) {
83  if ( !is_array( $files ) ) {
84  $files = [ $files ];
85  }
86  if ( isset( $extraSkinSpecific[$skin] ) ) {
87  $skinSpecific[$skin] = array_merge( [ $extraSkinSpecific[$skin] ], $files );
88  } elseif ( isset( $extraSkinSpecific['default'] ) ) {
89  $skinSpecific[$skin] = array_merge( [ $extraSkinSpecific['default'] ], $files );
90  }
91  }
92  // Add our remaining skinStyles/skinScripts for skins that did not have them defined
93  foreach ( $extraSkinSpecific as $skin => $file ) {
94  if ( !isset( $skinSpecific[$skin] ) ) {
95  $skinSpecific[$skin] = $file;
96  }
97  }
98  }
99 }
ResourceLoaderOOUIModule
trait ResourceLoaderOOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins.
Definition: ResourceLoaderOOUIModule.php:27
ResourceLoaderFileModule\$skinScripts
array $skinScripts
List of JavaScript files to include when using a specific skin.
Definition: ResourceLoaderFileModule.php:74
getThemeScriptsPath
getThemeScriptsPath( $theme, $module)
Definition: ResourceLoaderOOUIModule.php:146
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
ResourceLoaderFileModule\$skinStyles
array $skinStyles
List of paths to CSS files to include when using specific skins.
Definition: ResourceLoaderFileModule.php:101
ResourceLoaderFileModule
Module based on local JavaScript/CSS files.
Definition: ResourceLoaderFileModule.php:39
ResourceLoaderOOUIFileModule\getSkinSpecific
getSkinSpecific( $module, $which)
Helper function to generate values for 'skinStyles' and 'skinScripts'.
Definition: ResourceLoaderOOUIFileModule.php:58
getThemeStylesPath
getThemeStylesPath( $theme, $module)
Definition: ResourceLoaderOOUIModule.php:158
ResourceLoaderOOUIFileModule\__construct
__construct(array $options=[])
Definition: ResourceLoaderOOUIFileModule.php:31
getSkinThemeMap
static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
Definition: ResourceLoaderOOUIModule.php:76
ResourceLoaderOOUIFileModule
Module which magically loads the right skinScripts and skinStyles for every skin, using the specified...
Definition: ResourceLoaderOOUIFileModule.php:28
ResourceLoaderOOUIFileModule\extendSkinSpecific
extendSkinSpecific(array &$skinSpecific, array $extraSkinSpecific)
Prepend the $extraSkinSpecific assoc.
Definition: ResourceLoaderOOUIFileModule.php:80