MediaWiki REL1_34
ResourceLoaderModule Class Reference

Abstraction for ResourceLoader modules, with name registration and maxage functionality. More...

Inheritance diagram for ResourceLoaderModule:
Collaboration diagram for ResourceLoaderModule:

Public Member Functions

 enableModuleContentVersion ()
 Whether to generate version hash based on module content.
 
 getConfig ()
 
 getDefinitionSummary (ResourceLoaderContext $context)
 Get the definition summary for this module.
 
 getDependencies (ResourceLoaderContext $context=null)
 Get a list of modules this module depends on.
 
 getDeprecationInformation (ResourceLoaderContext $context=null)
 Get JS representing deprecation information for the current module if available.
 
 getFlip (ResourceLoaderContext $context)
 
 getGroup ()
 Get the group this module is in.
 
 getHeaders (ResourceLoaderContext $context)
 Get headers to send as part of a module web response.
 
 getMessages ()
 Get the messages needed for this module.
 
 getModuleContent (ResourceLoaderContext $context)
 Get an array of this module's resources.
 
 getName ()
 Get this module's name.
 
 getOrigin ()
 Get this module's origin.
 
 getScript (ResourceLoaderContext $context)
 Get all JS for this module for a given language and skin.
 
 getScriptURLsForDebug (ResourceLoaderContext $context)
 Get the URL or URLs to load for this module's JS in debug mode.
 
 getSkipFunction ()
 Get the skip function.
 
 getSource ()
 Get the source of this module.
 
 getStyles (ResourceLoaderContext $context)
 Get all CSS for this module for a given skin.
 
 getStyleURLsForDebug (ResourceLoaderContext $context)
 Get the URL or URLs to load for this module's CSS in debug mode.
 
 getTargets ()
 Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
 
 getTemplates ()
 Takes named templates by the module and returns an array mapping.
 
 getType ()
 Get the module's load type.
 
 getVersionHash (ResourceLoaderContext $context)
 Get a string identifying the current version of this module in a given context.
 
 isKnownEmpty (ResourceLoaderContext $context)
 Check whether this module is known to be empty.
 
 setConfig (Config $config)
 
 setFileDependencies (ResourceLoaderContext $context, $files)
 Set in-object cache for file dependencies.
 
 setLogger (LoggerInterface $logger)
 
 setMessageBlob ( $blob, $lang)
 Set in-object cache for message blobs.
 
 setName ( $name)
 Set this module's name.
 
 shouldEmbedModule (ResourceLoaderContext $context)
 Check whether this module should be embeded rather than linked.
 
 supportsURLLoading ()
 Whether this module supports URL loading.
 

Static Public Member Functions

static expandRelativePaths (array $filePaths)
 Expand directories relative to $IP.
 
static getRelativePaths (array $filePaths)
 Make file paths relative to MediaWiki directory.
 
static getVary (ResourceLoaderContext $context)
 Get vary string.
 

Protected Member Functions

 buildContent (ResourceLoaderContext $context)
 Bundle all resources attached to this module into an array.
 
 getFileDependencies (ResourceLoaderContext $context)
 Get the files this module depends on indirectly for a given skin.
 
 getLessVars (ResourceLoaderContext $context)
 Get module-specific LESS variables, if any.
 
 getLogger ()
 
 getMessageBlob (ResourceLoaderContext $context)
 Get the hash of the message blob.
 
 getPreloadLinks (ResourceLoaderContext $context)
 Get a list of resources that web browsers may preload.
 
 saveFileDependencies (ResourceLoaderContext $context, $localFileRefs)
 Set the files this module depends on indirectly for a given skin.
 
 validateScriptFile ( $fileName, $contents)
 Validate a given script file; if valid returns the original source.
 

Static Protected Member Functions

static javaScriptParser ()
 
static safeFileHash ( $filePath)
 Compute a non-cryptographic string hash of a file's contents.
 
static safeFilemtime ( $filePath)
 Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist.
 

Protected Attributes

Config $config
 
array $contents = []
 Map of (context hash => cached module content)
 
string bool $deprecated = false
 Deprecation string or true if deprecated; false otherwise.
 
array $fileDeps = []
 Map of (variant => indirect file dependencies)
 
LoggerInterface $logger
 
