MediaWiki REL1_32
ResourceLoader Class Reference

Dynamic JavaScript and CSS resource loading system. More...

Inheritance diagram for ResourceLoader:
Collaboration diagram for ResourceLoader:

Public Member Functions

 __construct (Config $config=null, LoggerInterface $logger=null)
 Register core modules and runs registration hooks.
 
 addSource ( $id, $loadUrl=null)
 Add a foreign source of modules.
 
 createLoaderURL ( $source, ResourceLoaderContext $context, $extraQuery=[])
 Build a load.php URL.
 
 getCombinedVersion (ResourceLoaderContext $context, array $moduleNames)
 Helper method to get and combine versions of multiple modules.
 
 getConfig ()
 
 getLessCompiler ( $vars=[])
 Returns LESS compiler set up for use with MediaWiki.
 
 getLessVars ()
 Get global LESS variables.
 
 getLoadScript ( $source)
 Get the URL to the load.php endpoint for the given ResourceLoader source.
 
 getLogger ()
 
 getMessageBlobStore ()
 
 getModule ( $name)
 Get the ResourceLoaderModule object for a given module name.
 
 getModuleNames ()
 Get a list of module names.
 
 getModulesByMessage ( $messageKey)
 Get names of modules that use a certain message.
 
 getSources ()
 Get the list of sources.
 
 getTestModuleNames ( $framework='all')
 Get a list of test module names for one (or all) frameworks.
 
 isModuleRegistered ( $name)
 Check whether a ResourceLoader module is registered.
 
 makeModuleResponse (ResourceLoaderContext $context, array $modules, array $missing=[])
 Generate code for a response.
 
 makeVersionQuery (ResourceLoaderContext $context)
 Get the expected value of the 'version' query parameter.
 
 outputErrorAndLog (Exception $e, $msg, array $context=[])
 Add an error to the 'errors' array and log it.
 
 preloadModuleInfo (array $moduleNames, ResourceLoaderContext $context)
 Load information stored in the database about modules.
 
 register ( $name, $info=null)
 Register a module with the ResourceLoader system.
 
 registerTestModules ()
 
 respond (ResourceLoaderContext $context)
 Output a response to a load request, including the content-type header.
 
 setLogger (LoggerInterface $logger)
 
 setMessageBlobStore (MessageBlobStore $blobStore)
 

Static Public Member Functions

static clearCache ()
 Reset static members used for caching.
 
static encodeJsonForScript ( $data)
 Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
 
static filter ( $filter, $data, array $options=[])
 Run JavaScript or CSS data through a filter, caching the filtered result for future calls.
 
static formatException ( $e)
 Handle exception display.
 
static inDebugMode ()
 Determine whether debug mode was requested Order of priority is 1) request param, 2) cookie, 3) $wg setting.
 
static isValidModuleName ( $moduleName)
 Check a module name for validity.
 
static makeCombinedStyles (array $stylePairs)
 Combines an associative array mapping media type to CSS into a single stylesheet with "@media" blocks.
 
static makeComment ( $text)
 Generate a CSS or JS comment block.
 
static makeConfigSetScript (array $configuration)
 Returns JS code which will set the MediaWiki configuration array to the given value.
 
static makeHash ( $value)
 
static makeInlineCodeWithModule ( $modules, $script)
 Wraps JavaScript code to run after a required module.
 
static makeInlineScript ( $script, $nonce=null)
 Returns an HTML script tag that runs given JS code after startup and base modules.
 
static makeLoaderConditionalScript ( $script)
 Wraps JavaScript code to run after the startup module.
 
static makeLoaderQuery ( $modules, $lang, $skin, $user=null, $version=null, $debug=false, $only=null, $printable=false, $handheld=false, $extraQuery=[])
 Build a query array (array representation of query string) for load.php.
 
static makeLoaderRegisterScript (array $modules)
 Returns JS code which calls mw.loader.register with the given parameter.
 
static makeLoaderSourcesScript ( $sources, $loadUrl=null)
 Returns JS code which calls mw.loader.addSource() with the given parameters.
 
