MediaWiki  master
ResourceLoaderFileModule Class Reference

ResourceLoader module based on local JavaScript/CSS files. More...

Inheritance diagram for ResourceLoaderFileModule:
Collaboration diagram for ResourceLoaderFileModule:

Public Member Functions

 __construct ( $options=[], $localBasePath=null, $remoteBasePath=null)
 Constructs a new module from an options array. More...
 
 enableModuleContentVersion ()
 Disable module content versioning. More...
 
 getAllStyleFiles ()
 Returns all style files and all skin style files used by this module. More...
 
 getDefinitionSummary (ResourceLoaderContext $context)
 Get the definition summary for this module. More...
 
 getDependencies (ResourceLoaderContext $context=null)
 Gets list of names of modules this module depends on. More...
 
 getFlip ( $context)
 Get whether CSS for this module should be flipped. More...
 
 getGroup ()
 Gets the name of the group this module should be loaded in. More...
 
 getMessages ()
 Gets list of message keys used by this module. More...
 
 getPackageFiles (ResourceLoaderContext $context)
 Resolves the package files defintion and generates the content of each package file. More...
 
 getScript (ResourceLoaderContext $context)
 Gets all scripts for a given context concatenated together. More...
 
 getScriptURLsForDebug (ResourceLoaderContext $context)
 
 getSkipFunction ()
 Get the skip function. More...
 
 getStyleFiles (ResourceLoaderContext $context)
 Get a list of file paths for all styles in this module, in order of proper inclusion. More...
 
 getStyles (ResourceLoaderContext $context)
 Get all styles for a given context. More...
 
 getStyleSheetLang ( $path)
 Infer the stylesheet language from a stylesheet file path. More...
 
 getStyleURLsForDebug (ResourceLoaderContext $context)
 
 getTargets ()
 Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile']. More...
 
 getTemplates ()
 Takes named templates by the module and returns an array mapping. More...
 
 getType ()
 Get the module's load type. More...
 
 readStyleFiles (array $styles, $flip, $context)
 Get the contents of a list of CSS files. More...
 
 supportsURLLoading ()
 
- Public Member Functions inherited from ResourceLoaderModule
 enableModuleContentVersion ()
 Whether to generate version hash based on module content. More...
 
 getConfig ()
 
 getDefinitionSummary (ResourceLoaderContext $context)
 Get the definition summary for this module. More...
 
 getDependencies (ResourceLoaderContext $context=null)
 Get a list of modules this module depends on. More...
 
 getDeprecationInformation ()
 Get JS representing deprecation information for the current module if available. More...
 
 getFlip ( $context)
 
 getGroup ()
 Get the group this module is in. More...
 
 getHeaders (ResourceLoaderContext $context)
 Get headers to send as part of a module web response. More...
 
 getMessages ()
 Get the messages needed for this module. More...
 
 getModuleContent (ResourceLoaderContext $context)
 Get an array of this module's resources. More...
 
 getName ()
 Get this module's name. More...
 
 getOrigin ()
 Get this module's origin. More...
 
 getScript (ResourceLoaderContext $context)
 Get all JS for this module for a given language and skin. More...
 
 getScriptURLsForDebug (ResourceLoaderContext $context)
 Get the URL or URLs to load for this module's JS in debug mode. More...
 
 getSkipFunction ()
 Get the skip function. More...
 
 getSource ()
 Get the source of this module. More...
 
 getStyles (ResourceLoaderContext $context)
 Get all CSS for this module for a given skin. More...
 
 getStyleURLsForDebug (ResourceLoaderContext $context)
 Get the URL or URLs to load for this module's CSS in debug mode. More...
 
 getTargets ()
 Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile']. More...
 
 getTemplates ()
 Takes named templates by the module and returns an array mapping. More...
 
 getType ()
 Get the module's load type. More...
 
 getVersionHash (ResourceLoaderContext $context)
 Get a string identifying the current version of this module in a given context. More...
 
 isKnownEmpty (ResourceLoaderContext $context)
 Check whether this module is known to be empty. More...
 
 setConfig (Config $config)
 
 setFileDependencies (ResourceLoaderContext $context, $files)
 Set in-object cache for file dependencies. More...
 
 setLogger (LoggerInterface $logger)
 
 setMessageBlob ( $blob, $lang)
 Set in-object cache for message blobs. More...
 
 setName ( $name)
 Set this module's name. More...
 
 shouldEmbedModule (ResourceLoaderContext $context)
 Check whether this module should be embeded rather than linked. More...
 
 supportsURLLoading ()
 Whether this module supports URL loading. More...
 

