MediaWiki  1.30.0
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

 getConfig ()
 
 getDefinitionMtime (ResourceLoaderContext $context)
 Back-compat dummy for old subclass implementations of getModifiedTime(). More...
 
 getDefinitionSummary (ResourceLoaderContext $context)
 Get a list of resources that web browsers may preload. More...
 
 getDependencies (ResourceLoaderContext $context=null)
 Get a list of modules this module depends on. More...
 
 getFlip ( $context)
 
 getGroup ()
 Get the group this module is in. More...
 
 getHashMtime (ResourceLoaderContext $context)
 Back-compat dummy for old subclass implementations of getModifiedTime(). 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...
 
 getModifiedHash (ResourceLoaderContext $context)
 Helper method for providing a version hash to getVersionHash(). More...
 
 getModifiedTime (ResourceLoaderContext $context)
 Get this module's last modification timestamp for a given context. More...
 
 getName ()
 Get this module's name. More...
 
 getOrigin ()
 Get this module's origin. More...
 
 getPosition ()
 From where in the page HTML should this module be loaded? 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 origin 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...
 
 isKnownEmpty (ResourceLoaderContext $context)
 Check whether this module is known to be empty. More...
 
 isRaw ()
 Whether this module's JS expects to work without the client-side ResourceLoader module. More...
 
 setConfig (Config $config)
 
 setFileDependencies (ResourceLoaderContext $context, $files)
 Set in-object cache for file dependencies. More...
 
 setLogger (LoggerInterface $logger)
 
 setMessageBlob ( $blob, $lang)
 Set in-object cache for message blobs. More...
 
 setName ( $name)
 Set this module's name. More...
 
 shouldEmbedModule (ResourceLoaderContext $context)
 Check whether this module should be embeded rather than linked. More...
 
 supportsURLLoading ()
 Whether this module supports URL loading. More...
 

Static Public Member Functions

static expandRelativePaths (array $filePaths)
 Expand directories relative to $IP. More...
 
static getRelativePaths (array $filePaths)
 Make file paths relative to MediaWiki directory. More...
 

Public Attributes

const LOAD_GENERAL = 'general'
 
const LOAD_STYLES = 'styles'
 
const ORIGIN_ALL = 10
 
const ORIGIN_CORE_INDIVIDUAL = 2
 
const ORIGIN_CORE_SITEWIDE = 1
 
const ORIGIN_USER_INDIVIDUAL = 4
 
const ORIGIN_USER_SITEWIDE = 3
 
const TYPE_COMBINED = 'combined'
 
const TYPE_SCRIPTS = 'scripts'
 
const TYPE_STYLES = 'styles'
 

Protected Member Functions

 getDeprecationInformation ()
 Get JS representing deprecation information for the current module if available. More...
 
 getFileDependencies (ResourceLoaderContext $context)
 Get the files this module depends on indirectly for a given skin. More...
 
 getLogger ()
 
 getMessageBlob (ResourceLoaderContext $context)
 Get the hash of the message blob. More...
 
 saveFileDependencies (ResourceLoaderContext $context, $localFileRefs)
 Set the files this module depends on indirectly for a given skin. More...
 
 validateScriptFile ( $fileName, $contents)
 Validate a given script file; if valid returns the original source. More...
 

Static Protected Member Functions

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

Protected Attributes

Config $config
 
 $contents = []
 
array bool $deprecated = false
 
 $fileDeps = []
 
LoggerInterface $logger
 
 $msgBlobs = []
 
 $name = null
 
 $origin = self::ORIGIN_CORE_SITEWIDE
 
 $targets = [ 'desktop' ]
 
 $versionHash = []
 

Static Private Attributes

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

Detailed Description

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

Definition at line 34 of file ResourceLoaderModule.php.

Member Function Documentation

◆ 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, $path, global, and use.

Referenced by getFileDependencies().

◆ getConfig()

◆ getDefinitionMtime()

ResourceLoaderModule::getDefinitionMtime ( ResourceLoaderContext  $context)