static makeLoaderStateScript ( $states, $state=null)
 Returns a JS call to mw.loader.state, which sets the state of one ore more modules to a given value.
 
static makeMessageSetScript ( $messages)
 Returns JS code which, when called, will register a given list of messages.
 
static makePackedModulesString ( $modules)
 Convert an array of module names to a packed query string.
 

Protected Member Functions

 isFileModule ( $name)
 Whether the module is a ResourceLoaderFileModule (including subclasses).
 
 measureResponseTime (Timing $timing)
 
 sendResponseHeaders (ResourceLoaderContext $context, $etag, $errors, array $extra=[])
 Send main response headers to the client.
 
 tryRespondFromFileCache (ResourceFileCache $fileCache, ResourceLoaderContext $context, $etag)
 Send out code for a response from file cache if possible.
 
 tryRespondNotModified (ResourceLoaderContext $context, $etag)
 Respond with HTTP 304 Not Modified if appropiate.
 

Static Protected Member Functions

static createLoaderQuery (ResourceLoaderContext $context, $extraQuery=[])
 Helper for createLoaderURL()
 
static formatExceptionNoComment ( $e)
 Handle exception display.
 
static makeLoaderImplementScript ( $name, $scripts, $styles, $messages, $templates)
 Return JS code that calls mw.loader.implement with given module properties.
 

Protected Attributes

MessageBlobStore $blobStore
 
 $config
 
array $errors = []
 Errors accumulated during current respond() call.
 
array $extraHeaders = []
 List of extra HTTP response headers provided by loaded modules.
 
array $moduleInfos = []
 Associative array mapping module name to info associative array.
 
array $modules = []
 Module name/ResourceLoaderModule object pairs.
 
array $sources = []
 E.g.
 
array $testModuleNames = []
 Associative array mapping framework ids to a list of names of test suite modules like [ 'qunit' => [ 'mediawiki.tests.qunit.suites', 'ext.foo.tests', ... ], ... ].
 

Static Protected Attributes

static bool $debugMode = null
 

Private Member Functions

 ensureNewline ( $str)
 Ensure the string is either empty or ends in a line break.
 

Static Private Member Functions

static applyFilter ( $filter, $data)
 
static isEmptyObject (stdClass $obj)
 
static trimArray (array &$array)
 Remove empty values from the end of an array.
 

Private Attributes

LoggerInterface $logger
 

Detailed Description

Dynamic JavaScript and CSS resource loading system.

Most of the documentation is on the MediaWiki documentation wiki starting at: https://www.mediawiki.org/wiki/ResourceLoader

Definition at line 38 of file ResourceLoader.php.

Constructor & Destructor Documentation

◆ __construct()

ResourceLoader::__construct ( Config  $config = null,
LoggerInterface  $logger = null 
)

Register core modules and runs registration hooks.

Parameters
Config | null$config[optional]
LoggerInterface | null$logger[optional]

Reimplemented in EmptyResourceLoader.

Definition at line 242 of file ResourceLoader.php.

References $config, $IP, $logger, addSource(), registerTestModules(), and setMessageBlobStore().

Member Function Documentation

◆ addSource()

ResourceLoader::addSource (   $id,
  $loadUrl = null 
)

Add a foreign source of modules.

Source IDs are typically the same as the Wiki ID or database name (e.g. lowercase a-z).

Parameters
array | string$idSource ID (string), or [ id1 => loadUrl, id2 => loadUrl, ... ]
string | array | null$loadUrlload.php url (string), or array with loadUrl key for backwards-compatibility.
Exceptions
MWException

Definition at line 451 of file ResourceLoader.php.

References $value, and as.

Referenced by __construct(), EmptyResourceLoader\__construct(), and ResourceLoaderTest\testAddSource().

◆ applyFilter()

static ResourceLoader::applyFilter (   $filter,
  $data 
)
staticprivate

Definition at line 222 of file ResourceLoader.php.

References $e, CSSMin\minify(), and JavaScriptMinifier\minify().

Referenced by filter().

◆ clearCache()

static ResourceLoader::clearCache ( )
static