Static Public Member Functions

static extractBasePaths ( $options=[], $localBasePath=null, $remoteBasePath=null)
 Extract a pair of local and remote base paths from module definition information. More...
 
static getPackageFileType ( $path)
 Infer the file type from a package file path. More...
 
- Static Public Member Functions inherited from ResourceLoaderModule
static expandRelativePaths (array $filePaths)
 Expand directories relative to $IP. More...
 
static getRelativePaths (array $filePaths)
 Make file paths relative to MediaWiki directory. More...
 
static getVary (ResourceLoaderContext $context)
 Get vary string. More...
 

Protected Member Functions

 compileLessFile ( $fileName, ResourceLoaderContext $context)
 Compile a LESS file into CSS. More...
 
 getAllSkinStyleFiles ()
 Gets a list of file paths for all skin style files in the module, for all available skins. More...
 
 getLocalPath ( $path)
 
 getPath ( $path)
 
 getRemotePath ( $path)
 
 getSkinStyleFiles ( $skinName)
 Gets a list of file paths for all skin styles in the module used by the skin. More...
 
 readStyleFile ( $path, $flip, $context)
 Reads a style file. More...
 
 stripBom ( $input)
 Takes an input string and removes the UTF-8 BOM character if present. More...
 
- Protected Member Functions inherited from ResourceLoaderModule
 buildContent (ResourceLoaderContext $context)
 Bundle all resources attached to this module into an array. More...
 
 getFileDependencies (ResourceLoaderContext $context)
 Get the files this module depends on indirectly for a given skin. More...
 
 getLessVars (ResourceLoaderContext $context)
 Get module-specific LESS variables, if any. More...
 
 getLogger ()
 
 getMessageBlob (ResourceLoaderContext $context)
 Get the hash of the message blob. More...
 
 getPreloadLinks (ResourceLoaderContext $context)
 Get a list of resources that web browsers may preload. More...
 
 saveFileDependencies (ResourceLoaderContext $context, $localFileRefs)
 Set the files this module depends on indirectly for a given skin. More...
 
 validateScriptFile ( $fileName, $contents)
 Validate a given script file; if valid returns the original source. More...
 

Static Protected Member Functions

static collateFilePathListByOption (array $list, $option, $default)
 Collates file paths by option (where provided). More...
 
static tryForKey (array $list, $key, $fallback=null)
 Get a list of element that match a key, optionally using a fallback key. More...
 
- Static Protected Member Functions inherited from ResourceLoaderModule
static javaScriptParser ()
 
static safeFileHash ( $filePath)
 Compute a non-cryptographic string hash of a file's contents. More...
 
static safeFilemtime ( $filePath)
 Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist. More...
 

Protected Attributes

bool $debugRaw = true
 Link to raw files in debug mode. More...
 
array $debugScripts = []
 List of paths to JavaScript files to include in debug mode. More...
 
array $dependencies = []
 List of modules this module depends on. More...
 
string $group
 Name of group to load this module in. More...
 
bool $hasGeneratedStyles = false
 Whether getStyleURLsForDebug should return raw file paths, or return load.php urls. More...
 
array $languageScripts = []
 List of JavaScript files to include when using a specific language. More...
 
string $localBasePath = ''
 Local base path, see __construct() More...
 
array $localFileRefs = []
 Place where readStyleFile() tracks file dependencies. More...
 
array $messages = []
 List of message keys used by this module. More...
 
array $missingLocalFileRefs = []
 Place where readStyleFile() tracks file dependencies for non-existent files. More...
 
bool $noflip = false
 Whether CSSJanus flipping should be skipped for this module. More...
 
array $packageFiles = null
 List of packaged files to make available through require() More...
 
string $remoteBasePath = ''
 Remote base path, see __construct() More...
 
array $scripts = []
 List of paths to JavaScript files to always include. More...
 
array $skinScripts = []
 List of JavaScript files to include when using a specific skin. More...
 
