MediaWiki
REL1_19
|
Dynamic JavaScript and CSS resource loading system. More...
Public Member Functions | |
__construct () | |
Registers core modules and runs registration hooks. | |
addSource ($id, $properties=null) | |
Add a foreign source of modules. | |
getModule ($name) | |
Get the ResourceLoaderModule object for a given module name. | |
getModuleNames () | |
Get a list of module names. | |
getSources () | |
Get the list of sources. | |
getTestModuleNames ($framework= 'all') | |
Get a list of test module names for one (or all) frameworks. | |
makeModuleResponse (ResourceLoaderContext $context, array $modules, $missing=array()) | |
Generates code for a response. | |
preloadModuleInfo (array $modules, ResourceLoaderContext $context) | |
Loads information stored in the database about modules. | |
register ($name, $info=null) | |
Registers a module with the ResourceLoader system. | |
registerTestModules () | |
respond (ResourceLoaderContext $context) | |
Outputs a response to a resource load-request, including a content-type header. | |
Static Public Member Functions | |
static | inDebugMode () |
Determine whether debug mode was requested Order of priority is 1) request param, 2) cookie, 3) $wg setting. | |
static | makeCombinedStyles (array $styles) |
Combines an associative array mapping media type to CSS into a single stylesheet with blocks. | |
static | makeConfigSetScript (array $configuration) |
Returns JS code which will set the MediaWiki configuration array to the given value. | |
static | makeCustomLoaderScript ($name, $version, $dependencies, $group, $source, $script) |
Returns JS code which calls the script given by $script. | |
static | makeLoaderConditionalScript ($script) |
Returns JS code which runs given JS code if the client-side framework is present. | |
static | makeLoaderImplementScript ($name, $scripts, $styles, $messages) |
Returns JS code to call to mw.loader.implement for a module with given properties. | |
static | makeLoaderQuery ($modules, $lang, $skin, $user=null, $version=null, $debug=false, $only=null, $printable=false, $handheld=false, $extraQuery=array()) |
Build a query array (array representation of query string) for load.php. | |
static | makeLoaderRegisterScript ($name, $version=null, $dependencies=null, $group=null, $source=null) |
Returns JS code which calls mw.loader.register with the given parameters. | |
static | makeLoaderSourcesScript ($id, $properties=null) |
Returns JS code which calls mw.loader.addSource() with the given parameters. | |
static | makeLoaderStateScript ($name, $state=null) |
Returns a JS call to mw.loader.state, which sets the state of a module or modules to a given value. | |
static | makeLoaderURL ($modules, $lang, $skin, $user=null, $version=null, $debug=false, $only=null, $printable=false, $handheld=false, $extraQuery=array()) |
Build a load.php URL. | |
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 | |
filter ($filter, $data) | |
Runs JavaScript or CSS data through a filter, caching the filtered result for future calls. | |
formatException ($e) | |
Handle exception display. | |
makeComment ($text) | |
sendResponseHeaders (ResourceLoaderContext $context, $mtime) | |
Send content type and last modified headers to the client. | |
tryRespondFromFileCache (ResourceFileCache $fileCache, ResourceLoaderContext $context) | |
Send out code for a response from file cache if possible. | |
tryRespondLastModified (ResourceLoaderContext $context, $mtime) | |
If there's an If-Modified-Since header, respond with a 304 appropriately and clear out the output buffer. | |
Protected Attributes | |
$moduleInfos = array() | |
Associative array mapping module name to info associative array. | |
$modules = array() | |
Array: List of module name/ResourceLoaderModule object pairs. | |
$sources = array() | |
array( 'source-id' => array( 'loadScript' => 'http://.../load.php' ) ) | |
$testModuleNames = array() | |
Associative array mapping framework ids to a list of names of test suite modules. | |
Static Protected Attributes | |
static | $filterCacheVersion = 7 |
static | $requiredSourceProperties = array( 'loadScript' ) |
Dynamic JavaScript and CSS resource loading system.
Most of the documention is on the MediaWiki documentation wiki starting at: http://www.mediawiki.org/wiki/ResourceLoader
Definition at line 29 of file ResourceLoader.php.
Registers core modules and runs registration hooks.
Definition at line 189 of file ResourceLoader.php.
References $IP, $wgEnableJavaScriptTest, $wgLoadScript, $wgResourceLoaderSources, $wgResourceModules, addSource(), registerTestModules(), wfProfileIn(), wfProfileOut(), wfRunHooks(), and wfScript().
ResourceLoader::addSource | ( | $ | id, |
$ | properties = null |
||
) |
Add a foreign source of modules.
Source properties: 'loadScript': URL (either fully-qualified or protocol-relative) of load.php for this source
$id | Mixed: source ID (string), or array( id1 => props1, id2 => props2, ... ) |
$properties | Array: source properties |
Definition at line 311 of file ResourceLoader.php.
Referenced by __construct().
ResourceLoader::filter | ( | $ | filter, |
$ | data | ||
) | [protected] |
Runs JavaScript or CSS data through a filter, caching the filtered result for future calls.
Available filters are:
$filter | String: Name of filter to run |
$data | String: Text to filter, such as JavaScript or CSS text |
Definition at line 132 of file ResourceLoader.php.
References $result, $wgResourceLoaderMinifierMaxLineLength, $wgResourceLoaderMinifierStatementsOnOwnLine, formatException(), JavaScriptMinifier\minify(), CSSMin\minify(), wfGetCache(), wfMemcKey(), wfProfileIn(), and wfProfileOut().
Referenced by makeModuleResponse().
ResourceLoader::formatException | ( | $ | e | ) | [protected] |
Handle exception display.
Exception | $e | to be shown to the user |
Definition at line 660 of file ResourceLoader.php.
References $wgShowExceptionDetails, makeComment(), and wfMessage().
Referenced by filter(), makeModuleResponse(), and respond().
ResourceLoader::getModule | ( | $ | name | ) |
Get the ResourceLoaderModule object for a given module name.
$name | String: Module name |
Definition at line 372 of file ResourceLoader.php.
Referenced by MessageBlobStore\getFromDB(), preloadModuleInfo(), respond(), and ResourceLoaderTest\testRegisteredValidModulesAreAccessible().
Get a list of module names.
Definition at line 343 of file ResourceLoader.php.
Get the list of sources.
Definition at line 403 of file ResourceLoader.php.
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.
$framework | String: Optional. Get only the test module names for one particular framework. |
Definition at line 356 of file ResourceLoader.php.
static ResourceLoader::inDebugMode | ( | ) | [static] |
Determine whether debug mode was requested Order of priority is 1) request param, 2) cookie, 3) $wg setting.
Definition at line 1040 of file ResourceLoader.php.
References $wgResourceLoaderDebug.
Referenced by OutputPage\makeResourceLoaderLink().
static ResourceLoader::makeCombinedStyles | ( | array $ | styles | ) | [static] |
Combines an associative array mapping media type to CSS into a single stylesheet with blocks.
$styles | Array: List of CSS strings keyed by media type |
Definition at line 861 of file ResourceLoader.php.
References $out, and OutputPage\transformCssMedia().
Referenced by makeModuleResponse().
ResourceLoader::makeComment | ( | $ | text | ) | [protected] |
Definition at line 649 of file ResourceLoader.php.
Referenced by formatException(), and respond().
static ResourceLoader::makeConfigSetScript | ( | array $ | configuration | ) | [static] |
Returns JS code which will set the MediaWiki configuration array to the given value.
$configuration | Array: List of configuration values keyed by variable name |
Definition at line 1005 of file ResourceLoader.php.
References Xml\encodeJsCall().
Referenced by MWDebug\getDebugHTML(), OutputPage\getHeadScripts(), and Skin\makeVariablesScript().
static ResourceLoader::makeCustomLoaderScript | ( | $ | name, |
$ | version, | ||
$ | dependencies, | ||
$ | group, | ||
$ | source, | ||
$ | script | ||
) | [static] |
Returns JS code which calls the script given by $script.
The script will be called with local variables name, version, dependencies and group, which will have values corresponding to $name, $version, $dependencies and $group as supplied.
$name | String: Module name |
$version | Integer: Module version number as a timestamp |
$dependencies | Array: List of module names on which this module depends |
$group | String: Group which the module is in. |
$source | String: Source of the module, or 'local' if not foreign. |
$script | String: JavaScript code |
Definition at line 918 of file ResourceLoader.php.
References $version, and Xml\encodeJsCall().
Referenced by ResourceLoaderStartUpModule\getModuleRegistrations().
static ResourceLoader::makeLoaderConditionalScript | ( | $ | script | ) | [static] |
Returns JS code which runs given JS code if the client-side framework is present.
$script | String: JavaScript code |
Definition at line 993 of file ResourceLoader.php.
Referenced by ProtectionForm\buildCleanupScript(), MWDebug\getDebugHTML(), EditPage\getEditToolbar(), OutputPage\getHeadScripts(), OutputPage\getScriptsForBottomQueue(), OutputPage\makeResourceLoaderLink(), and Skin\makeVariablesScript().
static ResourceLoader::makeLoaderImplementScript | ( | $ | name, |
$ | scripts, | ||
$ | styles, | ||
$ | messages | ||
) | [static] |
Returns JS code to call to mw.loader.implement for a module with given properties.
$name | Module name |
$scripts | Mixed: List of URLs to JavaScript files or String of JavaScript code |
$styles | Mixed: List of CSS strings keyed by media type, or list of lists of URLs to CSS files keyed by media type |
$messages | Mixed: List 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. |
Definition at line 825 of file ResourceLoader.php.
References $messages, and Xml\encodeJsCall().
Referenced by makeModuleResponse().
static ResourceLoader::makeLoaderQuery | ( | $ | modules, |
$ | lang, | ||
$ | skin, | ||
$ | user = null , |
||
$ | version = null , |
||
$ | debug = false , |
||
$ | only = null , |
||
$ | printable = false , |
||
$ | handheld = false , |
||
$ | extraQuery = array() |
||
) | [static] |
Build a query array (array representation of query string) for load.php.
Helper function for makeLoaderURL().
Definition at line 1081 of file ResourceLoader.php.
References $user, and $version.
Referenced by makeLoaderURL(), and OutputPage\makeResourceLoaderLink().
static ResourceLoader::makeLoaderRegisterScript | ( | $ | name, |
$ | version = null , |
||
$ | dependencies = null , |
||
$ | group = null , |
||
$ | source = null |
||
) | [static] |
Returns JS code which calls mw.loader.register with the given parameters.
Has three calling conventions:
$name | String: Module name |
$version | Integer: Module version number as a timestamp |
$dependencies | Array: List of module names on which this module depends |
$group | String: group which the module is in. |
$source | String: source of the module, or 'local' if not foreign |
Definition at line 950 of file ResourceLoader.php.
References $version, and Xml\encodeJsCall().
Referenced by ResourceLoaderStartUpModule\getModuleRegistrations().
static ResourceLoader::makeLoaderSourcesScript | ( | $ | id, |
$ | properties = null |
||
) | [static] |
Returns JS code which calls mw.loader.addSource() with the given parameters.
Has two calling conventions:
$id | String: source ID |
$properties | Array: source properties (see addSource()) |
Definition at line 977 of file ResourceLoader.php.
References Xml\encodeJsCall().
Referenced by ResourceLoaderStartUpModule\getModuleRegistrations().
static ResourceLoader::makeLoaderStateScript | ( | $ | name, |
$ | state = null |
||
) | [static] |
Returns a JS call to mw.loader.state, which sets the state of a module or modules to a given value.
Has two calling conventions:
$name | string |
$state |
Definition at line 895 of file ResourceLoader.php.
References Xml\encodeJsCall().
Referenced by makeModuleResponse().
static ResourceLoader::makeLoaderURL | ( | $ | modules, |
$ | lang, | ||
$ | skin, | ||
$ | user = null , |
||
$ | version = null , |
||
$ | debug = false , |
||
$ | only = null , |
||
$ | printable = false , |
||
$ | handheld = false , |
||
$ | extraQuery = array() |
||
) | [static] |
Build a load.php URL.
$modules | array of module names (strings) |
$lang | string Language code |
$skin | string Skin name |
$user | string|null User name. If null, the &user= parameter is omitted |
$version | string|null Versioning timestamp |
$debug | bool Whether the request should be in debug mode |
$only | string|null &only= parameter |
$printable | bool Printable mode |
$handheld | bool Handheld mode |
$extraQuery | array Extra query parameters to add |
Definition at line 1064 of file ResourceLoader.php.
References $user, $version, $wgLoadScript, makeLoaderQuery(), wfAppendQuery(), and wfExpandUrl().
Referenced by ResourceLoaderModule\getScriptURLsForDebug(), ResourceLoaderModule\getStyleURLsForDebug(), and OutputPage\makeResourceLoaderLink().
static ResourceLoader::makeMessageSetScript | ( | $ | messages | ) | [static] |
Returns JS code which, when called, will register a given list of messages.
$messages | Mixed: Either an associative array mapping message key to value, or a JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object. |
Definition at line 849 of file ResourceLoader.php.
References $messages, and Xml\encodeJsCall().
Referenced by makeModuleResponse().
ResourceLoader::makeModuleResponse | ( | ResourceLoaderContext $ | context, |
array $ | modules, | ||
$ | missing = array() |
||
) |
Generates code for a response.
$context | ResourceLoaderContext: Context in which to generate a response |
$modules | Array: List of module objects keyed by module name |
$missing | Array: List of unavailable modules (optional) |
Definition at line 678 of file ResourceLoader.php.
References $exceptions, $out, filter(), formatException(), MessageBlobStore\get(), ResourceLoaderContext\getDebug(), ResourceLoaderContext\getLanguage(), ResourceLoaderContext\getOnly(), makeCombinedStyles(), makeLoaderImplementScript(), makeLoaderStateScript(), makeMessageSetScript(), ResourceLoaderContext\shouldIncludeMessages(), ResourceLoaderContext\shouldIncludeScripts(), ResourceLoaderContext\shouldIncludeStyles(), wfProfileIn(), and wfProfileOut().
Referenced by respond().
static ResourceLoader::makePackedModulesString | ( | $ | modules | ) | [static] |
Convert an array of module names to a packed query string.
For example, array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ) becomes 'foo.bar,baz|bar.baz,quux'
$modules | array of module names (strings) |
Definition at line 1017 of file ResourceLoader.php.
Referenced by ResourceLoaderStartUpModule\getScript(), and ResourceLoaderTest\testMakePackedModulesString().
ResourceLoader::preloadModuleInfo | ( | array $ | modules, |
ResourceLoaderContext $ | context | ||
) |
Loads 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.
$modules | Array: List of module names to preload information for |
$context | ResourceLoaderContext: Context to load the information within |
Definition at line 64 of file ResourceLoader.php.
References $dbr, $res, FormatJson\decode(), ResourceLoaderContext\getLanguage(), getModule(), ResourceLoaderContext\getSkin(), wfGetDB(), and wfTimestamp().
Referenced by respond().
ResourceLoader::register | ( | $ | name, |
$ | info = null |
||
) |
Registers a module with the ResourceLoader system.
$name | Mixed: Name of module as a string or List of name/object pairs as an array |
$info | Module info array. For backwards compatibility with 1.17alpha, this may also be a ResourceLoaderModule object. Optional when using multiple-registration calling style. |
MWException,: | If a duplicate module registration is attempted |
MWException,: | If a module name contains illegal characters (pipes or commas) |
MWException,: | If something other than a ResourceLoaderModule is being registered |
Definition at line 227 of file ResourceLoader.php.
References wfProfileIn(), and wfProfileOut().
Referenced by ResourceLoaderTest\testRegisteredValidModulesAreAccessible().
Definition at line 270 of file ResourceLoader.php.
References $IP, $wgEnableJavaScriptTest, wfProfileIn(), wfProfileOut(), and wfRunHooks().
Referenced by __construct().
ResourceLoader::respond | ( | ResourceLoaderContext $ | context | ) |
Outputs a response to a resource load-request, including a content-type header.
$context | ResourceLoaderContext: Context in which a response should be formed |
Definition at line 412 of file ResourceLoader.php.
References $modules, $wgCacheEpoch, $wgUseFileCache, echo, formatException(), ResourceLoaderContext\getDebug(), getModule(), ResourceLoaderContext\getModules(), ResourceLoaderContext\getRequest(), makeComment(), makeModuleResponse(), ResourceFileCache\newFromContext(), preloadModuleInfo(), sendResponseHeaders(), tryRespondFromFileCache(), tryRespondLastModified(), ResourceFileCache\useFileCache(), wfProfileIn(), wfProfileOut(), and wfTimestamp().
ResourceLoader::sendResponseHeaders | ( | ResourceLoaderContext $ | context, |
$ | mtime | ||
) | [protected] |
Send content type and last modified headers to the client.
$context | ResourceLoaderContext |
$mtime | string TS_MW timestamp to use for last-modified |
Definition at line 527 of file ResourceLoader.php.
References $wgResourceLoaderMaxage, ResourceLoaderContext\getDebug(), ResourceLoaderContext\getOnly(), ResourceLoaderContext\getVersion(), and wfTimestamp().
Referenced by respond(), and tryRespondFromFileCache().
ResourceLoader::tryRespondFromFileCache | ( | ResourceFileCache $ | fileCache, |
ResourceLoaderContext $ | context | ||
) | [protected] |
Send out code for a response from file cache if possible.
$fileCache | ObjectFileCache: Cache object for this request URL |
$context | ResourceLoaderContext: Context in which to generate a response |
Definition at line 605 of file ResourceLoader.php.
References $wgResourceLoaderMaxage, FileCacheBase\cacheTimestamp(), echo, FileCacheBase\fetchText(), ResourceLoaderContext\getDebug(), ResourceLoaderContext\getVersion(), FileCacheBase\isCacheGood(), sendResponseHeaders(), tryRespondLastModified(), wfGetDB(), and wfTimestamp().
Referenced by respond().
ResourceLoader::tryRespondLastModified | ( | ResourceLoaderContext $ | context, |
$ | mtime | ||
) | [protected] |
If there's an If-Modified-Since header, respond with a 304 appropriately and clear out the output buffer.
If the client cache is too old then do nothing.
$context | ResourceLoaderContext |
$mtime | string The TS_MW timestamp to check the header against |
Definition at line 564 of file ResourceLoader.php.
References ResourceLoaderContext\getDebug(), ResourceLoaderContext\getRequest(), and wfTimestamp().
Referenced by respond(), and tryRespondFromFileCache().
ResourceLoader::$filterCacheVersion = 7 [static, protected] |
Definition at line 32 of file ResourceLoader.php.
ResourceLoader::$moduleInfos = array() [protected] |
Associative array mapping module name to info associative array.
Definition at line 39 of file ResourceLoader.php.
ResourceLoader::$modules = array() [protected] |
Array: List of module name/ResourceLoaderModule object pairs.
Definition at line 36 of file ResourceLoader.php.
Referenced by respond().
ResourceLoader::$requiredSourceProperties = array( 'loadScript' ) [static, protected] |
Definition at line 33 of file ResourceLoader.php.
ResourceLoader::$sources = array() [protected] |
array( 'source-id' => array( 'loadScript' => 'http://.../load.php' ) )
Definition at line 46 of file ResourceLoader.php.
ResourceLoader::$testModuleNames = array() [protected] |
Associative array mapping framework ids to a list of names of test suite modules.
like array( 'qunit' => array( 'mediawiki.tests.qunit.suites', 'ext.foo.tests', .. ), .. )
Definition at line 43 of file ResourceLoader.php.