Reset static members used for caching.

Global state and $wgRequest are evil, but we're using it right now and sometimes we need to be able to force ResourceLoader to re-evaluate the context because it has changed (e.g. in the test suite).

Definition at line 1597 of file ResourceLoader.php.

Referenced by OutputPageTest\setUp(), ResourceLoaderTestCase\setUp(), OutputPageTest\tearDown(), and ResourceLoaderTest\testMakeLoaderImplementScript().

◆ createLoaderQuery()

static ResourceLoader::createLoaderQuery ( ResourceLoaderContext  $context,
  $extraQuery = [] 
)
staticprotected

Helper for createLoaderURL()

Since
1.24
See also
makeLoaderQuery
Parameters
ResourceLoaderContext$context
array$extraQuery
Returns
array

Definition at line 1628 of file ResourceLoader.php.

◆ createLoaderURL()

ResourceLoader::createLoaderURL (   $source,
ResourceLoaderContext  $context,
  $extraQuery = [] 
)

Build a load.php URL.

Since
1.24
Parameters
string$sourceName of the ResourceLoader source
ResourceLoaderContext$context
array$extraQuery
Returns
string URL to load.php. May be protocol-relative if $wgLoadScript is, too.

Definition at line 1610 of file ResourceLoader.php.

◆ encodeJsonForScript()

static ResourceLoader::encodeJsonForScript (   $data)
static

Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.

Definition at line 1303 of file ResourceLoader.php.

Referenced by ResourceLoaderClientHtml\getHeadHtml(), and ResourceLoaderStartUpModule\getScript().

◆ ensureNewline()

ResourceLoader::ensureNewline (   $str)
private

Ensure the string is either empty or ends in a line break.

Parameters
string$str
Returns
string

Definition at line 1177 of file ResourceLoader.php.

◆ filter()

static ResourceLoader::filter (   $filter,
  $data,
array  $options = [] 
)
static

Run JavaScript or CSS data through a filter, caching the filtered result for future calls.

Available filters are:

If $data is empty, only contains whitespace or the filter was unknown, $data is returned unmodified.

Parameters
string$filterName of filter to run
string$dataText to filter, such as JavaScript or CSS text
array$optionsKeys:
  • (bool) cache: Whether to allow caching this data. Default: true.
Returns
string Filtered data, or a comment containing an error message

Definition at line 186 of file ResourceLoader.php.

References $cache, $options, applyFilter(), and CACHE_ANYTHING.

Referenced by ResourceLoaderModule\buildContent(), and ResourceLoaderStartUpModule\getModuleRegistrations().

◆ formatException()

static ResourceLoader::formatException (   $e)
static

Handle exception display.

Parameters
Exception$eException to be shown to the user
Returns
string Sanitized text in a CSS/JS comment that can be returned to the user

Definition at line 1003 of file ResourceLoader.php.

References $e.

◆ formatExceptionNoComment()

static ResourceLoader::formatExceptionNoComment (   $e)
staticprotected

Handle exception display.

Since
1.25
Parameters
Exception$eException to be shown to the user
Returns
string Sanitized text that can be returned to the user

Definition at line 1014 of file ResourceLoader.php.

References $e, and $wgShowExceptionDetails.

◆ getCombinedVersion()

ResourceLoader::getCombinedVersion ( ResourceLoaderContext  $context,
array  $moduleNames 
)

Helper method to get and combine versions of multiple modules.

Since
1.26
Parameters
ResourceLoaderContext$context
string[]$moduleNamesList of known module names
Returns
string Hash

Definition at line 654 of file ResourceLoader.php.

References $context, $e, $hashes, and use.

◆ getConfig()

ResourceLoader::getConfig ( )
Returns
Config

Definition at line 278 of file ResourceLoader.php.

References $config.

◆ getLessCompiler()

ResourceLoader::getLessCompiler (   $vars = [])

Returns LESS compiler set up for use with MediaWiki.

Since
1.27
Parameters
array$varsAssociative array of variables that should be used for compilation. Since 1.32, this method no longer automatically includes global LESS vars from ResourceLoader::getLessVars (T191937).
Exceptions
MWException
Returns
Less_Parser

