MediaWiki  master
CodexModule.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\ResourceLoader;
22 
23 use Config;
24 
32 class CodexModule extends FileModule {
33 
34  protected $dirSpecificStyles = [];
35 
36  public function __construct( array $options = [], $localBasePath = null, $remoteBasePath = null ) {
37  if ( isset( $options['dirSpecificStyles'] ) ) {
38  $this->dirSpecificStyles = $options['dirSpecificStyles'];
39  }
40 
41  parent::__construct( $options, $localBasePath, $remoteBasePath );
42  }
43 
44  public function getStyleFiles( Context $context ) {
45  // Add direction-specific styles
46  $dir = $context->getDirection();
47  if ( isset( $this->dirSpecificStyles[ $dir ] ) ) {
48  $this->styles = array_merge( $this->styles, (array)$this->dirSpecificStyles[ $dir ] );
49  // Empty dirSpecificStyles so we don't add them twice if getStyleFiles() is called twice
50  $this->dirSpecificStyles = [];
51  }
52 
53  return parent::getStyleFiles( $context );
54  }
55 
77  public static function getIcons( Context $context, Config $config, array $iconNames = [] ) {
78  global $IP;
79  static $allIcons = null;
80  if ( $allIcons === null ) {
81  $allIcons = json_decode( file_get_contents( "$IP/resources/lib/codex-icons/codex-icons.json" ), true );
82  }
83  return array_intersect_key( $allIcons, array_flip( $iconNames ) );
84  }
85 }
86 
88 class_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:91
Module for codex that has direction-specific style files and a static helper function for embedding i...
Definition: CodexModule.php:32
getStyleFiles(Context $context)
Get a list of file paths for all styles in this module, in order of proper inclusion.
Definition: CodexModule.php:44
__construct(array $options=[], $localBasePath=null, $remoteBasePath=null)
Definition: CodexModule.php:36
static getIcons(Context $context, Config $config, array $iconNames=[])
Retrieve the specified icon definitions from codex-icons.json.
Definition: CodexModule.php:77
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.
Definition: FileModule.php:53
string $remoteBasePath
Remote base path, see __construct()
Definition: FileModule.php:58
string $localBasePath
Local base path, see __construct()
Definition: FileModule.php:55
Interface for configuration instances.
Definition: Config.php:30