array $msgBlobs = []
 Map of (language => in-object cache for message blob)
 
string null $name = null
 Module name.
 
int $origin = self::ORIGIN_CORE_SITEWIDE
 Script and style modules form a hierarchy of trustworthiness, with core modules like skins and jQuery as most trustworthy, and user scripts as least trustworthy.
 
string[] $targets = [ 'desktop' ]
 What client platforms the module targets (e.g.
 
array $versionHash = []
 Map of (context hash => cached module version hash)
 

Static Private Attributes

static JSParser $jsParser
 Lazy-initialized; use self::javaScriptParser()
 
static $parseCacheVersion = 1
 

Detailed Description

Abstraction for ResourceLoader modules, with name registration and maxage functionality.

Since
1.17

Definition at line 37 of file ResourceLoaderModule.php.

Member Function Documentation

◆ buildContent()

ResourceLoaderModule::buildContent ( ResourceLoaderContext $context)
finalprotected

Bundle all resources attached to this module into an array.

Since
1.26
Parameters
ResourceLoaderContext$context
Returns
array

Definition at line 699 of file ResourceLoaderModule.php.

References $blob, $content, $context, getHeaders(), getMessageBlob(), getName(), getScript(), getScriptURLsForDebug(), getStyles(), getStyleURLsForDebug(), and getTemplates().

Referenced by getModuleContent().

◆ enableModuleContentVersion()

ResourceLoaderModule::enableModuleContentVersion ( )

Whether to generate version hash based on module content.

If a module requires database or file system access to build the module content, consider disabling this in favour of manually tracking relevant aspects in getDefinitionSummary(). See getVersionHash() for how this is used.

Returns
bool

Reimplemented in ResourceLoaderSyntaxHighlightVisualEditorModule, ResourceLoaderFileModule, ResourceLoaderLanguageDataModule, ResourceLoaderStartUpModule, ResourceLoaderUserDefaultsModule, ResourceLoaderUserOptionsModule, and ResourceLoaderWikiModule.

Definition at line 846 of file ResourceLoaderModule.php.

Referenced by getVersionHash().

◆ expandRelativePaths()

static ResourceLoaderModule::expandRelativePaths ( array $filePaths)
static

Expand directories relative to $IP.

Since
1.27
Parameters
array$filePaths
Returns
array

Definition at line 545 of file ResourceLoaderModule.php.

References $IP, and $path.

Referenced by getFileDependencies(), and ResourceLoader\preloadModuleInfo().

◆ getConfig()

◆ getDefinitionSummary()

ResourceLoaderModule::getDefinitionSummary ( ResourceLoaderContext $context)

Get the definition summary for this module.

This is the method subclasses are recommended to use to track values in their version hash. Call this in getVersionHash() and pass it to e.g. json_encode.

Subclasses must call the parent getDefinitionSummary() and build on that. It is recommended that each subclass appends its own new array. This prevents clashes or accidental overwrites of existing keys and gives each subclass its own scope for simple array keys.

$summary = parent::getDefinitionSummary( $context );
$summary[] = [
'foo' => 123,
'bar' => 'quux',
];
return $summary;
$context
Definition load.php:45

Return an array containing values from all significant properties of this module's definition.

Be careful not to normalise too much. Especially preserve the order of things that carry significance in getScript and getStyles (T39812).

Avoid including things that are insiginificant (e.g. order of message keys is insignificant and should be sorted to avoid unnecessary cache invalidation).

This data structure must exclusively contain arrays and scalars as values (avoid object instances) to allow simple serialisation using json_encode.

If modules have a hash or timestamp from another source, that may be incuded as-is.

A number of utility methods are available to help you gather data. These are not called by default and must be included by the subclass' getDefinitionSummary().

Since
1.23
Parameters
ResourceLoaderContext$context
Returns
array|null

Reimplemented in CiteDataModule, ResourceLoaderFileModule, ResourceLoaderImageModule, ResourceLoaderSkinModule, ResourceLoaderWikiModule, and TimelessVariablesModule.

Definition at line 893 of file ResourceLoaderModule.php.

Referenced by getVersionHash().

◆ getDependencies()

ResourceLoaderModule::getDependencies ( ResourceLoaderContext $context = null)

Get a list of modules this module depends on.

Dependency information is taken into account when loading a module on the client side.

Note: It is expected that $context will be made non-optional in the near future.

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

Reimplemented in CiteDataModule, GadgetResourceLoaderModule, ResourceLoaderFileModule, ResourceLoaderForeignApiModule, ResourceLoaderSiteModule, and ResourceLoaderUserOptionsModule.

Definition at line 356 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderWikiModule\isKnownEmpty().

◆ getDeprecationInformation()

ResourceLoaderModule::getDeprecationInformation ( ResourceLoaderContext $context = null)

Get JS representing deprecation information for the current module if available.

Parameters
ResourceLoaderContext | null$contextMissing $context is deprecated in 1.34
Returns
string JavaScript code

Definition at line 142 of file ResourceLoaderModule.php.

References $context, $deprecated, $name, getName(), and wfDeprecated().

Referenced by ResourceLoaderFileModule\getScript().

◆ getFileDependencies()

ResourceLoaderModule::getFileDependencies ( ResourceLoaderContext $context)
protected

Get the files this module depends on indirectly for a given skin.

These are only image files referenced by the module's stylesheet.

Parameters
ResourceLoaderContext$context
Returns
array List of files

Definition at line 406 of file ResourceLoaderModule.php.

References $context, $dbr, DB_REPLICA, expandRelativePaths(), getName(), getVary(), and wfGetDB().

Referenced by ResourceLoaderFileModule\getFileHashes(), and saveFileDependencies().

◆ getFlip()

ResourceLoaderModule::getFlip ( ResourceLoaderContext $context)
Parameters
ResourceLoaderContext$context
Returns
bool

Reimplemented in ResourceLoaderFileModule.

Definition at line 131 of file ResourceLoaderModule.php.

References $context.

Referenced by ResourceLoaderWikiModule\getStyles().

◆ getGroup()

ResourceLoaderModule::getGroup ( )

◆ getHeaders()

ResourceLoaderModule::getHeaders ( ResourceLoaderContext $context)
final

Get headers to send as part of a module web response.

It is not supported to send headers through this method that are required to be unique or otherwise sent once in an HTTP response because clients may make batch requests for multiple modules (as is the default behaviour for ResourceLoader clients).

For exclusive or aggregated headers, see ResourceLoader::sendResponseHeaders().

Since
1.30
Parameters
ResourceLoaderContext$context
Returns
string[] Array of HTTP response headers

Definition at line 603 of file ResourceLoaderModule.php.

References getPreloadLinks().

Referenced by buildContent().

◆ getLessVars()

ResourceLoaderModule::getLessVars ( ResourceLoaderContext $context)
protected

Get module-specific LESS variables, if any.

Since
1.27
Parameters
ResourceLoaderContext$context
Returns
array Module-specific LESS variables.

Reimplemented in ResourceLoaderLessVarFileModule, TimelessVariablesModule, and Vector\ResourceLoaderLessModule.

Definition at line 671 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderFileModule\compileLessFile(), and ResourceLoaderFileModule\getDefinitionSummary().

◆ getLogger()

ResourceLoaderModule::getLogger ( )
protected
Since
1.27
Returns
LoggerInterface

Definition at line 229 of file ResourceLoaderModule.php.

References $logger.

Referenced by ResourceLoaderWikiModule\getContentObj(), and getMessageBlob().

◆ getMessageBlob()

ResourceLoaderModule::getMessageBlob ( ResourceLoaderContext $context)
protected

Get the hash of the message blob.

Since
1.27
Parameters
ResourceLoaderContext$context
Returns
string|null JSON blob or null if module has no messages

Reimplemented in ResourceLoaderLessVarFileModule.

Definition at line 559 of file ResourceLoaderModule.php.

References $context, $lang, ResourceLoaderContext\getLanguage(), getLogger(), getMessages(), and getName().

Referenced by buildContent(), and ResourceLoaderFileModule\getDefinitionSummary().

◆ getMessages()

ResourceLoaderModule::getMessages ( )

Get the messages needed for this module.

To get a JSON blob with messages, use MessageBlobStore::get()

Returns
array List of message keys. Keys may occur more than once

Reimplemented in GadgetResourceLoaderModule, ResourceLoaderFileModule, and ResourceLoaderLessVarFileModule.

Definition at line 319 of file ResourceLoaderModule.php.

Referenced by MessageBlobStore\generateMessageBlob(), getMessageBlob(), and MessageBlobStore\makeCacheKey().

◆ getModuleContent()

ResourceLoaderModule::getModuleContent ( ResourceLoaderContext $context)

Get an array of this module's resources.

Ready for serving to the web.

Since
1.26
Parameters
ResourceLoaderContext$context
Returns
array

Definition at line 682 of file ResourceLoaderModule.php.

References $context, and buildContent().

Referenced by getVersionHash().

◆ getName()

ResourceLoaderModule::getName ( )

Get this module's name.

This is set when the module is registered with ResourceLoader::register()

Returns
string|null Name (string) or null if no name was set

Definition at line 102 of file ResourceLoaderModule.php.

References $name.

Referenced by buildContent(), MessageBlobStore\generateMessageBlob(), MessageBlobStore\getBlob(), getDeprecationInformation(), getFileDependencies(), ResourceLoaderImageModule\getImages(), getMessageBlob(), getScriptURLsForDebug(), getStyleURLsForDebug(), MessageBlobStore\makeCacheKey(), and saveFileDependencies().

◆ getOrigin()

ResourceLoaderModule::getOrigin ( )

Get this module's origin.

This is set when the module is registered with ResourceLoader::register()

Returns
int ResourceLoaderModule class constant, the subclass default if not set manually

Definition at line 123 of file ResourceLoaderModule.php.

References $origin.

Referenced by OutputPage\filterModules().

◆ getPreloadLinks()

ResourceLoaderModule::getPreloadLinks ( ResourceLoaderContext $context)
protected

Get a list of resources that web browsers may preload.

Behaviour of rel=preload link is specified at https://www.w3.org/TR/preload/.

Use case for ResourceLoader originally part of T164299.

Example
protected function getPreloadLinks() {
return [
'https://example.org/script.js' => [ 'as' => 'script' ],
'https://example.org/image.png' => [ 'as' => 'image' ],
];
}
getPreloadLinks(ResourceLoaderContext $context)
Get a list of resources that web browsers may preload.
Example using HiDPI image variants
protected function getPreloadLinks() {
return [
'https://example.org/logo.png' => [
'as' => 'image',
'media' => 'not all and (min-resolution: 2dppx)',
],
'https://example.org/logo@2x.png' => [
'as' => 'image',
'media' => '(min-resolution: 2dppx)',
],
];
}
See also
ResourceLoaderModule::getHeaders
Since
1.30
Parameters
ResourceLoaderContext$context
Returns
array Keyed by url, values must be an array containing at least an 'as' key. Optionally a 'media' key as well.

Reimplemented in ResourceLoaderSkinModule.

Definition at line 660 of file ResourceLoaderModule.php.

Referenced by getHeaders().

◆ getRelativePaths()

static ResourceLoaderModule::getRelativePaths ( array $filePaths)
static

Make file paths relative to MediaWiki directory.

This is used to make file paths safe for storing in a database without the paths becoming stale or incorrect when MediaWiki is moved or upgraded (T111481).

Since
1.27
Parameters
array$filePaths
Returns
array

Definition at line 531 of file ResourceLoaderModule.php.

References $IP, and $path.

Referenced by saveFileDependencies().

◆ getScript()

ResourceLoaderModule::getScript ( ResourceLoaderContext $context)

Get all JS for this module for a given language and skin.

Includes all relevant JS except loader scripts.

For "plain" script modules, this should return a string with JS code. For multi-file modules where require() is used to load one file from another file, this should return an array structured as follows: [ 'files' => [ 'file1.js' => [ 'type' => 'script', 'content' => 'JS code' ], 'file2.js' => [ 'type' => 'script', 'content' => 'JS code' ], 'data.json' => [ 'type' => 'data', 'content' => array ] ], 'main' => 'file1.js' ]

Parameters
ResourceLoaderContext$context
Returns
string|array JavaScript code (string), or multi-file structure described above (array)

Reimplemented in CiteDataModule, ResourceLoaderSyntaxHighlightVisualEditorModule, ResourceLoaderFileModule, ResourceLoaderLanguageDataModule, ResourceLoaderStartUpModule, ResourceLoaderUserDefaultsModule, ResourceLoaderUserOptionsModule, ResourceLoaderUserTokensModule, and ResourceLoaderWikiModule.

Definition at line 181 of file ResourceLoaderModule.php.

Referenced by buildContent().

◆ getScriptURLsForDebug()

ResourceLoaderModule::getScriptURLsForDebug ( ResourceLoaderContext $context)

Get the URL or URLs to load for this module's JS in debug mode.

The default behavior is to return a load.php?only=scripts URL for the module, but file-based modules will want to override this to load the files directly.

This function is called only when 1) we're in debug mode, 2) there is no only= parameter and 3) supportsURLLoading() returns true. #2 is important to prevent an infinite loop, therefore this function MUST return either an only= URL or a non-load.php URL.