array $skinStyles = []
 List of paths to CSS files to include when using specific skins. More...
 
string $skipFunction = null
 File name containing the body of the skip function. More...
 
array $styles = []
 List of paths to CSS files to always include. More...
 
 $targets = [ 'desktop' ]
 
array $templates = []
 Saves a list of the templates named by the modules. More...
 
- Protected Attributes inherited from ResourceLoaderModule
Config $config
 
 $contents = []
 
array bool $deprecated = false
 
 $fileDeps = []
 
LoggerInterface $logger
 
 $msgBlobs = []
 
 $name = null
 
 $origin = self::ORIGIN_CORE_SITEWIDE
 
 $targets = [ 'desktop' ]
 
 $versionHash = []
 

Private Member Functions

 expandPackageFiles (ResourceLoaderContext $context)
 Internal helper for use by getPackageFiles(), getFileHashes() and getDefinitionSummary(). More...
 
 getFileHashes (ResourceLoaderContext $context)
 Helper method for getDefinitionSummary. More...
 
 getLanguageScripts ( $lang)
 Get the set of language scripts for the given language, possibly using a fallback language. More...
 
 getScriptFiles (ResourceLoaderContext $context)
 Get a list of script file paths for this module, in order of proper execution. More...
 
 readScriptFiles (array $scripts)
 Get the contents of a list of JavaScript files. More...
 

Private Attributes

array $expandedPackageFiles = []
 Expanded versions of $packageFiles, lazy-computed by expandPackageFiles(); keyed by context hash. More...
 

Additional Inherited Members

- Public Attributes inherited from ResourceLoaderModule
const LOAD_GENERAL = 'general'
 
const LOAD_STYLES = 'styles'
 
const ORIGIN_ALL = 10
 
const ORIGIN_CORE_INDIVIDUAL = 2
 
const ORIGIN_CORE_SITEWIDE = 1
 
const ORIGIN_USER_INDIVIDUAL = 4
 
const ORIGIN_USER_SITEWIDE = 3
 
const TYPE_COMBINED = 'combined'
 
const TYPE_SCRIPTS = 'scripts'
 
const TYPE_STYLES = 'styles'
 

Detailed Description

ResourceLoader module based on local JavaScript/CSS files.

The following public methods can query the database:

Definition at line 34 of file ResourceLoaderFileModule.php.

Constructor & Destructor Documentation

◆ __construct()

ResourceLoaderFileModule::__construct (   $options = [],
  $localBasePath = null,
  $remoteBasePath = null 
)

Constructs a new module from an options array.

Parameters
array$optionsList of options; if not given or empty, an empty module will be constructed
string | null$localBasePathBase path to prepend to all local paths in $options. Defaults to $IP
string | null$remoteBasePathBase path to prepend to all remote paths in $options. Defaults to $wgResourceBasePath

Below is a description for the $options array:

Exceptions
InvalidArgumentException
Construction options:
[
// Base path to prepend to all local paths in $options. Defaults to $IP
'localBasePath' => [base path],
// Base path to prepend to all remote paths in $options. Defaults to $wgResourceBasePath
'remoteBasePath' => [base path],
// Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath
'remoteExtPath' => [base path],
// Equivalent of remoteBasePath, but relative to $wgStylePath
'remoteSkinPath' => [base path],
// Scripts to always include (cannot be set if 'packageFiles' is also set, see below)
'scripts' => [file path string or array of file path strings],
// Scripts to include in specific language contexts
'languageScripts' => [
[language code] => [file path string or array of file path strings],
],
// Scripts to include in specific skin contexts
'skinScripts' => [
[skin name] => [file path string or array of file path strings],
],
// Scripts to include in debug contexts
'debugScripts' => [file path string or array of file path strings],
// For package modules: files to be made available for internal require() do not
// need to have 'type' defined; it will be inferred from the file name extension
// if omitted. 'config' can only be used when 'type' is 'data'; the variables are
// resolved with Config::get(). The first entry in 'packageFiles' is always the
// module entry point. If 'packageFiles' is set, 'scripts' cannot also be set.
'packageFiles' => [
[file path string], // or:
[ 'name' => [file name], 'file' => [file path], 'type' => 'script'|'data' ], // or:
[ 'name' => [name], 'content' => [string], 'type' => 'script'|'data' ], // or:
[ 'name' => [name], 'callback' => [callable], 'type' => 'script'|'data' ],
[ 'name' => [name], 'config' => [ [config var name], ... ], 'type' => 'data' ],
[ 'name' => [name], 'config' => [ [JS name] => [PHP name] ], 'type' => 'data' ],
],
// Modules which must be loaded before this module
'dependencies' => [module name string or array of module name strings],
'templates' => [
[template alias with file.ext] => [file path to a template file],
],
// Styles to always load
'styles' => [file path string or array of file path strings],
// Styles to include in specific skin contexts
'skinStyles' => [
[skin name] => [file path string or array of file path strings],
],
// Messages to always load
'messages' => [array of message key strings],
// Group which this module should be loaded together with
'group' => [group name string],
// Function that, if it returns true, makes the loader skip this module.
// The file must contain valid JavaScript for execution in a private function.
// The file must not contain the "function () {" and "}" wrapper though.
'skipFunction' => [file path]
]