Definition at line 1715 of file ResourceLoader.php.

◆ getLessVars()

ResourceLoader::getLessVars ( )

Get global LESS variables.

Since
1.27
Deprecated:
since 1.32 Use ResourceLoderModule::getLessVars() instead.
Returns
array Map of variable names to string CSS values.

Definition at line 1741 of file ResourceLoader.php.

◆ getLoadScript()

ResourceLoader::getLoadScript (   $source)

Get the URL to the load.php endpoint for the given ResourceLoader source.

Since
1.24
Parameters
string$source
Exceptions
MWExceptionOn an invalid $source name
Returns
string

Definition at line 611 of file ResourceLoader.php.

References $source.

◆ getLogger()

ResourceLoader::getLogger ( )
Since
1.27
Returns
LoggerInterface

Definition at line 294 of file ResourceLoader.php.

References $logger.

Referenced by EmptyResourceLoader\__construct().

◆ getMessageBlobStore()

ResourceLoader::getMessageBlobStore ( )
Since
1.26
Returns
MessageBlobStore

Definition at line 302 of file ResourceLoader.php.

References $blobStore.

Referenced by preloadModuleInfo().

◆ getModule()

ResourceLoader::getModule (   $name)

Get the ResourceLoaderModule object for a given module name.

If an array of module parameters exists but a ResourceLoaderModule object has not yet been instantiated, this method will instantiate and cache that object such that subsequent calls simply return the same object.

Parameters
string$nameModule name
Returns
ResourceLoaderModule|null If module has been registered, return a ResourceLoaderModule instance. Otherwise, return null.

Definition at line 536 of file ResourceLoader.php.

References $name.

Referenced by ResourceLoaderClientHtml\getData(), and preloadModuleInfo().

◆ getModuleNames()

ResourceLoader::getModuleNames ( )

Get a list of module names.

Returns
array List of module names

Definition at line 487 of file ResourceLoader.php.

◆ getModulesByMessage()

ResourceLoader::getModulesByMessage (   $messageKey)

Get names of modules that use a certain message.

Parameters
string$messageKey
Returns
array List of module names

Definition at line 1191 of file ResourceLoader.php.

◆ getSources()

ResourceLoader::getSources ( )

Get the list of sources.

Returns
array Like [ id => load.php url, ... ]

Definition at line 598 of file ResourceLoader.php.

◆ getTestModuleNames()

ResourceLoader::getTestModuleNames (   $framework = 'all')

Get a list of test module names for one (or all) frameworks.

If the given framework id is unknkown, or if the in-object variable is not an array, then it will return an empty array.

Parameters
string$frameworkGet only the test module names for one particular framework (optional)
Returns
array

Definition at line 501 of file ResourceLoader.php.

◆ inDebugMode()

◆ isEmptyObject()

static ResourceLoader::isEmptyObject ( stdClass  $obj)
staticprivate

Definition at line 1348 of file ResourceLoader.php.

◆ isFileModule()

ResourceLoader::isFileModule (   $name)
protected

Whether the module is a ResourceLoaderFileModule (including subclasses).

Parameters
string$nameModule name
Returns
bool

Definition at line 576 of file ResourceLoader.php.

References $name.

◆ isModuleRegistered()

ResourceLoader::isModuleRegistered (   $name)

Check whether a ResourceLoader module is registered.

Since
1.25
Parameters
string$name
Returns
bool

Definition at line 521 of file ResourceLoader.php.

References $name.

◆ isValidModuleName()

static ResourceLoader::isValidModuleName (   $moduleName)
static

Check a module name for validity.

Module names may not contain pipes (|), commas (,) or exclamation marks (!) and can be at most 255 bytes.

Parameters
string$moduleNameModule name to check
Returns
bool Whether $moduleName is a valid module name

Definition at line 1701 of file ResourceLoader.php.

◆ makeCombinedStyles()

static ResourceLoader::makeCombinedStyles ( array  $stylePairs)
static

