MediaWiki  1.30.0
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 }
ResourceLoaderFileModule\$skinScripts
array $skinScripts
List of JavaScript files to include when using a specific skin.
Definition: ResourceLoaderFileModule.php:65
ResourceLoaderOOUIFileModule\extendSkinSpecific
extendSkinSpecific(&$skinSpecific, $extraSkinSpecific)
Prepend the $extraSkinSpecific assoc.
Definition: ResourceLoaderOOUIFileModule.php:79
getThemeScriptsPath
getThemeScriptsPath( $theme, $module)
Definition: ResourceLoaderOOUIModule.php:116
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ResourceLoaderFileModule\$skinStyles
array $skinStyles
List of paths to CSS files to include when using specific skins.
Definition: ResourceLoaderFileModule.php:92
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ResourceLoaderFileModule
ResourceLoader module based on local JavaScript/CSS files.
Definition: ResourceLoaderFileModule.php:28
ResourceLoaderOOUIFileModule\getSkinSpecific
getSkinSpecific( $module, $which)
Helper function to generate values for 'skinStyles' and 'skinScripts'.
Definition: ResourceLoaderOOUIFileModule.php:57
getThemeStylesPath
getThemeStylesPath( $theme, $module)
Definition: ResourceLoaderOOUIModule.php:128
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:74
ResourceLoaderOOUIFileModule
ResourceLoaderFileModule which magically loads the right skinScripts and skinStyles for every skin,...
Definition: ResourceLoaderOOUIFileModule.php:27
$options
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:1965
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$skin
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:1965
ResourceLoaderOOUIModule
trait ResourceLoaderOOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins.
Definition: ResourceLoaderOOUIModule.php:26
ResourceLoaderOOUIFileModule\__construct
__construct( $options=[])
Definition: ResourceLoaderOOUIFileModule.php:30