MediaWiki REL1_40
CodexModule.php
Go to the documentation of this file.
1<?php
22
23use Config;
25
33class CodexModule extends FileModule {
34
35 protected $themeStyles = [];
36 protected $themeStylesAdded = false;
37
38 protected static $builtinSkinThemeMap = [
39 'default' => 'wikimedia-ui'
40 ];
41
42 public function __construct( array $options = [], $localBasePath = null, $remoteBasePath = null ) {
43 if ( isset( $options['themeStyles'] ) ) {
44 $this->themeStyles = $options['themeStyles'];
45 }
46
47 parent::__construct( $options, $localBasePath, $remoteBasePath );
48 }
49
50 public function getStyleFiles( Context $context ) {
51 if ( !$this->themeStylesAdded ) {
52 // Add theme styles
53 $themeMap = static::$builtinSkinThemeMap +
54 ExtensionRegistry::getInstance()->getAttribute( 'SkinCodexThemes' );
55 $theme = $themeMap[ $context->getSkin() ] ?? $themeMap[ 'default' ];
56 $dir = $context->getDirection();
57 $styles = $this->themeStyles[ $theme ][ $dir ];
58 $this->styles = array_merge( $this->styles, (array)$styles );
59 // Remember we added the theme styles so we don't add them twice if getStyleFiles() is called twice
60 $this->themeStylesAdded = true;
61 }
62 return parent::getStyleFiles( $context );
63 }
64
86 public static function getIcons( Context $context, Config $config, array $iconNames = [] ) {
87 global $IP;
88 static $allIcons = null;
89 if ( $allIcons === null ) {
90 $allIcons = json_decode( file_get_contents( "$IP/resources/lib/codex-icons/codex-icons.json" ), true );
91 }
92 return array_intersect_key( $allIcons, array_flip( $iconNames ) );
93 }
94}
95
97class_alias( CodexModule::class, 'ResourceLoaderCodexModule' );
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:93
The Registry loads JSON files, and uses a Processor to extract information from them.
Module for codex that has direction-specific style files and a static helper function for embedding i...
getStyleFiles(Context $context)
Get a list of file paths for all styles in this module, in order of proper inclusion.
__construct(array $options=[], $localBasePath=null, $remoteBasePath=null)
static getIcons(Context $context, Config $config, array $iconNames=[])
Retrieve the specified icon definitions from codex-icons.json.
Context object that contains information about the state of a specific ResourceLoader web request.
Definition Context.php:46
Module based on local JavaScript/CSS files.
string $remoteBasePath
Remote base path, see __construct()
string $localBasePath
Local base path, see __construct()
array< int, string|FilePath > $styles
List of CSS file files to always include.
Interface for configuration instances.
Definition Config.php:30