Parameters
ResourceLoaderContext$context
Returns
array Array of URLs

Reimplemented in ResourceLoaderFileModule.

Definition at line 250 of file ResourceLoaderModule.php.

References $context, $resourceLoader, getName(), and getSource().

Referenced by buildContent().

◆ getSkipFunction()

ResourceLoaderModule::getSkipFunction ( )

Get the skip function.

Modules that provide fallback functionality can provide a "skip function". This function, if provided, will be passed along to the module registry on the client. When this module is loaded (either directly or as a dependency of another module), then this function is executed first. If the function returns true, the module will instantly be considered "ready" without requesting the associated module resources.

The value returned here must be valid javascript for execution in a private function. It must not contain the "function () {" and "}" wrapper though.

Returns
string|null A JavaScript function body returning a boolean value, or null

Reimplemented in ResourceLoaderFileModule.

Definition at line 394 of file ResourceLoaderModule.php.

◆ getSource()

ResourceLoaderModule::getSource ( )

Get the source of this module.

Should only be overridden for foreign modules.

Returns
string Source name, 'local' for local modules

Definition at line 339 of file ResourceLoaderModule.php.

Referenced by getScriptURLsForDebug(), ResourceLoaderImageModule\getStyles(), getStyleURLsForDebug(), and ResourceLoaderWikiModule\shouldEmbedModule().

