MediaWiki  master
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. 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 (ResourceLoaderContext $context)
 Get JS representing deprecation information for the current module if available. More...
 
 getFlip (ResourceLoaderContext $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)
 
 setDependencyAccessCallbacks (callable $loadCallback, callable $saveCallback)
 Inject the functions that load/save the indirect file path dependency list from storage. More...
 
 setFileDependencies (ResourceLoaderContext $context, array $paths)
 Set the indirect dependencies for this module persuant to the skin/language context. More...
 
 setHookContainer (HookContainer $hookContainer)
 
 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 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

 buildContent (ResourceLoaderContext $context)
 Bundle all resources attached to this module into an array. More...
 
 getFileDependencies (ResourceLoaderContext $context)
 Get the indirect dependencies for this module persuant to the skin/language context. More...
 
 getHookRunner ()
 Get a HookRunner for running core hooks. 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, array $curFileRefs)
 Save the indirect dependencies for this module persuant to the skin/language context. More...
 
 validateScriptFile ( $fileName, $contents)
 Validate a given script file; if valid returns the original source. More...
 

Static Protected Member Functions

static safeFileHash ( $filePath)
 Compute a non-cryptographic string hash of a file's contents. More...
 

Protected Attributes

Config $config
 
array $contents = []
 Map of (context hash => cached module content) More...
 
string bool $deprecated = false
 Deprecation string or true if deprecated; false otherwise. More...
 
array $fileDeps = []
 Map of (variant => indirect file dependencies) More...
 
LoggerInterface $logger
 
array $msgBlobs = []
 Map of (language => in-object cache for message blob) More...
 
string null $name = null
 Module name. More...
 
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. More...
 
string[] $targets = [ 'desktop' ]
 What client platforms the module targets (e.g. More...
 
array $versionHash = []
 Map of (context hash => cached module version hash) More...
 

Private Attributes

callback $depLoadCallback
 Function of (module name, variant) to get indirect file dependencies. More...
 
callback $depSaveCallback
 Function of (module name, variant) to get indirect file dependencies. More...
 
HookRunner null $hookRunner
 

Static Private Attributes

static $parseCacheVersion = 1
 

Detailed Description

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

Stable to extend

Since
1.17

Definition at line 39 of file ResourceLoaderModule.php.

Member Function Documentation

◆ buildContent()

ResourceLoaderModule::buildContent ( ResourceLoaderContext  $context)
finalprotected

◆ 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.

Stable to override

Returns
bool

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

Definition at line 864 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 558 of file ResourceLoaderModule.php.

References $IP, and $path.

Referenced by ResourceLoaderFileModule\compileLessString(), ResourceLoader\loadModuleDependenciesInternal(), 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 data that should influence the module's version hash.

Subclasses must call the parent getDefinitionSummary() and add to the returned array. It is recommended that each subclass appends its own array, to prevent clashes or accidental overwrites of array keys from the parent class. This gives each subclass a clean scope.

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

Return an array that contains all significant properties that define the module. The returned data should be deterministic and only change when the generated module response would change. Prefer content hashes over modified timestamps because timestamps may change for unrelated reasons and are not deterministic (T102578). For example, because timestamps are not stored in Git, each branch checkout would cause all files to appear as new. Timestamps also tend to not match between servers causing additional ever-lasting churning of the version hash.

Be careful not to normalise the data too much in an effort to be deterministic. For example, if a module concatenates files together (order is significant), then the definition summary could be a list of file names, and a list of file hashes. These lists should not be sorted as that would mean the cache is not invalidated when the order changes (T39812).

This data structure must exclusively contain primitive "scalar" values, as it will be serialised using json_encode.

Stable to override

Since
1.23
Parameters
ResourceLoaderContext$context
Returns
array|null

Reimplemented in ResourceLoaderWikiModule, ResourceLoaderSkinModule, ResourceLoaderImageModule, and ResourceLoaderFileModule.

Definition at line 911 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.

Stable to override

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

Reimplemented in ResourceLoaderUserOptionsModule, ResourceLoaderSiteModule, ResourceLoaderForeignApiModule, and ResourceLoaderFileModule.

Definition at line 402 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderWikiModule\isKnownEmpty().

◆ getDeprecationInformation()

ResourceLoaderModule::getDeprecationInformation ( ResourceLoaderContext  $context)

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

Parameters
ResourceLoaderContext$context
Returns
string JavaScript code

Definition at line 164 of file ResourceLoaderModule.php.

References $deprecated, $name, ResourceLoaderContext\encodeJson(), and getName().

Referenced by ResourceLoaderFileModule\getScript().

◆ getFileDependencies()

ResourceLoaderModule::getFileDependencies ( ResourceLoaderContext  $context)
protected

Get the indirect dependencies for this module persuant to the skin/language context.

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

If niether setFileDependencies() nor setDependencyLoadCallback() was called, this will simply return a placeholder with an empty file list

See also
ResourceLoader::setFileDependencies()
ResourceLoader::saveFileDependencies()
Parameters
ResourceLoaderContext$context
Returns
string[] List of absolute file paths
Exceptions
RuntimeExceptionWhen setFileDependencies() has not yet been called

Definition at line 462 of file ResourceLoaderModule.php.

References getLogger(), getName(), and getVary().

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

◆ getFlip()

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

Reimplemented in ResourceLoaderFileModule.

Definition at line 153 of file ResourceLoaderModule.php.

References ResourceLoaderContext\getDirection().

Referenced by ResourceLoaderWikiModule\getStyles().

◆ getGroup()

ResourceLoaderModule::getGroup ( )

Get the group this module is in.

Stable to override

Returns
string Group name

Reimplemented in ResourceLoaderWikiModule, ResourceLoaderUserStylesModule, ResourceLoaderUserOptionsModule, ResourceLoaderUserModule, ResourceLoaderSiteStylesModule, and ResourceLoaderFileModule.

Definition at line 373 of file ResourceLoaderModule.php.

Referenced by shouldEmbedModule().

◆ 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 617 of file ResourceLoaderModule.php.

References getPreloadLinks().

Referenced by buildContent().

◆ getHookRunner()

ResourceLoaderModule::getHookRunner ( )
protected

Get a HookRunner for running core hooks.

Definition at line 269 of file ResourceLoaderModule.php.

References $hookRunner.

Referenced by ResourceLoaderForeignApiModule\getDependencies(), ResourceLoaderSiteModule\getPages(), and ResourceLoaderSiteStylesModule\getPages().

◆ getLessVars()

ResourceLoaderModule::getLessVars ( ResourceLoaderContext  $context)
protected

Get module-specific LESS variables, if any.

Stable to override

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

Reimplemented in ResourceLoaderSkinModule, and ResourceLoaderLessVarFileModule.

Definition at line 688 of file ResourceLoaderModule.php.

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

◆ getLogger()

ResourceLoaderModule::getLogger ( )
protected

◆ getMessageBlob()

ResourceLoaderModule::getMessageBlob ( ResourceLoaderContext  $context)
protected

Get the hash of the message blob.

Stable to override

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

Reimplemented in ResourceLoaderLessVarFileModule.

Definition at line 573 of file ResourceLoaderModule.php.

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

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()

Stable to override

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

Reimplemented in ResourceLoaderLessVarFileModule, and ResourceLoaderFileModule.

Definition at line 362 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 699 of file ResourceLoaderModule.php.

References buildContent(), and ResourceLoaderContext\getHash().

Referenced by getVersionHash().

◆ getName()

ResourceLoaderModule::getName ( )

◆ 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 145 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' ],
];
}
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