Combines an associative array mapping media type to CSS into a single stylesheet with "@media" blocks.

Parameters
array$stylePairsArray keyed by media type containing (arrays of) CSS strings
Returns
array

Definition at line 1267 of file ResourceLoader.php.

Referenced by WebInstallerOutput\getCSS().

◆ makeComment()

static ResourceLoader::makeComment (   $text)
static

Generate a CSS or JS comment block.

Only use this for public data, not error message details.

Parameters
string$text
Returns
string

Definition at line 992 of file ResourceLoader.php.

Referenced by ResourceLoaderWikiModule\getScript(), and ResourceLoaderWikiModule\getStyles().

◆ makeConfigSetScript()

static ResourceLoader::makeConfigSetScript ( array  $configuration)
static

Returns JS code which will set the MediaWiki configuration array to the given value.

Parameters
array$configurationList of configuration values keyed by variable name
Returns
string JavaScript code
Exceptions
Exception

Definition at line 1527 of file ResourceLoader.php.

Referenced by SpecialJavaScriptTest\exportQUnit(), OutputPage\getBottomScripts(), MWDebug\getDebugHTML(), ResourceLoaderClientHtml\getHeadHtml(), ResourceLoaderMediaWikiUtilModule\getScript(), ResourceLoaderUploadDialogModule\getScript(), and Skin\makeVariablesScript().

◆ makeHash()

static ResourceLoader::makeHash (   $value)
static
Since
1.26
Parameters
string$value
Returns
string Hash

Definition at line 623 of file ResourceLoader.php.

References $value.

Referenced by ResourceLoaderStartUpModule\getModuleRegistrations(), ResourceLoaderModule\getVersionHash(), and ResourceLoaderTest\testGetCombinedVersion().

◆ makeInlineCodeWithModule()

static ResourceLoader::makeInlineCodeWithModule (   $modules,
  $script 
)
static

Wraps JavaScript code to run after a required module.

Since
1.32
Parameters
string | string[]$modulesModule name(s)
string$scriptJavaScript code
Returns
string JavaScript code

Definition at line 1481 of file ResourceLoader.php.

Referenced by SpecialJavaScriptTest\exportQUnit().

◆ makeInlineScript()

static ResourceLoader::makeInlineScript (   $script,
  $nonce = null 
)
static

Returns an HTML script tag that runs given JS code after startup and base modules.

The code will be wrapped in a closure, and it will be executed by ResourceLoader's startup module if the client has adequate support for MediaWiki JavaScript code.

Parameters
string$scriptJavaScript code
string | null$nonce[optional] Content-Security-Policy nonce (from OutputPage::getCSPNonce)
Returns
string|WrappedString HTML

Definition at line 1500 of file ResourceLoader.php.

Referenced by ResourceLoaderClientHtml\getBodyHtml(), OutputPage\getBottomScripts(), MWDebug\getDebugHTML(), ResourceLoaderClientHtml\getHeadHtml(), ResourceLoaderClientHtml\makeLoad(), and Skin\makeVariablesScript().

◆ makeLoaderConditionalScript()

static ResourceLoader::makeLoaderConditionalScript (   $script)
static

Wraps JavaScript code to run after the startup module.

Parameters
string$scriptJavaScript code
Returns
string JavaScript code

Definition at line 1467 of file ResourceLoader.php.

Referenced by SpecialJavaScriptTest\exportQUnit().

◆ makeLoaderImplementScript()

static ResourceLoader::makeLoaderImplementScript (   $name,
  $scripts,
  $styles,
  $messages,
  $templates 
)
staticprotected

Return JS code that calls mw.loader.implement with given module properties.

Parameters
string$nameModule name or implement key (format "`[name]@[version]`")
XmlJsCode | array | string$scriptsCode as XmlJsCode (to be wrapped in a closure), list of URLs to JavaScript files, or a string of JavaScript for $.globalEval.
mixed$stylesArray of CSS strings keyed by media type, or an array of lists of URLs to CSS files keyed by media type
mixed$messagesList of messages associated with this module. May either be an associative array mapping message key to value, or a JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object.
array$templatesKeys are name of templates and values are the source of the template.
Exceptions
MWException
Returns
string JavaScript code