◆ getStyles()

ResourceLoaderModule::getStyles ( ResourceLoaderContext $context)

Get all CSS for this module for a given skin.

Parameters
ResourceLoaderContext$context
Returns
array List of CSS strings or array of CSS strings keyed by media type. like [ 'screen' => '.foo { width: 0 }' ]; or [ 'screen' => [ '.foo { width: 0 }' ] ];

Reimplemented in ResourceLoaderFileModule, ResourceLoaderImageModule, ResourceLoaderSkinModule, and ResourceLoaderWikiModule.

Definition at line 283 of file ResourceLoaderModule.php.

Referenced by buildContent().

◆ getStyleURLsForDebug()

ResourceLoaderModule::getStyleURLsForDebug ( ResourceLoaderContext $context)

Get the URL or URLs to load for this module's CSS in debug mode.

The default behavior is to return a load.php?only=styles URL for the module, but file-based modules will want to override this to load the files directly. See also getScriptURLsForDebug()

Parameters
ResourceLoaderContext$context
Returns
array [ mediaType => [ URL1, URL2, ... ], ... ]

Reimplemented in ResourceLoaderFileModule.

Definition at line 297 of file ResourceLoaderModule.php.

References $context, $resourceLoader, getName(), and getSource().

Referenced by buildContent().