Stable to override

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 676 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 544 of file ResourceLoaderModule.php.

References $IP, and $path.

Referenced by ResourceLoaderFileModule\compileLessString().

◆ 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' ]

Stable to override

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

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

Definition at line 198 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.

Stable to override

Parameters
ResourceLoaderContext$context
Returns
array Array of URLs

Reimplemented in ResourceLoaderFileModule.

Definition at line 288 of file ResourceLoaderModule.php.

References getName(), ResourceLoaderContext\getResourceLoader(), 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.

Stable to override

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

Reimplemented in ResourceLoaderFileModule.

Definition at line 443 of file ResourceLoaderModule.php.

◆ getSource()

ResourceLoaderModule::getSource ( )

Get the source of this module.

Should only be overridden for foreign modules.

Stable to override

Returns
string Source name, 'local' for local modules

Definition at line 384 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.

Stable to override

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 ResourceLoaderWikiModule, ResourceLoaderSkinModule, ResourceLoaderImageModule, and ResourceLoaderFileModule.

Definition at line 324 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()

Stable to override

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

Reimplemented in ResourceLoaderFileModule.

Definition at line 339 of file ResourceLoaderModule.php.

References getName(), ResourceLoaderContext\getResourceLoader(), and getSource().

Referenced by buildContent().

◆ getTargets()

ResourceLoaderModule::getTargets ( )

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

Stable to override

Returns
array Array of strings

Reimplemented in ResourceLoaderFileModule.

Definition at line 413 of file ResourceLoaderModule.php.

References $targets.

◆ getTemplates()

ResourceLoaderModule::getTemplates ( )

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

Stable to override

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

Reimplemented in ResourceLoaderFileModule.

Definition at line 209 of file ResourceLoaderModule.php.

Referenced by buildContent().

◆ getType()

ResourceLoaderModule::getType ( )

Get the module's load type.

Stable to override

Since
1.28
Returns
string ResourceLoaderModule LOAD_* constant

Reimplemented in ResourceLoaderWikiModule, ResourceLoaderUserStylesModule, ResourceLoaderSiteStylesModule, ResourceLoaderImageModule, and ResourceLoaderFileModule.

Definition at line 424 of file ResourceLoaderModule.php.

