MediaWiki REL1_34
ResourceLoaderOOUIFileModule.php
Go to the documentation of this file.
1<?php
30
31 public function __construct( $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 ) {
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( &$skinSpecific, $extraSkinSpecific ) {
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}
static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
getThemeScriptsPath( $theme, $module)
getThemeStylesPath( $theme, $module)
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.
Module which magically loads the right skinScripts and skinStyles for every skin, using the specified...
extendSkinSpecific(&$skinSpecific, $extraSkinSpecific)
Prepend the $extraSkinSpecific assoc.
getSkinSpecific( $module, $which)
Helper function to generate values for 'skinStyles' and 'skinScripts'.
trait ResourceLoaderOOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42