◆ getTargets()

ResourceLoaderModule::getTargets ( )

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

Returns
array Array of strings

Reimplemented in GadgetResourceLoaderModule, and ResourceLoaderFileModule.

Definition at line 366 of file ResourceLoaderModule.php.

References $targets.

◆ getTemplates()

ResourceLoaderModule::getTemplates ( )

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

Returns
string[] Array of templates mapping template alias to content

Reimplemented in ResourceLoaderFileModule.

Definition at line 191 of file ResourceLoaderModule.php.

Referenced by buildContent().

◆ getType()

ResourceLoaderModule::getType ( )

◆ getVary()

static ResourceLoaderModule::getVary ( ResourceLoaderContext $context)
static

◆ getVersionHash()

ResourceLoaderModule::getVersionHash ( ResourceLoaderContext $context)

Get a string identifying the current version of this module in a given context.

Whenever anything happens that changes the module's response (e.g. scripts, styles, and messages) this value must change. This value is used to store module responses in cache. (Both client-side and server-side.)

It is not recommended to override this directly. Use getDefinitionSummary() instead. If overridden, one must call the parent getVersionHash(), append data and re-hash.

This method should be quick because it is frequently run by ResourceLoaderStartUpModule to propagate changes to the client and effectively invalidate cache.

Since
1.26
Parameters
ResourceLoaderContext$context
Returns
string Hash (should use ResourceLoader::makeHash)