◆ 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 832 of file ResourceLoaderModule.php.

References enableModuleContentVersion(), getDefinitionSummary(), ResourceLoaderContext\getHash(), getModuleContent(), and ResourceLoader\makeHash().

◆ 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.

Stable to override

Parameters
ResourceLoaderContext$context
Returns
bool

Reimplemented in ResourceLoaderWikiModule, and ResourceLoaderSkinModule.

Definition at line 931 of file ResourceLoaderModule.php.

◆ 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 1006 of file ResourceLoaderModule.php.

References FileContentsHasher\getFileContentsHash().

◆ saveFileDependencies()

ResourceLoaderModule::saveFileDependencies ( ResourceLoaderContext  $context,
array  $curFileRefs 
)
protected

Save the indirect dependencies for this module persuant to the skin/language context.

Parameters
ResourceLoaderContext$context
string[]$curFileRefsList of newly computed indirect file dependencies
Since
1.27

Definition at line 501 of file ResourceLoaderModule.php.

References getFileDependencies(), getLogger(), and getName().

Referenced by ResourceLoaderFileModule\getStyles().

◆ setConfig()

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

Definition at line 231 of file ResourceLoaderModule.php.

References $config.

◆ setDependencyAccessCallbacks()

ResourceLoaderModule::setDependencyAccessCallbacks ( callable  $loadCallback,
callable  $saveCallback 
)

Inject the functions that load/save the indirect file path dependency list from storage.

Parameters
callable$loadCallbackFunction of (module name, variant)
callable$saveCallbackFunction of (module name, variant, current paths, stored paths)
Since
1.35

Definition at line 133 of file ResourceLoaderModule.php.

◆ setFileDependencies()

ResourceLoaderModule::setFileDependencies ( ResourceLoaderContext  $context,
array  $paths 
)

Set the indirect dependencies for this module persuant to the skin/language context.

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

See also
ResourceLoader::getFileDependencies()
ResourceLoader::saveFileDependencies()
Parameters
ResourceLoaderContext$context
string[]$pathsList of absolute file paths

Definition at line 489 of file ResourceLoaderModule.php.

References getVary().

◆ setHookContainer()

ResourceLoaderModule::setHookContainer ( HookContainer  $hookContainer)

Definition at line 258 of file ResourceLoaderModule.php.

◆ setLogger()

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

Definition at line 239 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 599 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 122 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 Stable to override
Parameters
ResourceLoaderContext$context
Returns
bool

Reimplemented in ResourceLoaderWikiModule.

Definition at line 946 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.

Stable to override

Returns
bool

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

Definition at line 311 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 960 of file ResourceLoaderModule.php.

References $cache, $contents, Xml\encodeJsVar(), and getConfig().

Referenced by ResourceLoaderWikiModule\getScript().

Member Data Documentation

◆ $config

◆ $contents

array ResourceLoaderModule::$contents = []
protected

Map of (context hash => cached module content)

Definition at line 66 of file ResourceLoaderModule.php.

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

◆ $depLoadCallback

callback ResourceLoaderModule::$depLoadCallback
private

Function of (module name, variant) to get indirect file dependencies.

Definition at line 72 of file ResourceLoaderModule.php.

◆ $deprecated

string bool ResourceLoaderModule::$deprecated = false
protected

Deprecation string or true if deprecated; false otherwise.

Definition at line 77 of file ResourceLoaderModule.php.

Referenced by getDeprecationInformation().

◆ $depSaveCallback

callback ResourceLoaderModule::$depSaveCallback
private

Function of (module name, variant) to get indirect file dependencies.

Definition at line 74 of file ResourceLoaderModule.php.

◆ $fileDeps

array ResourceLoaderModule::$fileDeps = []
protected

Map of (variant => indirect file dependencies)

Definition at line 60 of file ResourceLoaderModule.php.

◆ $hookRunner

HookRunner null ResourceLoaderModule::$hookRunner
private

Definition at line 69 of file ResourceLoaderModule.php.

Referenced by getHookRunner().

◆ $logger

LoggerInterface ResourceLoaderModule::$logger
protected

Definition at line 43 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 62 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 52 of file ResourceLoaderModule.php.

Referenced by getOrigin().

◆ $parseCacheVersion

ResourceLoaderModule::$parseCacheVersion = 1
staticprivate

Definition at line 950 of file ResourceLoaderModule.php.

◆ $targets

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

What client platforms the module targets (e.g.

desktop, mobile)

Definition at line 57 of file ResourceLoaderModule.php.

Referenced by getTargets().

◆ $versionHash

array ResourceLoaderModule::$versionHash = []
protected

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

Definition at line 64 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderStartUpModule\getModuleRegistrations().


The documentation for this class was generated from the following file:
ResourceLoaderModule\getPreloadLinks
getPreloadLinks(ResourceLoaderContext $context)
Get a list of resources that web browsers may preload.
Definition: ResourceLoaderModule.php:676