Definition at line 1218 of file ResourceLoader.php.

◆ makeLoaderQuery()

static ResourceLoader::makeLoaderQuery (   $modules,
  $lang,
  $skin,
  $user = null,
  $version = null,
  $debug = false,
  $only = null,
  $printable = false,
  $handheld = false,
  $extraQuery = [] 
)
static

Build a query array (array representation of query string) for load.php.

Helper function for createLoaderURL().

Parameters
array$modules
string$lang
string$skin
string | null$user
string | null$version
bool$debug
string | null$only
bool$printable
bool$handheld
array$extraQuery
Returns
array

Definition at line 1660 of file ResourceLoader.php.

Referenced by OutputPage\getRlClientContext().

◆ makeLoaderRegisterScript()

static ResourceLoader::makeLoaderRegisterScript ( array  $modules)
static

Returns JS code which calls mw.loader.register with the given parameter.

Example
[ $name1, $version1, $dependencies1, $group1, $source1, $skip1 ],
[ $name2, $version2, $dependencies1, $group2, $source2, $skip2 ],
...
] ):
static makeLoaderRegisterScript(array $modules)
Returns JS code which calls mw.loader.register with the given parameter.

Definition at line 1407 of file ResourceLoader.php.

Referenced by ResourceLoaderStartUpModule\getModuleRegistrations(), and ResourceLoaderTest\testMakeLoaderRegisterScript().

◆ makeLoaderSourcesScript()

static ResourceLoader::makeLoaderSourcesScript (   $sources,
  $loadUrl = null 
)
static

Returns JS code which calls mw.loader.addSource() with the given parameters.

Has two calling conventions:

Parameters
string | array$sourcesSource ID
string | null$loadUrlload.php url
Returns
string JavaScript code

Definition at line 1450 of file ResourceLoader.php.

Referenced by ResourceLoaderStartUpModule\getModuleRegistrations(), and ResourceLoaderTest\testMakeLoaderSourcesScript().

◆ makeLoaderStateScript()

static ResourceLoader::makeLoaderStateScript (   $states,
  $state = null 
)
static

Returns a JS call to mw.loader.state, which sets the state of one ore more modules to a given value.

Has two calling conventions:

Parameters
array | string$states
string | null$state
Returns
string JavaScript code

Definition at line 1337 of file ResourceLoader.php.

Referenced by ResourceLoaderClientHtml\getHeadHtml(), and ResourceLoaderStartUpModule\getModuleRegistrations().

◆ makeMessageSetScript()

static ResourceLoader::makeMessageSetScript (   $messages)
static

Returns JS code which, when called, will register a given list of messages.

Parameters
mixed$messagesEither an associative array mapping message key to value, or a JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object.
Returns
string JavaScript code

Definition at line 1252 of file ResourceLoader.php.

◆ makeModuleResponse()

ResourceLoader::makeModuleResponse ( ResourceLoaderContext  $context,
array  $modules,
array  $missing = [] 
)

Generate code for a response.

Calling this method also populates the errors and headers members, later used by respond().

Parameters
ResourceLoaderContext$contextContext in which to generate a response
ResourceLoaderModule[]$modulesList of module objects keyed by module name
string[]$missingList of requested module names that are unregistered (optional)
Returns
string Response data

Definition at line 1037 of file ResourceLoader.php.

References $content, $context, $e, $image, $modules, $name, $out, as, and errors.

◆ makePackedModulesString()

static ResourceLoader::makePackedModulesString (   $modules)
static

Convert an array of module names to a packed query string.