Definition at line 815 of file ResourceLoaderModule.php.

References $context, enableModuleContentVersion(), getDefinitionSummary(), and getModuleContent().

◆ isKnownEmpty()

ResourceLoaderModule::isKnownEmpty ( ResourceLoaderContext $context)

Check whether this module is known to be empty.

If a child class has an easy and cheap way to determine that this module is definitely going to be empty, it should override this method to return true in that case. Callers may optimize the request for this module away if this function returns true.

Parameters
ResourceLoaderContext$context
Returns
bool

Reimplemented in ResourceLoaderSkinModule, ResourceLoaderUserOptionsModule, and ResourceLoaderWikiModule.

Definition at line 911 of file ResourceLoaderModule.php.

◆ javaScriptParser()

static ResourceLoaderModule::javaScriptParser ( )
staticprotected
Returns
JSParser

Definition at line 982 of file ResourceLoaderModule.php.

References $jsParser.

Referenced by validateScriptFile().

◆ safeFileHash()

static ResourceLoaderModule::safeFileHash ( $filePath)
staticprotected

Compute a non-cryptographic string hash of a file's contents.

If the file does not exist or cannot be read, returns an empty string.

Since
1.26 Uses MD4 instead of SHA1.
Parameters
string$filePathFile path
Returns
string Hash

Definition at line 1011 of file ResourceLoaderModule.php.

References FileContentsHasher\getFileContentsHash().

◆ safeFilemtime()

static ResourceLoaderModule::safeFilemtime ( $filePath)
staticprotected

Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist.

Defaults to 1.

Parameters
string$filePathFile path
Returns
int UNIX timestamp

Definition at line 996 of file ResourceLoaderModule.php.

◆ saveFileDependencies()

ResourceLoaderModule::saveFileDependencies ( ResourceLoaderContext $context,
$localFileRefs )
protected

Set the files this module depends on indirectly for a given skin.

Since
1.27
Parameters
ResourceLoaderContext$context
array$localFileRefsList of files

Definition at line 453 of file ResourceLoaderModule.php.

References $cache, $context, DB_MASTER, getFileDependencies(), getName(), getRelativePaths(), getVary(), wfDebugLog(), and wfGetDB().

Referenced by ResourceLoaderFileModule\getStyles().

◆ setConfig()

ResourceLoaderModule::setConfig ( Config $config)
Parameters
Config$config
Since
1.24

Definition at line 213 of file ResourceLoaderModule.php.

References $config.

◆ setFileDependencies()

ResourceLoaderModule::setFileDependencies ( ResourceLoaderContext $context,
$files )

Set in-object cache for file dependencies.

This is used to retrieve data in batches. See ResourceLoader::preloadModuleInfo(). To save the data, use saveFileDependencies().

Parameters
ResourceLoaderContext$context
string[]$filesArray of file names

Definition at line 441 of file ResourceLoaderModule.php.

References $context, and getVary().

◆ setLogger()

ResourceLoaderModule::setLogger ( LoggerInterface $logger)
Since
1.27
Parameters
LoggerInterface$logger

Definition at line 221 of file ResourceLoaderModule.php.

References $logger.

◆ setMessageBlob()

ResourceLoaderModule::setMessageBlob ( $blob,
$lang )

Set in-object cache for message blobs.

Used to allow fetching of message blobs in batches. See ResourceLoader::preloadModuleInfo().

Since
1.27
Parameters
string | null$blobJSON blob or null
string$langLanguage code

Definition at line 585 of file ResourceLoaderModule.php.

References $blob, and $lang.

◆ setName()

ResourceLoaderModule::setName ( $name)