Definition at line 239 of file ResourceLoaderFileModule.php.

References $options, $value, as, getPath(), list, and string.

Member Function Documentation

◆ collateFilePathListByOption()

static ResourceLoaderFileModule::collateFilePathListByOption ( array  $list,
  $option,
  $default 
)
staticprotected

Collates file paths by option (where provided).

Parameters
array$listList of file paths in any combination of index/path or path/options pairs
string$optionOption name
mixed$defaultDefault value if the option isn't set
Returns
array List of file paths, collated by $option

Definition at line 714 of file ResourceLoaderFileModule.php.

References $value, and as.

◆ compileLessFile()

ResourceLoaderFileModule::compileLessFile (   $fileName,
ResourceLoaderContext  $context 
)
protected

Compile a LESS file into CSS.

Keeps track of all used files and adds them to localFileRefs.

Since
1.22
1.27 Added $context paramter.
Exceptions
ExceptionIf less.php encounters a parse error
Parameters
string$fileNameFile path of LESS source
ResourceLoaderContext$contextContext in which to generate script
Returns
string CSS source

Definition at line 1023 of file ResourceLoaderFileModule.php.

References $cache, $css, $vars, CACHE_ANYTHING, FileContentsHasher\getFileContentsHash(), ResourceLoaderModule\getLessVars(), ObjectCache\getLocalServerInstance(), ResourceLoaderContext\getResourceLoader(), and serialize().

Referenced by readStyleFile().

◆ enableModuleContentVersion()

ResourceLoaderFileModule::enableModuleContentVersion ( )

Disable module content versioning.

This class uses getDefinitionSummary() instead, to avoid filesystem overhead involved with building the full module content inside a startup request.

Returns
bool

Definition at line 520 of file ResourceLoaderFileModule.php.

◆ expandPackageFiles()

ResourceLoaderFileModule::expandPackageFiles ( ResourceLoaderContext  $context)
private

Internal helper for use by getPackageFiles(), getFileHashes() and getDefinitionSummary().

This expands the 'packageFiles' definition into something that's (almost) the right format for getPackageFiles() to return. It expands shorthands, resolves config vars, and handles summarising any non-file data for getVersionHash(). For file-based data, getFileHashes() handles it instead, which also ends up in getDefinitionSummary().

What it does not do is reading the actual contents of any specified files, nor invoking the computation callbacks. Those things are done by getPackageFiles() instead to improve backend performance by only doing this work when the module response is needed, and not when merely computing the version hash for StartupModule, or when checking If-None-Match headers for a HTTP 304 response.

Parameters
ResourceLoaderContext$context
Returns
array|null
Exceptions
MWExceptionIf the 'packageFiles' definition is invalid.

Definition at line 1108 of file ResourceLoaderFileModule.php.

References $file, $path, $type, as, ResourceLoaderModule\getConfig(), ResourceLoaderContext\getHash(), null, and wfDebugLog().

Referenced by getDefinitionSummary(), getFileHashes(), and getPackageFiles().

◆ extractBasePaths()

static ResourceLoaderFileModule::extractBasePaths (   $options = [],
  $localBasePath = null,
  $remoteBasePath = null 
)
static

Extract a pair of local and remote base paths from module definition information.

Implementation note: the amount of global state used in this function is staggering.

