MediaWiki REL1_30
ResourceLoaderOOUIFileModule.php
Go to the documentation of this file.
1<?php
29
30 public function __construct( $options = [] ) {
31 if ( isset( $options[ 'themeScripts' ] ) ) {
32 $skinScripts = $this->getSkinSpecific( $options[ 'themeScripts' ], 'scripts' );
33 if ( !isset( $options['skinScripts'] ) ) {
34 $options['skinScripts'] = [];
35 }
36 $this->extendSkinSpecific( $options['skinScripts'], $skinScripts );
37 }
38 if ( isset( $options[ 'themeStyles' ] ) ) {
39 $skinStyles = $this->getSkinSpecific( $options[ 'themeStyles' ], 'styles' );
40 if ( !isset( $options['skinStyles'] ) ) {
41 $options['skinStyles'] = [];
42 }
43 $this->extendSkinSpecific( $options['skinStyles'], $skinStyles );
44 }
45
46 parent::__construct( $options );
47 }
48
57 private function getSkinSpecific( $module, $which ) {
58 $themes = self::getSkinThemeMap();
59
60 return array_combine(
61 array_keys( $themes ),
62 array_map( function ( $theme ) use ( $module, $which ) {
63 if ( $which === 'scripts' ) {
64 return $this->getThemeScriptsPath( $theme, $module );
65 } else {
66 return $this->getThemeStylesPath( $theme, $module );
67 }
68 }, array_values( $themes ) )
69 );
70 }
71
79 private function extendSkinSpecific( &$skinSpecific, $extraSkinSpecific ) {
80 // For each skin where skinStyles/skinScripts are defined, add our ones at the beginning
81 foreach ( $skinSpecific as $skin => $files ) {
82 if ( !is_array( $files ) ) {
83 $files = [ $files ];
84 }
85 if ( isset( $extraSkinSpecific[$skin] ) ) {
86 $skinSpecific[$skin] = array_merge( [ $extraSkinSpecific[$skin] ], $files );
87 } elseif ( isset( $extraSkinSpecific['default'] ) ) {
88 $skinSpecific[$skin] = array_merge( [ $extraSkinSpecific['default'] ], $files );
89 }
90 }
91 // Add our remaining skinStyles/skinScripts for skins that did not have them defined
92 foreach ( $extraSkinSpecific as $skin => $file ) {
93 if ( !isset( $skinSpecific[$skin] ) ) {
94 $skinSpecific[$skin] = $file;
95 }
96 }
97 }
98}
static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
trait ResourceLoaderOOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins.
getThemeScriptsPath( $theme, $module)
getThemeStylesPath( $theme, $module)
ResourceLoader module based on local JavaScript/CSS files.
array $skinStyles
List of paths to CSS files to include when using specific skins.
array $skinScripts
List of JavaScript files to include when using a specific skin.
ResourceLoaderFileModule which magically loads the right skinScripts and skinStyles for every skin,...
extendSkinSpecific(&$skinSpecific, $extraSkinSpecific)
Prepend the $extraSkinSpecific assoc.
getSkinSpecific( $module, $which)
Helper function to generate values for 'skinStyles' and 'skinScripts'.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1971
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition hooks.txt:1981