MediaWiki  master
MediaWiki\ResourceLoader\Module Class Reference

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

Inheritance diagram for MediaWiki\ResourceLoader\Module:
Collaboration diagram for MediaWiki\ResourceLoader\Module:

Public Member Functions

 enableModuleContentVersion ()
 Whether to generate version hash based on module content. More...
 
 getConfig ()
 
 getDefinitionSummary (Context $context)
 Get the definition summary for this module. More...
 
 getDependencies (Context $context=null)
 Get a list of modules this module depends on. More...
 
 getDeprecationInformation (Context $context)
 Get JS representing deprecation information for the current module if available. More...
 
 getFlip (Context $context)
 
 getGroup ()
 Get the group this module is in. More...
 
 getHeaders (Context $context)
 Get headers to send as part of a module web response. More...
 
 getMessages ()
 Get the messages needed for this module. More...
 
 getModuleContent (Context $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 (Context $context)
 Get all JS for this module for a given language and skin. More...
 
 getScriptURLsForDebug (Context $context)
 Get alternative script URLs for legacy debug mode. More...
 
 getSkins ()
 Get list of skins for which this module must be available to load. More...
 
 getSkipFunction ()
 Get the skip function. More...
 
 getSource ()
 Get the source of this module. More...
 
 getStyles (Context $context)
 Get all CSS for this module for a given skin. More...
 
 getStyleURLsForDebug (Context $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 (Context $context)
 Get a string identifying the current version of this module in a given context. More...
 
 isKnownEmpty (Context $context)
 Check whether this module is known to be empty. More...
 
 requiresES6 ()
 Whether the module requires ES6 support in the client. 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 (Context $context, array $paths)
 Set the indirect dependencies for this module pursuant 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...
 
 setSkinStylesOverride (array $moduleSkinStyles)
 Provide overrides for skinStyles to modules that support that. More...
 
 shouldEmbedModule (Context $context)
 Check whether this module should be embedded 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 (Context $context)
 Get vary string. More...
 

Protected Member Functions

 buildContent (Context $context)
 Bundle all resources attached to this module into an array. More...
 
 getFileDependencies (Context $context)
 Get the indirect dependencies for this module pursuant to the skin/language context. More...
 
 getHookRunner ()
 Get a HookRunner for running core hooks. More...
 
 getLessVars (Context $context)
 Get module-specific LESS variables, if any. More...
 
 getLogger ()
 
 getMessageBlob (Context $context)
 Get the hash of the message blob. More...
 
 getPreloadLinks (Context $context)
 Get a list of resources that web browsers may preload. More...
 
 saveFileDependencies (Context $context, array $curFileRefs)
 Save the indirect dependencies for this module pursuant to the skin/language context. More...
 
 validateScriptFile ( $fileName, $contents)
 Validate a user-provided JavaScript blob. 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[] null $skins = null
 Skin names. More...
 
string[] $targets = [ 'desktop' ]
 What client platforms the module targets (e.g. More...
 
array $versionHash = []
 Map of (context hash => cached module version hash) More...
 

Detailed Description

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

See also
$wgResourceModules for the available options when registering a module.
Stability: stable
to extend
Since
1.17

Definition at line 48 of file Module.php.

Member Function Documentation

◆ buildContent()

MediaWiki\ResourceLoader\Module::buildContent ( Context  $context)
finalprotected

Bundle all resources attached to this module into an array.

Since
1.26
Parameters
Context$context
Returns
array

Definition at line 798 of file Module.php.

References $blob, $content, MediaWiki\ResourceLoader\Context\getDebug(), and MediaWiki\ResourceLoader\Context\getOnly().

◆ enableModuleContentVersion()

MediaWiki\ResourceLoader\Module::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.

Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\ResourceLoader\WikiModule, MediaWiki\ResourceLoader\StartUpModule, MediaWiki\ResourceLoader\LanguageDataModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 950 of file Module.php.

◆ expandRelativePaths()

static MediaWiki\ResourceLoader\Module::expandRelativePaths ( array  $filePaths)
static

Expand directories relative to $IP.

Since
1.27
Parameters
array$filePaths
Returns
array

Definition at line 642 of file Module.php.

References $IP, and $path.

Referenced by MediaWiki\ResourceLoader\ResourceLoader\loadModuleDependenciesInternal(), and MediaWiki\ResourceLoader\ResourceLoader\preloadModuleInfo().

◆ getConfig()

◆ getDefinitionSummary()

MediaWiki\ResourceLoader\Module::getDefinitionSummary ( Context  $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.

Stability: stable
to override
Since
1.23
Parameters
Context$context
Returns
array|null

Reimplemented in MediaWiki\ResourceLoader\WikiModule, MediaWiki\ResourceLoader\SkinModule, MediaWiki\ResourceLoader\ImageModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 997 of file Module.php.

◆ getDependencies()

MediaWiki\ResourceLoader\Module::getDependencies ( Context  $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.

Stability: stable
to override
Parameters
Context | null$context
Returns
string[] List of module names as strings

Reimplemented in MediaWiki\ResourceLoader\SiteModule, MediaWiki\ResourceLoader\ForeignApiModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 457 of file Module.php.

◆ getDeprecationInformation()

MediaWiki\ResourceLoader\Module::getDeprecationInformation ( Context  $context)

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

Parameters
Context$context
Returns
string JavaScript code

Definition at line 200 of file Module.php.

References MediaWiki\ResourceLoader\Module\$deprecated, MediaWiki\ResourceLoader\Module\$name, MediaWiki\ResourceLoader\Context\encodeJson(), and MediaWiki\ResourceLoader\Module\getName().

Referenced by MediaWiki\ResourceLoader\FileModule\getScript().

◆ getFileDependencies()

MediaWiki\ResourceLoader\Module::getFileDependencies ( Context  $context)
protected

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

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

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

See also
Module::setFileDependencies()
Module::saveFileDependencies()
Parameters
Context$context
Returns
string[] List of absolute file paths

Definition at line 545 of file Module.php.

◆ getFlip()

MediaWiki\ResourceLoader\Module::getFlip ( Context  $context)
Parameters
Context$context
Returns
bool

Reimplemented in MediaWiki\ResourceLoader\FileModule.

Definition at line 189 of file Module.php.

References MediaWiki\ResourceLoader\Context\getDirection(), and MediaWiki\MediaWikiServices\getInstance().

◆ getGroup()

MediaWiki\ResourceLoader\Module::getGroup ( )

◆ getHeaders()

MediaWiki\ResourceLoader\Module::getHeaders ( Context  $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
Context$context
Returns
string[] Array of HTTP response headers

Definition at line 701 of file Module.php.

◆ getHookRunner()

MediaWiki\ResourceLoader\Module::getHookRunner ( )
protected

Get a HookRunner for running core hooks.

Access: internal
For use only within core ResourceLoaderModule subclasses. Hook interfaces may be removed without notice.
Returns
HookRunner

Definition at line 304 of file Module.php.

Referenced by MediaWiki\ResourceLoader\ForeignApiModule\getDependencies(), MediaWiki\ResourceLoader\SiteModule\getPages(), and MediaWiki\ResourceLoader\SiteStylesModule\getPages().

◆ getLessVars()

MediaWiki\ResourceLoader\Module::getLessVars ( Context  $context)
protected

Get module-specific LESS variables, if any.

Stability: stable
to override
Since
1.27
Parameters
Context$context
Returns
array Module-specific LESS variables.

Reimplemented in MediaWiki\ResourceLoader\SkinModule, and MediaWiki\ResourceLoader\LessVarFileModule.

Definition at line 770 of file Module.php.

Referenced by MediaWiki\ResourceLoader\FileModule\getDefinitionSummary().

◆ getLogger()

MediaWiki\ResourceLoader\Module::getLogger ( )
protected
Since
1.27
Returns
LoggerInterface

Definition at line 282 of file Module.php.

References MediaWiki\ResourceLoader\Module\$logger.

Referenced by MediaWiki\ResourceLoader\WikiModule\getContentObj().

◆ getMessageBlob()

MediaWiki\ResourceLoader\Module::getMessageBlob ( Context  $context)
protected

Get the hash of the message blob.

Stability: stable
to override
Since
1.27
Parameters
Context$context
Returns
string|null JSON blob or null if module has no messages

Reimplemented in MediaWiki\ResourceLoader\LessVarFileModule.

Definition at line 657 of file Module.php.

References $lang, MediaWiki\ResourceLoader\Context\getLanguage(), and MediaWiki\ResourceLoader\Context\getResourceLoader().

Referenced by MediaWiki\ResourceLoader\FileModule\getDefinitionSummary().

◆ getMessages()

MediaWiki\ResourceLoader\Module::getMessages ( )

Get the messages needed for this module.

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

Stability: stable
to override
Returns
string[] List of message keys. Keys may occur more than once

Reimplemented in MediaWiki\ResourceLoader\LessVarFileModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 417 of file Module.php.

◆ getModuleContent()

MediaWiki\ResourceLoader\Module::getModuleContent ( Context  $context)

Get an array of this module's resources.

Ready for serving to the web.

Since
1.26
Parameters
Context$context
Returns
array

Definition at line 781 of file Module.php.

References MediaWiki\ResourceLoader\Context\getHash().

◆ getName()

MediaWiki\ResourceLoader\Module::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 135 of file Module.php.

References MediaWiki\ResourceLoader\Module\$name.

Referenced by MediaWiki\ResourceLoader\MessageBlobStore\getBlob(), and MediaWiki\ResourceLoader\Module\getDeprecationInformation().

◆ getOrigin()

MediaWiki\ResourceLoader\Module::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 181 of file Module.php.

References MediaWiki\ResourceLoader\Module\$origin.

◆ getPreloadLinks()

MediaWiki\ResourceLoader\Module::getPreloadLinks ( Context  $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(Context $context)
Get a list of resources that web browsers may preload.
Definition: Module.php:758
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
Module::getHeaders
Stability: stable
to override
Since
1.30
Parameters
Context$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 MediaWiki\ResourceLoader\SkinModule.

Definition at line 758 of file Module.php.

◆ getRelativePaths()

static MediaWiki\ResourceLoader\Module::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 628 of file Module.php.

References $IP, and $path.

◆ getScript()

MediaWiki\ResourceLoader\Module::getScript ( Context  $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' ]

Stability: stable
to override
Parameters
Context$context
Returns
string|array JavaScript code (string), or multi-file structure described above (array)

Reimplemented in MediaWiki\ResourceLoader\WikiModule, MediaWiki\ResourceLoader\UserOptionsModule, MediaWiki\ResourceLoader\StartUpModule, MediaWiki\ResourceLoader\LanguageDataModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 234 of file Module.php.

◆ getScriptURLsForDebug()

MediaWiki\ResourceLoader\Module::getScriptURLsForDebug ( Context  $context)

Get alternative script URLs for legacy debug mode.

The default behavior is to return a load.php?only=scripts&module=<name> URL.

Module classes that merely wrap one or more other script files in production mode, may override this method to return an array of raw URLs for those underlying scripts, if those are individually web-accessible.

The mw.loader client will load and execute each URL consecutively. This has the caveat of executing legacy debug scripts in the global scope, which is why non-package file modules tend to use file closures (T50886).

This function MUST NOT be called, unless all the following are true:

  1. We're in debug mode,
  2. There is no only= parameter in the context,
  3. self::supportsURLLoading() has returned true.

Point 2 prevents an infinite loop since we use the only= mechanism in the return value. Overrides must similarly return with only, or return or a non-load.php URL.

Stability: stable
to override
Parameters
Context$context
Returns
string[]

Reimplemented in MediaWiki\ResourceLoader\FileModule.

Definition at line 334 of file Module.php.

References MediaWiki\ResourceLoader\Context\getResourceLoader().

◆ getSkins()

MediaWiki\ResourceLoader\Module::getSkins ( )

Get list of skins for which this module must be available to load.

By default, modules are available to all skins.

This information may be used by the startup module to optimise registrations based on the current skin.

Stability: stable
to override
Since
1.39
Returns
string[]|null

Definition at line 484 of file Module.php.

◆ getSkipFunction()

MediaWiki\ResourceLoader\Module::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.

Stability: stable
to override
Returns
string|null A JavaScript function body returning a boolean value, or null

Reimplemented in MediaWiki\ResourceLoader\FileModule.

Definition at line 514 of file Module.php.

◆ getSource()

MediaWiki\ResourceLoader\Module::getSource ( )

Get the source of this module.

Should only be overridden for foreign modules.

Stability: stable
to override
Returns
string Source name, 'local' for local modules

Definition at line 439 of file Module.php.

Referenced by MediaWiki\ResourceLoader\WikiModule\shouldEmbedModule().

◆ getStyles()

MediaWiki\ResourceLoader\Module::getStyles ( Context  $context)

Get all CSS for this module for a given skin.

Stability: stable
to override
Parameters
Context$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 MediaWiki\ResourceLoader\WikiModule, MediaWiki\ResourceLoader\SkinModule, MediaWiki\ResourceLoader\ImageModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 372 of file Module.php.

◆ getStyleURLsForDebug()

MediaWiki\ResourceLoader\Module::getStyleURLsForDebug ( Context  $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

This function must only be called when:

  1. We're in debug mode,
  2. There is no only= parameter and,
  3. self::supportsURLLoading() returns true.

See also getScriptURLsForDebug().

Stability: stable
to override
Parameters
Context$context
Returns
array [ mediaType => [ URL1, URL2, ... ], ... ]

Reimplemented in MediaWiki\ResourceLoader\FileModule.

Definition at line 395 of file Module.php.

References MediaWiki\ResourceLoader\Context\getResourceLoader().

◆ getTargets()

MediaWiki\ResourceLoader\Module::getTargets ( )

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

Stability: stable
to override
Returns
string[]

Reimplemented in MediaWiki\ResourceLoader\FileModule.

Definition at line 468 of file Module.php.

◆ getTemplates()

MediaWiki\ResourceLoader\Module::getTemplates ( )

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

Stability: stable
to override
Returns
string[] Array of templates mapping template alias to content

Reimplemented in MediaWiki\ResourceLoader\FileModule.

Definition at line 245 of file Module.php.

◆ getType()

MediaWiki\ResourceLoader\Module::getType ( )

Get the module's load type.

Stability: stable
to override
Since
1.28
Returns
string Module LOAD_* constant

Reimplemented in MediaWiki\ResourceLoader\WikiModule, MediaWiki\ResourceLoader\UserStylesModule, MediaWiki\ResourceLoader\SiteStylesModule, MediaWiki\ResourceLoader\ImageModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 495 of file Module.php.

◆ getVary()

static MediaWiki\ResourceLoader\Module::getVary ( Context  $context)
static

Get vary string.

Access: internal
For internal use only.
Parameters
Context$context
Returns
string

Definition at line 1111 of file Module.php.

References MediaWiki\ResourceLoader\Context\getLanguage(), and MediaWiki\ResourceLoader\Context\getSkin().

Referenced by MediaWiki\ResourceLoader\ResourceLoader\preloadModuleInfo().

◆ getVersionHash()

MediaWiki\ResourceLoader\Module::getVersionHash ( Context  $context)
final

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 caches, both server-side (by a CDN, or other HTTP cache), and client-side (in mw.loader.store, and in the browser's own HTTP cache).

The underlying methods called here for any given module should be quick because this is called for potentially thousands of module bundles in the same request as part of the StartUpModule, which is how we invalidate caches and propagate changes to clients.

Since
1.26
See also
self::getDefinitionSummary for how to customize version computation.
Parameters
Context$context
Returns
string Hash formatted by ResourceLoader::makeHash

Definition at line 910 of file Module.php.

References MediaWiki\ResourceLoader\Context\getDebug(), and MediaWiki\ResourceLoader\Context\getHash().

◆ isKnownEmpty()

MediaWiki\ResourceLoader\Module::isKnownEmpty ( Context  $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.

Stability: stable
to override
Parameters
Context$context
Returns
bool

Reimplemented in MediaWiki\ResourceLoader\WikiModule, and MediaWiki\ResourceLoader\SkinModule.

Definition at line 1017 of file Module.php.

◆ requiresES6()

MediaWiki\ResourceLoader\Module::requiresES6 ( )

Whether the module requires ES6 support in the client.

If the client does not support ES6, attempting to load a module that requires ES6 will result in an error.

Stability: stable
to override
Since
1.36
Returns
bool

Reimplemented in MediaWiki\ResourceLoader\FileModule.

Definition at line 528 of file Module.php.

◆ safeFileHash()

static MediaWiki\ResourceLoader\Module::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$filePath
Returns
string Hash

Definition at line 1100 of file Module.php.

References FileContentsHasher\getFileContentsHash().

◆ saveFileDependencies()

MediaWiki\ResourceLoader\Module::saveFileDependencies ( Context  $context,
array  $curFileRefs 
)
protected

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

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

Definition at line 583 of file Module.php.

Referenced by MediaWiki\ResourceLoader\FileModule\getStyles().

◆ setConfig()

MediaWiki\ResourceLoader\Module::setConfig ( Config  $config)
Parameters
Config$config
Since
1.24

Definition at line 266 of file Module.php.

References MediaWiki\ResourceLoader\Module\$config.

◆ setDependencyAccessCallbacks()

MediaWiki\ResourceLoader\Module::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 169 of file Module.php.

◆ setFileDependencies()

MediaWiki\ResourceLoader\Module::setFileDependencies ( Context  $context,
array  $paths 
)

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

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

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

Definition at line 571 of file Module.php.

◆ setHookContainer()

MediaWiki\ResourceLoader\Module::setHookContainer ( HookContainer  $hookContainer)
Access: internal
For use only by ResourceLoader::getModule
Parameters
HookContainer$hookContainer

Definition at line 293 of file Module.php.

◆ setLogger()

MediaWiki\ResourceLoader\Module::setLogger ( LoggerInterface  $logger)
Since
1.27
Parameters
LoggerInterface$logger

Definition at line 274 of file Module.php.

References MediaWiki\ResourceLoader\Module\$logger.

◆ setMessageBlob()

MediaWiki\ResourceLoader\Module::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 683 of file Module.php.

References $blob, and $lang.

◆ setName()

MediaWiki\ResourceLoader\Module::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 145 of file Module.php.

References MediaWiki\ResourceLoader\Module\$name.

◆ setSkinStylesOverride()

MediaWiki\ResourceLoader\Module::setSkinStylesOverride ( array  $moduleSkinStyles)

Provide overrides for skinStyles to modules that support that.

This MUST be called after self::setName().

Since
1.37
See also
$wgResourceModuleSkinStyles
Parameters
array$moduleSkinStyles

Reimplemented in MediaWiki\ResourceLoader\OOUIFileModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 158 of file Module.php.

◆ shouldEmbedModule()

MediaWiki\ResourceLoader\Module::shouldEmbedModule ( Context  $context)

Check whether this module should be embedded rather than linked.

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

Since
1.30
Stability: stable
to override
Parameters
Context$context
Returns
bool

Reimplemented in MediaWiki\ResourceLoader\WikiModule.

Definition at line 1032 of file Module.php.

◆ supportsURLLoading()

MediaWiki\ResourceLoader\Module::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.

Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\ResourceLoader\WikiModule, MediaWiki\ResourceLoader\UserOptionsModule, MediaWiki\ResourceLoader\StartUpModule, MediaWiki\ResourceLoader\LanguageDataModule, MediaWiki\ResourceLoader\ImageModule, and MediaWiki\ResourceLoader\FileModule.

Definition at line 359 of file Module.php.

◆ validateScriptFile()

MediaWiki\ResourceLoader\Module::validateScriptFile (   $fileName,
  $contents 
)
protected

Validate a user-provided JavaScript blob.

Parameters
string$fileName
string$contentsJavaScript code
Returns
string JavaScript code, either the original content or a replacement that uses mw.log.error() to communicate a syntax error.

Definition at line 1044 of file Module.php.

References $cache.

Referenced by MediaWiki\ResourceLoader\WikiModule\getScript().

Member Data Documentation

◆ $config

◆ $contents

array MediaWiki\ResourceLoader\Module::$contents = []
protected

Map of (context hash => cached module content)

Definition at line 77 of file Module.php.

◆ $deprecated

string bool MediaWiki\ResourceLoader\Module::$deprecated = false
protected

Deprecation string or true if deprecated; false otherwise.

Definition at line 88 of file Module.php.

Referenced by MediaWiki\ResourceLoader\Module\getDeprecationInformation().

◆ $fileDeps

array MediaWiki\ResourceLoader\Module::$fileDeps = []
protected

Map of (variant => indirect file dependencies)

Definition at line 71 of file Module.php.

◆ $logger

LoggerInterface MediaWiki\ResourceLoader\Module::$logger
protected

◆ $msgBlobs

array MediaWiki\ResourceLoader\Module::$msgBlobs = []
protected

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

Definition at line 73 of file Module.php.

◆ $name

string null MediaWiki\ResourceLoader\Module::$name = null
protected

◆ $origin

int MediaWiki\ResourceLoader\Module::$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 61 of file Module.php.

Referenced by MediaWiki\ResourceLoader\Module\getOrigin().

◆ $skins

string [] null MediaWiki\ResourceLoader\Module::$skins = null
protected

Skin names.

Definition at line 68 of file Module.php.

◆ $targets

string [] MediaWiki\ResourceLoader\Module::$targets = [ 'desktop' ]
protected

What client platforms the module targets (e.g.

desktop, mobile)

Definition at line 66 of file Module.php.

◆ $versionHash

array MediaWiki\ResourceLoader\Module::$versionHash = []
protected

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

Definition at line 75 of file Module.php.


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