Parameters
array$optionsModule definition
string | null$localBasePathPath to use if not provided in module definition. Defaults to $IP
string | null$remoteBasePathPath to use if not provided in module definition. Defaults to $wgResourceBasePath
Returns
array [ localBasePath, remoteBasePath ]

Definition at line 341 of file ResourceLoaderFileModule.php.

References $IP, $localBasePath, $options, $remoteBasePath, $wgExtensionAssetsPath, $wgResourceBasePath, $wgStylePath, null, and string.

Referenced by getThemePaths(), and ResourceLoader\register().

◆ getAllSkinStyleFiles()

ResourceLoaderFileModule::getAllSkinStyleFiles ( )
protected

Gets a list of file paths for all skin style files in the module, for all available skins.

Returns
array A list of file paths collated by media type

Definition at line 839 of file ResourceLoaderFileModule.php.

References as, Skin\getSkinNames(), and getSkinStyleFiles().

Referenced by getAllStyleFiles().

◆ getAllStyleFiles()

ResourceLoaderFileModule::getAllStyleFiles ( )

Returns all style files and all skin style files used by this module.

Returns
array

Definition at line 859 of file ResourceLoaderFileModule.php.

References as, getAllSkinStyleFiles(), and getLocalPath().

◆ getDefinitionSummary()

ResourceLoaderFileModule::getDefinitionSummary ( ResourceLoaderContext  $context)

Get the definition summary for this module.

Parameters
ResourceLoaderContext$context
Returns
array

Definition at line 590 of file ResourceLoaderFileModule.php.

References $options, $packageFiles, as, expandPackageFiles(), getFileHashes(), ResourceLoaderModule\getLessVars(), ResourceLoaderModule\getMessageBlob(), and null.

◆ getDependencies()

ResourceLoaderFileModule::getDependencies ( ResourceLoaderContext  $context = null)

Gets list of names of modules this module depends on.

Parameters
ResourceLoaderContext | null$context
Returns
array List of module names

Definition at line 490 of file ResourceLoaderFileModule.php.

References $dependencies.

◆ getFileHashes()

◆ getFlip()

ResourceLoaderFileModule::getFlip (   $context)

Get whether CSS for this module should be flipped.

Parameters
ResourceLoaderContext$context
Returns
bool

Definition at line 977 of file ResourceLoaderFileModule.php.

References $context, and $noflip.

Referenced by getStyles().

◆ getGroup()

ResourceLoaderFileModule::getGroup ( )

Gets the name of the group this module should be loaded in.

Returns
string Group name

Definition at line 481 of file ResourceLoaderFileModule.php.

References $group.

◆ getLanguageScripts()

ResourceLoaderFileModule::getLanguageScripts (   $lang)
private

Get the set of language scripts for the given language, possibly using a fallback language.

Parameters
string$lang
Returns
array

Definition at line 782 of file ResourceLoaderFileModule.php.

References $lang, $scripts, as, and Language\getFallbacksFor().

Referenced by getFileHashes(), and getScriptFiles().

◆ getLocalPath()

ResourceLoaderFileModule::getLocalPath (   $path)
protected
Parameters
string | ResourceLoaderFilePath$path
Returns
string

Definition at line 662 of file ResourceLoaderFileModule.php.

References $path.

Referenced by getAllStyleFiles(), getPackageFiles(), getSkipFunction(), getTemplates(), readScriptFiles(), and readStyleFile().

◆ getMessages()

ResourceLoaderFileModule::getMessages ( )

Gets list of message keys used by this module.

Returns
array List of message keys

Definition at line 472 of file ResourceLoaderFileModule.php.

References $messages.

◆ getPackageFiles()

ResourceLoaderFileModule::getPackageFiles ( ResourceLoaderContext  $context)

Resolves the package files defintion and generates the content of each package file.

Parameters
ResourceLoaderContext$context
Returns
array Package files data structure, see ResourceLoaderModule::getScript()

Definition at line 1219 of file ResourceLoaderFileModule.php.

References $content, $expandedPackageFiles, as, expandPackageFiles(), ResourceLoaderModule\getConfig(), getLocalPath(), null, stripBom(), and wfDebugLog().

Referenced by getScript().

◆ getPackageFileType()