Back-compat dummy for old subclass implementations of getModifiedTime().

Since
1.23
Deprecated:
since 1.26 Superseded by getVersionHash()
Parameters
ResourceLoaderContext$context
Returns
int UNIX timestamp

Definition at line 980 of file ResourceLoaderModule.php.

References getDefinitionSummary().

◆ getDefinitionSummary()

ResourceLoaderModule::getDefinitionSummary ( ResourceLoaderContext  $context)

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' ],
];
}
@encode
@par 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)',
],
];
}
@encode
@since 1.30
@return array Keyed by url, values must be an array containing
at least an 'as' key. Optionally a 'media' key as well.
/
protected function getPreloadLinks( ResourceLoaderContext $context ) {
return [];
}
protected function getLessVars( ResourceLoaderContext $context ) {
return [];
}
public function getModuleContent( ResourceLoaderContext $context ) {
$contextHash = $context->getHash();
// Cache this expensive operation. This calls builds the scripts, styles, and messages
// content which typically involves filesystem and/or database access.
if ( !array_key_exists( $contextHash, $this->contents ) ) {
$this->contents[$contextHash] = $this->buildContent( $context );
}
return $this->contents[$contextHash];
}
final protected function buildContent( ResourceLoaderContext $context ) {
$rl = $context->getResourceLoader();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
$statStart = microtime( true );
// Only include properties that are relevant to this context (e.g. only=scripts)
// and that are non-empty (e.g. don't include "templates" for modules without
// templates). This helps prevent invalidating cache for all modules when new
// optional properties are introduced.
$content = [];
// Scripts
if ( $context->shouldIncludeScripts() ) {
// If we are in debug mode, we'll want to return an array of URLs if possible
// However, we can't do this if the module doesn't support it
// We also can't do this if there is an only= parameter, because we have to give
// the module a way to return a load.php URL without causing an infinite loop
if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
$scripts = $this->getScriptURLsForDebug( $context );
} else {
$scripts = $this->getScript( $context );
// Make the script safe to concatenate by making sure there is at least one
// trailing new line at the end of the content. Previously, this looked for
// a semi-colon instead, but that breaks concatenation if the semicolon
// is inside a comment like "// foo();". Instead, simply use a
// line break as separator which matches JavaScript native logic for implicitly
// ending statements even if a semi-colon is missing.
// Bugs: T29054, T162719.
if ( is_string( $scripts )
&& strlen( $scripts )
&& substr( $scripts, -1 ) !== "\n"
) {
$scripts .= "\n";
}
}
$content['scripts'] = $scripts;
}
// Styles
if ( $context->shouldIncludeStyles() ) {
$styles = [];
// Don't create empty stylesheets like [ '' => '' ] for modules
// that don't *have* any stylesheets (T40024).
$stylePairs = $this->getStyles( $context );
if ( count( $stylePairs ) ) {
// If we are in debug mode without &only= set, we'll want to return an array of URLs
// See comment near shouldIncludeScripts() for more details
if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
$styles = [
'url' => $this->getStyleURLsForDebug( $context )
];
} else {
// Minify CSS before embedding in mw.loader.implement call
// (unless in debug mode)
if ( !$context->getDebug() ) {
foreach ( $stylePairs as $media => $style ) {
// Can be either a string or an array of strings.
if ( is_array( $style ) ) {
$stylePairs[$media] = [];
foreach ( $style as $cssText ) {
if ( is_string( $cssText ) ) {
$stylePairs[$media][] =
ResourceLoader::filter( 'minify-css', $cssText );
}
}
} elseif ( is_string( $style ) ) {
$stylePairs[$media] = ResourceLoader::filter( 'minify-css', $style );
}
}
}
// Wrap styles into @media groups as needed and flatten into a numerical array
$styles = [
'css' => $rl->makeCombinedStyles( $stylePairs )
];
}
}
$content['styles'] = $styles;
}
// Messages
$blob = $this->getMessageBlob( $context );
if ( $blob ) {
$content['messagesBlob'] = $blob;
}
$templates = $this->getTemplates();
if ( $templates ) {
$content['templates'] = $templates;
}
$headers = $this->getHeaders( $context );
if ( $headers ) {
$content['headers'] = $headers;
}
$statTiming = microtime( true ) - $statStart;
$statName = strtr( $this->getName(), '.', '_' );
$stats->timing( "resourceloader_build.all", 1000 * $statTiming );
$stats->timing( "resourceloader_build.$statName", 1000 * $statTiming );
return $content;
}
public function getVersionHash( ResourceLoaderContext $context ) {
// The startup module produces a manifest with versions representing the entire module.
// Typically, the request for the startup module itself has only=scripts. That must apply
// only to the startup module content, and not to the module version computed here.
$context->setModules( [] );
// Version hash must cover all resources, regardless of startup request itself.
$context->setOnly( null );
// Compute version hash based on content, not debug urls.
$context->setDebug( false );
// Cache this somewhat expensive operation. Especially because some classes
// (e.g. startup module) iterate more than once over all modules to get versions.
$contextHash = $context->getHash();
if ( !array_key_exists( $contextHash, $this->versionHash ) ) {
if ( $this->enableModuleContentVersion() ) {
// Detect changes directly
$str = json_encode( $this->getModuleContent( $context ) );
} else {
// Infer changes based on definition and other metrics
$summary = $this->getDefinitionSummary( $context );
if ( !isset( $summary['_cacheEpoch'] ) ) {
throw new LogicException( 'getDefinitionSummary must call parent method' );
}
$str = json_encode( $summary );
$mtime = $this->getModifiedTime( $context );
if ( $mtime !== null ) {
// Support: MediaWiki 1.25 and earlier
$str .= strval( $mtime );
}
$mhash = $this->getModifiedHash( $context );
if ( $mhash !== null ) {
// Support: MediaWiki 1.25 and earlier
$str .= strval( $mhash );
}
}
$this->versionHash[$contextHash] = ResourceLoader::makeHash( $str );
}
return $this->versionHash[$contextHash];
}
public function enableModuleContentVersion() {
return false;
}

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

