MediaWiki REL1_37
ResourceLoaderOOUIFileModule.php
Go to the documentation of this file.
1<?php
30
32 private $themeStyles = [];
33
34 public function __construct( array $options = [] ) {
35 if ( isset( $options['themeScripts'] ) ) {
36 $skinScripts = $this->getSkinSpecific( $options['themeScripts'], 'scripts' );
37 $options['skinScripts'] = $this->extendSkinSpecific( $options['skinScripts'] ?? [], $skinScripts );
38 }
39 if ( isset( $options['themeStyles'] ) ) {
40 $this->themeStyles = $this->getSkinSpecific( $options['themeStyles'], 'styles' );
41 }
42
43 parent::__construct( $options );
44 }
45
46 public function setSkinStylesOverride( array $moduleSkinStyles ): void {
47 parent::setSkinStylesOverride( $moduleSkinStyles );
48
49 $this->skinStyles = $this->extendSkinSpecific( $this->skinStyles, $this->themeStyles );
50 }
51
60 private function getSkinSpecific( $module, $which ): array {
61 $themes = self::getSkinThemeMap();
62
63 return array_combine(
64 array_keys( $themes ),
65 array_map( function ( $theme ) use ( $module, $which ) {
66 if ( $which === 'scripts' ) {
67 return $this->getThemeScriptsPath( $theme, $module );
68 } else {
69 return $this->getThemeStylesPath( $theme, $module );
70 }
71 }, array_values( $themes ) )
72 );
73 }
74
94 private function extendSkinSpecific( array $skinSpecific, array $themeSpecific ): array {
95 // If the module or skin already set skinStyles/skinScripts, prepend ours
96 foreach ( $skinSpecific as $skin => $files ) {
97 if ( !is_array( $files ) ) {
98 $files = [ $files ];
99 }
100 if ( isset( $themeSpecific[$skin] ) ) {
101 $skinSpecific[$skin] = array_merge( [ $themeSpecific[$skin] ], $files );
102 } elseif ( isset( $themeSpecific['default'] ) ) {
103 $skinSpecific[$skin] = array_merge( [ $themeSpecific['default'] ], $files );
104 }
105 }
106 // If the module has no skinStyles/skinScripts for a skin, then set ours
107 foreach ( $themeSpecific as $skin => $file ) {
108 if ( !isset( $skinSpecific[$skin] ) ) {
109 $skinSpecific[$skin] = [ $file ];
110 }
111 }
112 return $skinSpecific;
113 }
114}
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 $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...
getSkinSpecific( $module, $which)
Helper function to generate values for 'skinStyles' and 'skinScripts'.
array< string, string|ResourceLoaderFilePath > $themeStyles
extendSkinSpecific(array $skinSpecific, array $themeSpecific)
Prepend theme-specific resources on behalf of the skin.
setSkinStylesOverride(array $moduleSkinStyles)
Provide overrides for skinStyles to modules that support that.
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