static ResourceLoaderFileModule::getPackageFileType (   $path)
static

Infer the file type from a package file path.

Parameters
string$path
Returns
string 'script' or 'data'

Definition at line 698 of file ResourceLoaderFileModule.php.

References $path.

◆ getPath()

ResourceLoaderFileModule::getPath (   $path)
protected
Parameters
string | ResourceLoaderFilePath$path
Returns
string

Definition at line 650 of file ResourceLoaderFileModule.php.

References $path.

Referenced by __construct(), and getTemplates().

◆ getRemotePath()

ResourceLoaderFileModule::getRemotePath (   $path)
protected
Parameters
string | ResourceLoaderFilePath$path
Returns
string

Definition at line 674 of file ResourceLoaderFileModule.php.

References $path.

Referenced by getScriptURLsForDebug(), getStyleURLsForDebug(), and readStyleFile().

◆ getScript()

ResourceLoaderFileModule::getScript ( ResourceLoaderContext  $context)

Gets all scripts for a given context concatenated together.

Parameters
ResourceLoaderContext$contextContext in which to generate script
Returns
string|array JavaScript code for $context, or package files data structure

Definition at line 385 of file ResourceLoaderFileModule.php.

References $packageFiles, ResourceLoaderModule\getDeprecationInformation(), getPackageFiles(), getScriptFiles(), null, and readScriptFiles().

◆ getScriptFiles()

ResourceLoaderFileModule::getScriptFiles ( ResourceLoaderContext  $context)
private

Get a list of script file paths for this module, in order of proper execution.

Parameters
ResourceLoaderContext$context
Returns
array List of file paths

Definition at line 762 of file ResourceLoaderFileModule.php.

References ResourceLoaderContext\getDebug(), ResourceLoaderContext\getLanguage(), getLanguageScripts(), ResourceLoaderContext\getSkin(), and scripts.

Referenced by getScript(), and getScriptURLsForDebug().

◆ getScriptURLsForDebug()

ResourceLoaderFileModule::getScriptURLsForDebug ( ResourceLoaderContext  $context)

◆ getSkinStyleFiles()

ResourceLoaderFileModule::getSkinStyleFiles (   $skinName)
protected

Gets a list of file paths for all skin styles in the module used by the skin.

Parameters
string$skinNameThe name of the skin
Returns
array A list of file paths collated by media type

Definition at line 825 of file ResourceLoaderFileModule.php.

Referenced by getAllSkinStyleFiles().

◆ getSkipFunction()

ResourceLoaderFileModule::getSkipFunction ( )

Get the skip function.

Returns
null|string
Exceptions
MWException

Definition at line 499 of file ResourceLoaderFileModule.php.

References ResourceLoaderModule\$contents, getLocalPath(), null, and stripBom().

◆ getStyleFiles()

ResourceLoaderFileModule::getStyleFiles ( ResourceLoaderContext  $context)

Get a list of file paths for all styles in this module, in order of proper inclusion.

This is considered a private method. Exposed for internal use by WebInstallerOutput.

Access:
private
Parameters
ResourceLoaderContext$context
Returns
array List of file paths

Definition at line 807 of file ResourceLoaderFileModule.php.

References ResourceLoaderContext\getSkin().

Referenced by getStyles(), and getStyleURLsForDebug().

◆ getStyles()

ResourceLoaderFileModule::getStyles ( ResourceLoaderContext  $context)

Get all styles for a given context.

Parameters
ResourceLoaderContext$context
Returns
array CSS code for $context as an associative array mapping media type to CSS text.

Definition at line 430 of file ResourceLoaderFileModule.php.

References $styles, getFlip(), getStyleFiles(), readStyleFiles(), and ResourceLoaderModule\saveFileDependencies().

◆ getStyleSheetLang()

ResourceLoaderFileModule::getStyleSheetLang (   $path)

Infer the stylesheet language from a stylesheet file path.

Since
1.22
Parameters
string$path
Returns
string The stylesheet language name

Definition at line 689 of file ResourceLoaderFileModule.php.

References $path.

Referenced by readStyleFile().

◆ getStyleURLsForDebug()

ResourceLoaderFileModule::getStyleURLsForDebug ( ResourceLoaderContext  $context)

◆ getTargets()

ResourceLoaderFileModule::getTargets ( )

Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].