For example, ‘[ 'foo.bar’, 'foo.baz', 'bar.baz', 'bar.quux' ] becomes'foo.bar,baz|bar.baz,quux'`.

This process is reversed by ResourceLoaderContext::expandModuleNames(). See also mw.loader::buildModulesString() which is a port of this, used on the client-side.

Parameters
array$modulesList of module names (strings)
Returns
string Packed query string

Definition at line 1555 of file ResourceLoader.php.

Referenced by ResourceLoaderTest\testMakePackedModulesString().

◆ makeVersionQuery()

ResourceLoader::makeVersionQuery ( ResourceLoaderContext  $context)

Get the expected value of the 'version' query parameter.

This is used by respond() to set a short Cache-Control header for requests with information newer than the current server has. This avoids pollution of edge caches. Typically during deployment. (T117587)

This MUST match return value of mw.loader#getCombinedVersion() client-side.

Since
1.28
Parameters
ResourceLoaderContext$context
Returns
string Hash

Definition at line 689 of file ResourceLoader.php.

References $context, $name, and as.

◆ measureResponseTime()

ResourceLoader::measureResponseTime ( Timing  $timing)
protected

Definition at line 824 of file ResourceLoader.php.

References Timing\measure(), and use.

◆ outputErrorAndLog()

ResourceLoader::outputErrorAndLog ( Exception  $e,
  $msg,
array  $context = [] 
)

Add an error to the 'errors' array and log it.

Access:\n private For internal use by ResourceLoader and ResourceLoaderStartUpModule.
Since
1.29
Parameters
Exception$e
string$msg
array$context

Definition at line 637 of file ResourceLoader.php.

References $context, $e, and errors.

◆ preloadModuleInfo()

ResourceLoader::preloadModuleInfo ( array  $moduleNames,
ResourceLoaderContext  $context 
)

Load information stored in the database about modules.

This method grabs modules dependencies from the database and updates modules objects.

This is not inside the module code because it is much faster to request all of the information at once than it is to have each module requests its own information. This sacrifice of modularity yields a substantial performance improvement.

Parameters
array$moduleNamesList of module names to preload information for
ResourceLoaderContext$contextContext to load the information within

Definition at line 115 of file ResourceLoader.php.

References $blob, $context, $dbr, $lang, $modules, $name, $res, $skin, as, DB_REPLICA, ResourceLoaderModule\expandRelativePaths(), getMessageBlobStore(), getModule(), and wfGetDB().

◆ register()

ResourceLoader::register (   $name,
  $info = null 
)

Register a module with the ResourceLoader system.

Parameters
mixed$nameName of module as a string or List of name/object pairs as an array
array | null$infoModule info array. For backwards compatibility with 1.17alpha, this may also be a ResourceLoaderModule object. Optional when using multiple-registration calling style.
Exceptions
MWExceptionIf a duplicate module registration is attempted
MWExceptionIf a module name contains illegal characters (pipes or commas)
MWExceptionIf something other than a ResourceLoaderModule is being registered
Returns
bool False if there were any errors, in which case one or more modules were not registered

Definition at line 327 of file ResourceLoader.php.

References $name, $path, array(), as, definition, ResourceLoaderFileModule\extractBasePaths(), from, MessageBlobStore\get(), list, and or.

◆ registerTestModules()

ResourceLoader::registerTestModules ( )

Definition at line 402 of file ResourceLoader.php.

References $IP, and as.

Referenced by __construct().

◆ respond()

ResourceLoader::respond ( ResourceLoaderContext  $context)

Output a response to a load request, including the content-type header.

Parameters
ResourceLoaderContext$contextContext in which a response should be formed

Definition at line 712 of file ResourceLoader.php.

References $context, $e, $modules, $name, $response, as, errors, ResourceFileCache\newFromContext(), and ResourceFileCache\useFileCache().

◆ sendResponseHeaders()

ResourceLoader::sendResponseHeaders ( ResourceLoaderContext  $context,
  $etag,
  $errors,
array  $extra = [] 
)
protected

Send main response headers to the client.

Deals with Content-Type, CORS (for stylesheets), and caching.

Parameters
ResourceLoaderContext$context
string$etagETag header value
bool$errorsWhether there are errors in the response
string[]$extraArray of extra HTTP response headers
Returns
void

Definition at line 845 of file ResourceLoader.php.

References $context, $header, as, and wfTimestamp().

◆ setLogger()

ResourceLoader::setLogger ( LoggerInterface  $logger)
Since
1.26
Parameters
LoggerInterface$logger

Definition at line 286 of file ResourceLoader.php.

References $logger.

Referenced by EmptyResourceLoader\__construct().

◆ setMessageBlobStore()

ResourceLoader::setMessageBlobStore ( MessageBlobStore  $blobStore)
Since
1.25
Parameters
MessageBlobStore$blobStore

Definition at line 310 of file ResourceLoader.php.

References $blobStore.

Referenced by __construct(), and EmptyResourceLoader\__construct().

◆ trimArray()

static ResourceLoader::trimArray ( array $array)
staticprivate

Remove empty values from the end of an array.

Values considered empty:

  • null
  • []
  • new XmlJsCode( '{}' )
  • new stdClass() // (object) []
Parameters
Array$array

Definition at line 1367 of file ResourceLoader.php.

◆ tryRespondFromFileCache()

ResourceLoader::tryRespondFromFileCache ( ResourceFileCache  $fileCache,
ResourceLoaderContext  $context,
  $etag 
)
protected

Send out code for a response from file cache if possible.

Parameters
ResourceFileCache$fileCacheCache object for this request URL
ResourceLoaderContext$contextContext in which to generate a response
string$etagETag header value
Returns
bool If this found a cache file and handled the response

Definition at line 939 of file ResourceLoader.php.

References $context, $e, $response, FileCacheBase\cacheTimestamp(), DB_REPLICA, FileCacheBase\fetchText(), FileCacheBase\isCacheGood(), wfGetDB(), and wfTimestamp().

◆ tryRespondNotModified()

ResourceLoader::tryRespondNotModified ( ResourceLoaderContext  $context,
  $etag 
)
protected

Respond with HTTP 304 Not Modified if appropiate.

If there's an If-None-Match header, respond with a 304 appropriately and clear out the output buffer. If the client cache is too old then do nothing.

Parameters
ResourceLoaderContext$context
string$etagETag header value
Returns
bool True if HTTP 304 was sent and output handled

Definition at line 906 of file ResourceLoader.php.

References $context, HttpStatus\header(), and wfResetOutputBuffers().

Member Data Documentation

◆ $blobStore

MessageBlobStore ResourceLoader::$blobStore
protected

Definition at line 91 of file ResourceLoader.php.

Referenced by getMessageBlobStore(), and setMessageBlobStore().

◆ $config

Config ResourceLoader::$config
protected

Definition at line 58 of file ResourceLoader.php.

Referenced by __construct(), EmptyResourceLoader\__construct(), and getConfig().

◆ $debugMode

bool ResourceLoader::$debugMode = null
staticprotected

Definition at line 43 of file ResourceLoader.php.

◆ $errors

array ResourceLoader::$errors = []
protected

Errors accumulated during current respond() call.

Definition at line 77 of file ResourceLoader.php.

Referenced by EmptyResourceLoader\getErrors().

◆ $extraHeaders

array ResourceLoader::$extraHeaders = []
protected

List of extra HTTP response headers provided by loaded modules.

Populated by makeModuleResponse().

Definition at line 86 of file ResourceLoader.php.

◆ $logger

LoggerInterface ResourceLoader::$logger
private

◆ $moduleInfos

array ResourceLoader::$moduleInfos = []
protected

Associative array mapping module name to info associative array.

Definition at line 55 of file ResourceLoader.php.

◆ $modules

array ResourceLoader::$modules = []
protected

Module name/ResourceLoaderModule object pairs.

Definition at line 49 of file ResourceLoader.php.

Referenced by preloadModuleInfo().

◆ $sources

array ResourceLoader::$sources = []
protected

E.g.

[ 'source-id' => 'http://.../load.php' ]

Definition at line 71 of file ResourceLoader.php.

◆ $testModuleNames

array ResourceLoader::$testModuleNames = []
protected

Associative array mapping framework ids to a list of names of test suite modules like [ 'qunit' => [ 'mediawiki.tests.qunit.suites', 'ext.foo.tests', ... ], ... ].

Definition at line 65 of file ResourceLoader.php.


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