Set this module's name.

This is called by ResourceLoader::register() when registering the module. Other code should not call this.

Parameters
string$name

Definition at line 112 of file ResourceLoaderModule.php.

References $name.

◆ shouldEmbedModule()

ResourceLoaderModule::shouldEmbedModule ( ResourceLoaderContext $context)

Check whether this module should be embeded rather than linked.

Modules returning true here will be embedded rather than loaded by ResourceLoaderClientHtml.

Since
1.30
Parameters
ResourceLoaderContext$context
Returns
bool

Reimplemented in ResourceLoaderWikiModule.

Definition at line 925 of file ResourceLoaderModule.php.

References getGroup().

◆ supportsURLLoading()

ResourceLoaderModule::supportsURLLoading ( )

Whether this module supports URL loading.

If this function returns false, getScript() will be used even in cases (debug mode, no only param) where getScriptURLsForDebug() would normally be used instead.

Returns
bool

Reimplemented in ResourceLoaderSyntaxHighlightVisualEditorModule, ResourceLoaderFileModule, ResourceLoaderImageModule, ResourceLoaderLanguageDataModule, ResourceLoaderStartUpModule, ResourceLoaderUserOptionsModule, and ResourceLoaderUserTokensModule.

Definition at line 271 of file ResourceLoaderModule.php.

◆ validateScriptFile()

ResourceLoaderModule::validateScriptFile ( $fileName,
$contents )
protected

Validate a given script file; if valid returns the original source.

If invalid, returns replacement JS source that throws an exception.

Parameters
string$fileName
string$contents
Returns
string JS with the original, or a replacement error

Definition at line 941 of file ResourceLoaderModule.php.

References $cache, $contents, getConfig(), and javaScriptParser().

Referenced by ResourceLoaderWikiModule\getScript().

Member Data Documentation

◆ $config

◆ $contents

array ResourceLoaderModule::$contents = []
protected

Map of (context hash => cached module content)

Definition at line 64 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderFileModule\getSkipFunction(), ResourceLoaderFileModule\readScriptFiles(), and validateScriptFile().

◆ $deprecated

string bool ResourceLoaderModule::$deprecated = false
protected

Deprecation string or true if deprecated; false otherwise.

Definition at line 67 of file ResourceLoaderModule.php.

Referenced by getDeprecationInformation().

◆ $fileDeps

array ResourceLoaderModule::$fileDeps = []
protected

Map of (variant => indirect file dependencies)

Definition at line 58 of file ResourceLoaderModule.php.

◆ $jsParser

JSParser ResourceLoaderModule::$jsParser
staticprivate

Lazy-initialized; use self::javaScriptParser()

Definition at line 930 of file ResourceLoaderModule.php.

Referenced by javaScriptParser().

◆ $logger

LoggerInterface ResourceLoaderModule::$logger
protected

Definition at line 41 of file ResourceLoaderModule.php.

Referenced by getLogger(), and setLogger().

◆ $msgBlobs

array ResourceLoaderModule::$msgBlobs = []
protected

Map of (language => in-object cache for message blob)

Definition at line 60 of file ResourceLoaderModule.php.

◆ $name

◆ $origin

int ResourceLoaderModule::$origin = self::ORIGIN_CORE_SITEWIDE
protected

Script and style modules form a hierarchy of trustworthiness, with core modules like skins and jQuery as most trustworthy, and user scripts as least trustworthy.

We can limit the types of scripts and styles we allow to load on, say, sensitive special pages like Special:UserLogin and Special:Preferences

Definition at line 50 of file ResourceLoaderModule.php.

Referenced by getOrigin().

◆ $parseCacheVersion

ResourceLoaderModule::$parseCacheVersion = 1
staticprivate

Definition at line 931 of file ResourceLoaderModule.php.

◆ $targets

string [] ResourceLoaderModule::$targets = [ 'desktop' ]
protected

What client platforms the module targets (e.g.

desktop, mobile)

Definition at line 55 of file ResourceLoaderModule.php.

Referenced by getTargets().

◆ $versionHash

array ResourceLoaderModule::$versionHash = []
protected

Map of (context hash => cached module version hash)

Definition at line 62 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderStartUpModule\getModuleRegistrations().


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