Returns
array Array of strings

Definition at line 986 of file ResourceLoaderFileModule.php.

References $targets.

◆ getTemplates()

ResourceLoaderFileModule::getTemplates ( )

Takes named templates by the module and returns an array mapping.

Returns
array Templates mapping template alias to content
Exceptions
MWException

Definition at line 1069 of file ResourceLoaderFileModule.php.

References $content, $templates, as, getLocalPath(), getPath(), stripBom(), and wfDebugLog().

◆ getType()

ResourceLoaderFileModule::getType ( )

Get the module's load type.

Since
1.28
Returns
string

Definition at line 996 of file ResourceLoaderFileModule.php.

References $skipFunction, messages, and scripts.

◆ readScriptFiles()

ResourceLoaderFileModule::readScriptFiles ( array  $scripts)
private

Get the contents of a list of JavaScript files.

Helper for getScript().

Parameters
array$scriptsList of file paths to scripts to read, remap and concetenate
Returns
string Concatenated JavaScript data from $scripts
Exceptions
MWException

Definition at line 883 of file ResourceLoaderFileModule.php.

References ResourceLoaderModule\$contents, as, getLocalPath(), and stripBom().

Referenced by getScript().

◆ readStyleFile()

ResourceLoaderFileModule::readStyleFile (   $path,
  $flip,
  $context 
)
protected

Reads a style file.

This method can be used as a callback for array_map()

Parameters
string$pathFile path of style file to read
bool$flip
ResourceLoaderContext$context
Returns
string CSS data in script file
Exceptions
MWExceptionIf the file doesn't exist

Definition at line 937 of file ResourceLoaderFileModule.php.

References $context, $file, $path, as, compileLessFile(), CSSMin\getLocalFileReferences(), getLocalPath(), getRemotePath(), getStyleSheetLang(), CSSMin\remap(), stripBom(), and wfDebugLog().

Referenced by readStyleFiles().

◆ readStyleFiles()

ResourceLoaderFileModule::readStyleFiles ( array  $styles,
  $flip,
  $context 
)

Get the contents of a list of CSS files.

Definition at line 910 of file ResourceLoaderFileModule.php.

References $context, $file, $styles, as, and readStyleFile().

Referenced by getStyles().

◆ stripBom()

ResourceLoaderFileModule::stripBom (   $input)
protected

Takes an input string and removes the UTF-8 BOM character if present.

We need to remove these after reading a file, because we concatenate our files and the BOM character is not valid in the middle of a string. We already assume UTF-8 everywhere, so this should be safe.

Parameters
string$input
Returns
string Input minus the intial BOM char

Definition at line 1265 of file ResourceLoaderFileModule.php.

References $input.

Referenced by getPackageFiles(), getSkipFunction(), getTemplates(), readScriptFiles(), and readStyleFile().

◆ supportsURLLoading()

ResourceLoaderFileModule::supportsURLLoading ( )
Returns
bool

Definition at line 418 of file ResourceLoaderFileModule.php.

References $packageFiles.

◆ tryForKey()

static ResourceLoaderFileModule::tryForKey ( array  $list,
  $key,
  $fallback = null 
)
staticprotected

Get a list of element that match a key, optionally using a fallback key.

Parameters
array$listList of lists to select from
string$keyKey to look for in $map
string | null$fallbackKey to look for in $list if $key doesn't exist
Returns
array List of elements from $map which matched $key or $fallback, or an empty list in case of no match

Definition at line 744 of file ResourceLoaderFileModule.php.

References $fallback.

Member Data Documentation

◆ $debugRaw

bool ResourceLoaderFileModule::$debugRaw = true
protected

Link to raw files in debug mode.

Definition at line 141 of file ResourceLoaderFileModule.php.

◆ $debugScripts

array ResourceLoaderFileModule::$debugScripts = []
protected

List of paths to JavaScript files to include in debug mode.

Usage:
[ [skin-name] => [ [file-path], [file-path], ... ], ... ]

Definition at line 79 of file ResourceLoaderFileModule.php.

◆ $dependencies

array ResourceLoaderFileModule::$dependencies = []
protected

List of modules this module depends on.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 121 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderForeignApiModule\getDependencies(), and getDependencies().

◆ $expandedPackageFiles