Definition at line 924 of file ResourceLoaderModule.php.

References class, and getConfig().

Referenced by getDefinitionMtime().

◆ 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$context
Returns
array List of module names as strings

Reimplemented in ResourceLoaderFileModule, ResourceLoaderTestModule, ResourceLoaderUserModule, ResourceLoaderLanguageDataModule, GadgetResourceLoaderModule, ResourceLoaderSpecialCharacterDataModule, ResourceLoaderLanguageNamesModule, CiteDataModule, ResourceLoaderSiteModule, ResourceLoaderUserOptionsModule, and ResourceLoaderForeignApiModule.

Definition at line 366 of file ResourceLoaderModule.php.

◆ getDeprecationInformation()

ResourceLoaderModule::getDeprecationInformation ( )
protected

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

Returns
string JavaScript code

Definition at line 145 of file ResourceLoaderModule.php.

References $deprecated, $name, Xml\encodeJsCall(), and getName().

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

References $context, $dbr, array(), DB_REPLICA, FormatJson\decode(), expandRelativePaths(), getName(), and wfGetDB().

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

◆ getFlip()

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

Reimplemented in ResourceLoaderFileModule.

Definition at line 134 of file ResourceLoaderModule.php.

References $context, $wgContLang, and global.

Referenced by ResourceLoaderWikiModule\getStyles().

◆ getGroup()

◆ getHashMtime()

ResourceLoaderModule::getHashMtime ( ResourceLoaderContext  $context)

Back-compat dummy for old subclass implementations of getModifiedTime().

This method used to use ObjectCache to track when a hash was first seen. That principle stems from a time that ResourceLoader could only identify module versions by timestamp. That is no longer the case. Use getDefinitionSummary() directly.

Deprecated:
since 1.26 Superseded by getVersionHash()
Parameters
ResourceLoaderContext$context
Returns
int UNIX timestamp

Definition at line 964 of file ResourceLoaderModule.php.

References getModifiedHash().

◆ 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 $attribs, $context, $link, and as.

◆ getLogger()

ResourceLoaderModule::getLogger ( )
protected
Since
1.27
Returns
LoggerInterface

Definition at line 218 of file ResourceLoaderModule.php.

References $logger.

Referenced by 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

Definition at line 559 of file ResourceLoaderModule.php.

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

Referenced by 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 ResourceLoaderFileModule, ResourceLoaderTestModule, GadgetResourceLoaderModule, and ResourceLoaderSpecialCharacterDataModule.

Definition at line 308 of file ResourceLoaderModule.php.

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

◆ getModifiedHash()

ResourceLoaderModule::getModifiedHash ( ResourceLoaderContext  $context)

Helper method for providing a version hash to getVersionHash().

Deprecated:
since 1.26 Use getDefinitionSummary() instead
Parameters
ResourceLoaderContext$context
Returns
string|null Hash

Definition at line 949 of file ResourceLoaderModule.php.

Referenced by getHashMtime().

◆ getModifiedTime()

ResourceLoaderModule::getModifiedTime ( ResourceLoaderContext  $context)

Get this module's last modification timestamp for a given context.

Deprecated:
since 1.26 Use getDefinitionSummary() instead
Parameters
ResourceLoaderContext$contextContext object
Returns
int|null UNIX timestamp

Definition at line 938 of file ResourceLoaderModule.php.

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

References $name.

Referenced by 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 126 of file ResourceLoaderModule.php.

References $origin.

Referenced by OutputPage\filterModules().

◆ getPosition()

ResourceLoaderModule::getPosition ( )

From where in the page HTML should this module be loaded?

Deprecated:
since 1.29 Obsolete. All modules load async from <head>.
Returns
string

Reimplemented in ResourceLoaderTestModule.

Definition at line 339 of file ResourceLoaderModule.php.

◆ 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, $path, global, and use.

Referenced by saveFileDependencies().

◆ getScript()

◆ 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, ResourceLoaderJqueryMsgModule, and ResourceLoaderSyntaxHighlightVisualEditorModule.

Definition at line 239 of file ResourceLoaderModule.php.

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

Referenced by ResourceLoaderSyntaxHighlightVisualEditorModule\getScriptURLsForDebug(), and ResourceLoaderJqueryMsgModule\getScriptURLsForDebug().

◆ 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, and ResourceLoaderTestModule.

Definition at line 404 of file ResourceLoaderModule.php.

◆ getSource()

ResourceLoaderModule::getSource ( )

Get the origin of this module.

Should only be overridden for foreign modules.

Returns
string Origin name, 'local' for local modules

Reimplemented in ResourceLoaderTestModule.

Definition at line 328 of file ResourceLoaderModule.php.

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

◆ 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, ResourceLoaderWikiModule, ResourceLoaderTestModule, and ResourceLoaderSkinModule.

Definition at line 272 of file ResourceLoaderModule.php.

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

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

◆ getTargets()

ResourceLoaderModule::getTargets ( )

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

Returns
array Array of strings

Reimplemented in ResourceLoaderFileModule, and GadgetResourceLoaderModule.

Definition at line 376 of file ResourceLoaderModule.php.

References $targets.

◆ getTemplates()

ResourceLoaderModule::getTemplates ( )

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

Returns
array of templates mapping template alias to content

Reimplemented in ResourceLoaderFileModule.

Definition at line 179 of file ResourceLoaderModule.php.

◆ getType()

ResourceLoaderModule::getType ( )

◆ 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 ResourceLoaderWikiModule, ResourceLoaderTestModule, and ResourceLoaderSkinModule.

Definition at line 997 of file ResourceLoaderModule.php.

◆ isRaw()

ResourceLoaderModule::isRaw ( )

Whether this module's JS expects to work without the client-side ResourceLoader module.

Returning true from this function will prevent mw.loader.state() call from being appended to the bottom of the script.

Returns
bool

Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, and ResourceLoaderTestModule.

Definition at line 350 of file ResourceLoaderModule.php.

◆ javaScriptParser()

static ResourceLoaderModule::javaScriptParser ( )
staticprotected
Returns
JSParser

Definition at line 1060 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 1089 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 1074 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 463 of file ResourceLoaderModule.php.

References $cache, $context, $e, DB_MASTER, FormatJson\encode(), getFileDependencies(), ObjectCache\getLocalClusterInstance(), getName(), getRelativePaths(), use, wfDebugLog(), and wfGetDB().

Referenced by ResourceLoaderFileModule\getStyles().

◆ setConfig()

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

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

References $context.

◆ setLogger()

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

Definition at line 210 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$nameName

Definition at line 115 of file ResourceLoaderModule.php.

References $name, and 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 ResourceLoaderTestModule.

Definition at line 1011 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 ResourceLoaderImageModule, ResourceLoaderStartUpModule, ResourceLoaderFileModule, ResourceLoaderUserTokensModule, ResourceLoaderUserOptionsModule, and ResourceLoaderMediaWikiUtilModule.

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

References $cache, $contents, $e, $parser, Xml\encodeJsVar(), getConfig(), ObjectCache\getMainWANInstance(), javaScriptParser(), and use.

Referenced by ResourceLoaderTestModule\getScript(), ResourceLoaderWikiModule\getScript(), ResourceLoaderFileModule\getSkipFunction(), and ResourceLoaderFileModule\readScriptFiles().

Member Data Documentation

◆ $config

◆ $contents

ResourceLoaderModule::$contents = []
protected

◆ $deprecated

array bool ResourceLoaderModule::$deprecated = false
protected

Definition at line 90 of file ResourceLoaderModule.php.

Referenced by getDeprecationInformation().

◆ $fileDeps

ResourceLoaderModule::$fileDeps = []
protected

Definition at line 74 of file ResourceLoaderModule.php.

◆ $jsParser

JSParser ResourceLoaderModule::$jsParser
staticprivate

Lazy-initialized; use self::javaScriptParser()

Definition at line 1016 of file ResourceLoaderModule.php.

Referenced by javaScriptParser().

◆ $logger

LoggerInterface ResourceLoaderModule::$logger
protected

Definition at line 95 of file ResourceLoaderModule.php.

Referenced by getLogger(), and setLogger().

◆ $msgBlobs

ResourceLoaderModule::$msgBlobs = []
protected

Definition at line 76 of file ResourceLoaderModule.php.

◆ $name

◆ $origin

ResourceLoaderModule::$origin = self::ORIGIN_CORE_SITEWIDE
protected

Definition at line 66 of file ResourceLoaderModule.php.

Referenced by getOrigin().

◆ $parseCacheVersion

ResourceLoaderModule::$parseCacheVersion = 1
staticprivate

Definition at line 1017 of file ResourceLoaderModule.php.

◆ $targets

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

Definition at line 71 of file ResourceLoaderModule.php.

Referenced by getTargets().

◆ $versionHash

ResourceLoaderModule::$versionHash = []
protected

◆ LOAD_GENERAL

const ResourceLoaderModule::LOAD_GENERAL = 'general'

◆ LOAD_STYLES

◆ ORIGIN_ALL

const ResourceLoaderModule::ORIGIN_ALL = 10

Definition at line 60 of file ResourceLoaderModule.php.

Referenced by OutputPage\getAllowedModules().

◆ ORIGIN_CORE_INDIVIDUAL

const ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL = 2

Definition at line 50 of file ResourceLoaderModule.php.

Referenced by OutputPage\disallowUserJs().

◆ ORIGIN_CORE_SITEWIDE

const ResourceLoaderModule::ORIGIN_CORE_SITEWIDE = 1

Definition at line 47 of file ResourceLoaderModule.php.

◆ ORIGIN_USER_INDIVIDUAL

const ResourceLoaderModule::ORIGIN_USER_INDIVIDUAL = 4

Definition at line 57 of file ResourceLoaderModule.php.

◆ ORIGIN_USER_SITEWIDE

const ResourceLoaderModule::ORIGIN_USER_SITEWIDE = 3

Definition at line 54 of file ResourceLoaderModule.php.

Referenced by OutputPage\disallowUserJs().

◆ TYPE_COMBINED

const ResourceLoaderModule::TYPE_COMBINED = 'combined'

◆ TYPE_SCRIPTS

◆ TYPE_STYLES


The documentation for this class was generated from the following file:
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:32
ResourceLoaderModule\supportsURLLoading
supportsURLLoading()
Whether this module supports URL loading.
Definition: ResourceLoaderModule.php:260
ResourceLoaderModule\getStyleURLsForDebug
getStyleURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's CSS in debug mode.
Definition: ResourceLoaderModule.php:286
ResourceLoaderModule\getModifiedTime
getModifiedTime(ResourceLoaderContext $context)
Get this module's last modification timestamp for a given context.
Definition: ResourceLoaderModule.php:938
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2581
captcha-old.count
count
Definition: captcha-old.py:249
well
page as well
Definition: All_system_messages.txt:2725
ResourceLoaderModule\getHeaders
getHeaders(ResourceLoaderContext $context)
Get headers to send as part of a module web response.
Definition: ResourceLoaderModule.php:603
ResourceLoaderModule\getStyles
getStyles(ResourceLoaderContext $context)
Get all CSS for this module for a given skin.
Definition: ResourceLoaderModule.php:272
ResourceLoaderModule\getTemplates
getTemplates()
Takes named templates by the module and returns an array mapping.
Definition: ResourceLoaderModule.php:179
key
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
a
</source > ! result< div class="mw-highlight mw-content-ltr" dir="ltr">< pre >< span ></span >< span class="kd"> var</span >< span class="nx"> a</span >< span class="p"></span ></pre ></div > ! end ! test Multiline< source/> in lists !input *< source > a b</source > *foo< source > a b</source > ! html< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! html tidy< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! end ! test Custom attributes !input< source lang="javascript" id="foo" class="bar" dir="rtl" style="font-size: larger;"> var a
Definition: parserTests.txt:89
ResourceLoaderModule\getScript
getScript(ResourceLoaderContext $context)
Get all JS for this module for a given language and skin.
Definition: ResourceLoaderModule.php:169
$blob
$blob
Definition: testCompression.php:63
contents
Some information about database access in MediaWiki By Tim January Database layout For information about the MediaWiki database such as a description of the tables and their contents
Definition: database.txt:2
by
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed by
Definition: APACHE-LICENSE-2.0.txt:49
ResourceLoaderModule\getMessageBlob
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
Definition: ResourceLoaderModule.php:559
code
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a third party developers and administrators to define code that will be run at certain points in the mainline code
Definition: hooks.txt:23
see
Some information about database access in MediaWiki By Tim January Database layout For information about the MediaWiki database such as a description of the tables and their please see
Definition: database.txt:2
DerivativeResourceLoaderContext
Allows changing specific properties of a context object, without changing the main one.
Definition: DerivativeResourceLoaderContext.php:30
ResourceLoaderModule\getModifiedHash
getModifiedHash(ResourceLoaderContext $context)
Helper method for providing a version hash to getVersionHash().
Definition: ResourceLoaderModule.php:949
ResourceLoaderModule\getDefinitionSummary
getDefinitionSummary(ResourceLoaderContext $context)
Get a list of resources that web browsers may preload.
Definition: ResourceLoaderModule.php:924
Example
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory Example
Definition: maintenance.txt:1
ResourceLoaderModule\getScriptURLsForDebug
getScriptURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's JS in debug mode.
Definition: ResourceLoaderModule.php:239
values
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition: hooks.txt:175
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ResourceLoaderModule\getName
getName()
Get this module's name.
Definition: ResourceLoaderModule.php:105
array
the array() calling protocol came about after MediaWiki 1.4rc1.