array ResourceLoaderFileModule::$expandedPackageFiles = []
private

Expanded versions of $packageFiles, lazy-computed by expandPackageFiles(); keyed by context hash.

Definition at line 112 of file ResourceLoaderFileModule.php.

Referenced by getPackageFiles().

◆ $group

string ResourceLoaderFileModule::$group
protected

Name of group to load this module in.

Definition at line 138 of file ResourceLoaderFileModule.php.

Referenced by getGroup().

◆ $hasGeneratedStyles

bool ResourceLoaderFileModule::$hasGeneratedStyles = false
protected

Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.

Definition at line 152 of file ResourceLoaderFileModule.php.

◆ $languageScripts

array ResourceLoaderFileModule::$languageScripts = []
protected

List of JavaScript files to include when using a specific language.

Usage:
[ [language-code] => [ [file-path], [file-path], ... ], ... ]

Definition at line 61 of file ResourceLoaderFileModule.php.

◆ $localBasePath

string ResourceLoaderFileModule::$localBasePath = ''
protected

Local base path, see __construct()

Definition at line 37 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderLessVarFileModule\__construct(), and extractBasePaths().

◆ $localFileRefs

array ResourceLoaderFileModule::$localFileRefs = []
protected

Place where readStyleFile() tracks file dependencies.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 161 of file ResourceLoaderFileModule.php.

◆ $messages

array ResourceLoaderFileModule::$messages = []
protected

List of message keys used by this module.

Usage:
[ [message-key], [message-key], ... ]

Definition at line 135 of file ResourceLoaderFileModule.php.

Referenced by getMessages().

◆ $missingLocalFileRefs

array ResourceLoaderFileModule::$missingLocalFileRefs = []
protected

Place where readStyleFile() tracks file dependencies for non-existent files.

Used in tests to detect missing dependencies.

Definition at line 167 of file ResourceLoaderFileModule.php.

◆ $noflip

bool ResourceLoaderFileModule::$noflip = false
protected

Whether CSSJanus flipping should be skipped for this module.

Definition at line 146 of file ResourceLoaderFileModule.php.

Referenced by getFlip().

◆ $packageFiles

array ResourceLoaderFileModule::$packageFiles = null
protected

List of packaged files to make available through require()

Usage:
[ [file-path], [file-path], ... ]

Definition at line 106 of file ResourceLoaderFileModule.php.

Referenced by getDefinitionSummary(), getScript(), and supportsURLLoading().

◆ $remoteBasePath

string ResourceLoaderFileModule::$remoteBasePath = ''
protected

Remote base path, see __construct()

Definition at line 40 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderLessVarFileModule\__construct(), and extractBasePaths().

◆ $scripts

array ResourceLoaderFileModule::$scripts = []
protected

List of paths to JavaScript files to always include.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 52 of file ResourceLoaderFileModule.php.

Referenced by getLanguageScripts().

◆ $skinScripts

array ResourceLoaderFileModule::$skinScripts = []
protected

List of JavaScript files to include when using a specific skin.

Usage:
[ [skin-name] => [ [file-path], [file-path], ... ], ... ]

Definition at line 70 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderOOUIFileModule\__construct().

◆ $skinStyles

array ResourceLoaderFileModule::$skinStyles = []
protected

List of paths to CSS files to include when using specific skins.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 97 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderOOUIFileModule\__construct().

◆ $skipFunction

string ResourceLoaderFileModule::$skipFunction = null
protected

File name containing the body of the skip function.

Definition at line 126 of file ResourceLoaderFileModule.php.

Referenced by getFileHashes(), and getType().

◆ $styles

array ResourceLoaderFileModule::$styles = []
protected

List of paths to CSS files to always include.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 88 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderSkinModule\getStyles(), getStyles(), ResourceLoaderSkinModule\normalizeStyles(), and readStyleFiles().

◆ $targets

ResourceLoaderFileModule::$targets = [ 'desktop' ]
protected

Definition at line 143 of file ResourceLoaderFileModule.php.

Referenced by getTargets().

◆ $templates

array ResourceLoaderFileModule::$templates = []
protected

Saves a list of the templates named by the modules.

Definition at line 43 of file ResourceLoaderFileModule.php.

Referenced by getTemplates().


The documentation for this class was generated from the following file: