MediaWiki
1.23.2
|
Abstraction for resource loader modules, with name registration and maxage functionality. More...
Public Member Functions | |
getDefinitionMtime (ResourceLoaderContext $context) | |
Helper method for calculating when this module's definition summary was last changed. More... | |
getDefinitionSummary (ResourceLoaderContext $context) | |
Get the definition summary for this module. More... | |
getDependencies () | |
Get a list of modules this module depends on. More... | |
getFileDependencies ( $skin) | |
Get the files this module depends on indirectly for a given skin. More... | |
getFlip ( $context) | |
getGroup () | |
Get the group this module is in. More... | |
getHashMtime (ResourceLoaderContext $context) | |
Helper method for calculating when the module's hash (if it has one) changed. More... | |
getLoaderScript () | |
Get the loader JS for this module, if set. More... | |
getMessages () | |
Get the messages needed for this module. More... | |
getModifiedHash (ResourceLoaderContext $context) | |
Get the hash for whatever this module may contain. More... | |
getModifiedTime (ResourceLoaderContext $context) | |
Get this module's last modification timestamp for a given combination of language, skin and debug mode flag. More... | |
getMsgBlobMtime ( $lang) | |
Get the last modification timestamp of the message blob for this module in a given language. More... | |
getName () | |
Get this module's name. More... | |
getOrigin () | |
Get this module's origin. More... | |
getPosition () | |
Where on the HTML page should this module's JS 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... | |
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... | |
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... | |
setFileDependencies ( $skin, $deps) | |
Set preloaded file dependency information. More... | |
setMsgBlobMtime ( $lang, $mtime) | |
Set a preloaded message blob last modification timestamp. More... | |
setName ( $name) | |
Set this module's name. More... | |
setOrigin ( $origin) | |
Set this module's origin. More... | |
supportsURLLoading () | |
Whether this module supports URL loading. More... | |
Public Attributes | |
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_MESSAGES = 'messages' |
const | TYPE_SCRIPTS = 'scripts' |
const | TYPE_STYLES = 'styles' |
Protected Member Functions | |
validateScriptFile ( $fileName, $contents) | |
Validate a given script file; if valid returns the original source. More... | |
Static Protected Member Functions | |
static | javaScriptParser () |
static | safeFilemtime ( $filename) |
Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist but returns 1 instead. More... | |
Protected Attributes | |
$fileDeps = array() | |
$msgBlobMtime = array() | |
$name = null | |
$origin = self::ORIGIN_CORE_SITEWIDE | |
$targets = array( 'desktop' ) | |
Static Private Attributes | |
static | $jsParser |
static | $parseCacheVersion = 1 |
Abstraction for resource loader modules, with name registration and maxage functionality.
Definition at line 28 of file ResourceLoaderModule.php.
ResourceLoaderModule::getDefinitionMtime | ( | ResourceLoaderContext | $context | ) |
Helper method for calculating when this module's definition summary was last changed.
Definition at line 447 of file ResourceLoaderModule.php.
References $cache, $hash, $summary, $timestamp, CACHE_ANYTHING, getDefinitionSummary(), getName(), wfDebugLog(), wfGetCache(), wfMemcKey(), wfProfileIn(), and wfProfileOut().
Referenced by ResourceLoaderWikiModule\getModifiedTime(), and ResourceLoaderFileModule\getModifiedTime().
ResourceLoaderModule::getDefinitionSummary | ( | ResourceLoaderContext | $context | ) |
Get the definition summary for this module.
This is the method subclasses should implement if they want to make use of getDefinitionMTime() inside getModifiedTime().
Return an array containing values from all significant properties of this module's definition. Be sure to include things that are explicitly ordered, in their actaul order (bug 37812).
Avoid including things that are insiginificant (e.g. order of message keys is insignificant and should be sorted to avoid unnecessary cache invalidation).
Avoid including things already considered by other methods inside your getModifiedTime(), such as file mtime timestamps.
Serialisation is done using json_encode, which means object state is not taken into account when building the hash. This data structure must only contain arrays and scalars as values (avoid object instances) which means it requires abstraction.
Reimplemented in ResourceLoaderFileModule, and ResourceLoaderWikiModule.
Definition at line 510 of file ResourceLoaderModule.php.
References array().
Referenced by getDefinitionMtime().
ResourceLoaderModule::getDependencies | ( | ) |
Get a list of modules this module depends on.
Dependency information is taken into account when loading a module on the client side.
To add dependencies dynamically on the client side, use a custom loader script, see getLoaderScript()
Reimplemented in ResourceLoaderFileModule, ResourceLoaderLanguageDataModule, ResourceLoaderUserCSSPrefsModule, and ResourceLoaderTestModule.
Definition at line 283 of file ResourceLoaderModule.php.
References array().
ResourceLoaderModule::getFileDependencies | ( | $skin | ) |
Get the files this module depends on indirectly for a given skin.
Currently these are only image files referenced by the module's CSS.
string | $skin | Skin name |
Definition at line 304 of file ResourceLoaderModule.php.
References $dbr, $skin, array(), DB_SLAVE, FormatJson\decode(), getName(), and wfGetDB().
Referenced by ResourceLoaderFileModule\getModifiedTime(), and ResourceLoaderFileModule\getStyles().
ResourceLoaderModule::getFlip | ( | $context | ) |
ResourceLoaderContext | $context |
Reimplemented in ResourceLoaderFileModule.
Definition at line 115 of file ResourceLoaderModule.php.
References $wgContLang, and global.
Referenced by ResourceLoaderUserCSSPrefsModule\getStyles(), and ResourceLoaderWikiModule\getStyles().
ResourceLoaderModule::getGroup | ( | ) |
Get the group this module is in.
Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, ResourceLoaderUserCSSPrefsModule, ResourceLoaderUserModule, ResourceLoaderUserGroupsModule, ResourceLoaderUserOptionsModule, ResourceLoaderUserTokensModule, ResourceLoaderSiteModule, ResourceLoaderTestModule, and ResourceLoaderNoscriptModule.
Definition at line 226 of file ResourceLoaderModule.php.
ResourceLoaderModule::getHashMtime | ( | ResourceLoaderContext | $context | ) |
Helper method for calculating when the module's hash (if it has one) changed.
ResourceLoaderContext | $context |
Definition at line 404 of file ResourceLoaderModule.php.
References $cache, $hash, $timestamp, array(), CACHE_ANYTHING, getModifiedHash(), getName(), wfGetCache(), wfMemcKey(), and wfTimestamp().
Referenced by ResourceLoaderLanguageDataModule\getModifiedTime(), and ResourceLoaderStartUpModule\getModifiedTime().
ResourceLoaderModule::getLoaderScript | ( | ) |
Get the loader JS for this module, if set.
Reimplemented in ResourceLoaderFileModule.
Definition at line 268 of file ResourceLoaderModule.php.
ResourceLoaderModule::getMessages | ( | ) |
Get the messages needed for this module.
To get a JSON blob with messages, use MessageBlobStore::get()
Reimplemented in ResourceLoaderFileModule.
Definition at line 216 of file ResourceLoaderModule.php.
References array().
Referenced by MessageBlobStore\generateMessageBlob(), getMsgBlobMtime(), and MessageBlobStore\insertMessageBlob().
ResourceLoaderModule::getModifiedHash | ( | ResourceLoaderContext | $context | ) |
Get the hash for whatever this module may contain.
This is the method subclasses should implement if they want to make use of getHashMTime() inside getModifiedTime().
ResourceLoaderContext | $context |
Reimplemented in ResourceLoaderStartUpModule, and ResourceLoaderLanguageDataModule.
Definition at line 437 of file ResourceLoaderModule.php.
Referenced by getHashMtime().
ResourceLoaderModule::getModifiedTime | ( | ResourceLoaderContext | $context | ) |
Get this module's last modification timestamp for a given combination of language, skin and debug mode flag.
This is typically the highest of each of the relevant components' modification timestamps. Whenever anything happens that changes the module's contents for these parameters, the mtime should increase.
NOTE: The mtime of the module's messages is NOT automatically included. If you want this to happen, you'll need to call getMsgBlobMtime() yourself and take its result into consideration.
NOTE: The mtime of the module's hash is NOT automatically included. If your module provides a getModifiedHash() method, you'll need to call getHashMtime() yourself and take its result into consideration.
ResourceLoaderContext | $context | Context object |
Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, ResourceLoaderWikiModule, ResourceLoaderLanguageDataModule, ResourceLoaderUserOptionsModule, and ResourceLoaderUserCSSPrefsModule.
Definition at line 392 of file ResourceLoaderModule.php.
ResourceLoaderModule::getMsgBlobMtime | ( | $lang | ) |
Get the last modification timestamp of the message blob for this module in a given language.
string | $lang | Language code |
Definition at line 340 of file ResourceLoaderModule.php.
References $dbr, $msgBlobMtime, array(), DB_SLAVE, getMessages(), getName(), TS_UNIX, wfGetDB(), wfTimestamp(), and wfTimestampNow().
Referenced by ResourceLoaderWikiModule\getModifiedTime(), and ResourceLoaderFileModule\getModifiedTime().
ResourceLoaderModule::getName | ( | ) |
Get this module's name.
This is set when the module is registered with ResourceLoader::register()
Definition at line 76 of file ResourceLoaderModule.php.
References $name.
Referenced by getDefinitionMtime(), getFileDependencies(), getHashMtime(), getMsgBlobMtime(), getScriptURLsForDebug(), ResourceLoaderFileModule\getStyles(), and getStyleURLsForDebug().
ResourceLoaderModule::getOrigin | ( | ) |
Get this module's origin.
This is set when the module is registered with ResourceLoader::register()
Definition at line 97 of file ResourceLoaderModule.php.
References $origin.
Referenced by OutputPage\filterModules().
ResourceLoaderModule::getPosition | ( | ) |
Where on the HTML page should this module's JS be loaded?
Reimplemented in ResourceLoaderFileModule.
Definition at line 248 of file ResourceLoaderModule.php.
ResourceLoaderModule::getScript | ( | ResourceLoaderContext | $context | ) |
Get all JS for this module for a given language and skin.
Includes all relevant JS except loader scripts.
ResourceLoaderContext | $context |
Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, ResourceLoaderWikiModule, ResourceLoaderLanguageDataModule, ResourceLoaderUserOptionsModule, and ResourceLoaderUserTokensModule.
Definition at line 128 of file ResourceLoaderModule.php.
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.
ResourceLoaderContext | $context |
Reimplemented in ResourceLoaderFileModule.
Definition at line 147 of file ResourceLoaderModule.php.
References array(), ResourceLoaderContext\getLanguage(), getName(), ResourceLoaderContext\getRequest(), ResourceLoaderContext\getSkin(), ResourceLoaderContext\getUser(), ResourceLoaderContext\getVersion(), and ResourceLoader\makeLoaderURL().
ResourceLoaderModule::getSource | ( | ) |
Get the origin of this module.
Should only be overridden for foreign modules.
Reimplemented in ResourceLoaderTestModule.
Definition at line 236 of file ResourceLoaderModule.php.
ResourceLoaderModule::getStyles | ( | ResourceLoaderContext | $context | ) |
Get all CSS for this module for a given skin.
ResourceLoaderContext | $context |
Reimplemented in ResourceLoaderFileModule, ResourceLoaderWikiModule, and ResourceLoaderUserCSSPrefsModule.
Definition at line 180 of file ResourceLoaderModule.php.
References array().
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()
ResourceLoaderContext | $context |
Reimplemented in ResourceLoaderFileModule.
Definition at line 194 of file ResourceLoaderModule.php.
References array(), ResourceLoaderContext\getLanguage(), getName(), ResourceLoaderContext\getRequest(), ResourceLoaderContext\getSkin(), ResourceLoaderContext\getUser(), ResourceLoaderContext\getVersion(), and ResourceLoader\makeLoaderURL().
ResourceLoaderModule::getTargets | ( | ) |
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Reimplemented in ResourceLoaderFileModule.
Definition at line 293 of file ResourceLoaderModule.php.
References $targets.
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.
ResourceLoaderContext | $context |
Reimplemented in ResourceLoaderWikiModule.
Definition at line 525 of file ResourceLoaderModule.php.
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.
Reimplemented in ResourceLoaderFileModule, and ResourceLoaderStartUpModule.
Definition at line 259 of file ResourceLoaderModule.php.
|
staticprotected |
Definition at line 573 of file ResourceLoaderModule.php.
References $jsParser.
Referenced by validateScriptFile().
|
staticprotected |
Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist but returns 1 instead.
string | $filename | File name |
Definition at line 586 of file ResourceLoaderModule.php.
ResourceLoaderModule::setFileDependencies | ( | $skin, | |
$deps | |||
) |
Set preloaded file dependency information.
Used so we can load this information for all modules at once.
string | $skin | Skin name |
array | $deps | Array of file names |
Definition at line 330 of file ResourceLoaderModule.php.
References $skin.
ResourceLoaderModule::setMsgBlobMtime | ( | $lang, | |
$mtime | |||
) |
Set a preloaded message blob last modification timestamp.
Used so we can load this information for all modules at once.
string | $lang | Language code |
$mtime | Integer: UNIX timestamp or 0 if there is no such blob |
Definition at line 368 of file ResourceLoaderModule.php.
ResourceLoaderModule::setName | ( | $name | ) |
Set this module's name.
This is called by ResourceLoader::register() when registering the module. Other code should not call this.
string | $name | Name |
Definition at line 86 of file ResourceLoaderModule.php.
ResourceLoaderModule::setOrigin | ( | $origin | ) |
Set this module's origin.
This is called by ResourceLoader::register() when registering the module. Other code should not call this.
int | $origin | origin |
Definition at line 107 of file ResourceLoaderModule.php.
References $origin.
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.
Reimplemented in ResourceLoaderStartUpModule, ResourceLoaderFileModule, ResourceLoaderUserOptionsModule, and ResourceLoaderUserTokensModule.
Definition at line 168 of file ResourceLoaderModule.php.
|
protected |
Validate a given script file; if valid returns the original source.
If invalid, returns replacement JS source that throws an exception.
string | $fileName | |
string | $contents |
Definition at line 541 of file ResourceLoaderModule.php.
References $cache, $e, $parser, CACHE_ANYTHING, Xml\encodeJsVar(), global, javaScriptParser(), wfGetCache(), and wfMemcKey().
Referenced by ResourceLoaderWikiModule\getScript(), and ResourceLoaderFileModule\readScriptFiles().
|
protected |
Definition at line 64 of file ResourceLoaderModule.php.
|
staticprivate |
Definition at line 530 of file ResourceLoaderModule.php.
Referenced by javaScriptParser().
|
protected |
Definition at line 66 of file ResourceLoaderModule.php.
Referenced by getMsgBlobMtime().
|
protected |
Definition at line 60 of file ResourceLoaderModule.php.
Referenced by ResourceLoaderStartUpModule\getConfig(), ResourceLoaderStartUpModule\getModifiedTime(), ResourceLoaderStartUpModule\getModuleRegistrations(), getName(), and setName().
|
protected |
Definition at line 56 of file ResourceLoaderModule.php.
Referenced by getOrigin(), and setOrigin().
|
staticprivate |
Definition at line 531 of file ResourceLoaderModule.php.
|
protected |
Definition at line 61 of file ResourceLoaderModule.php.
Referenced by getTargets().
const ResourceLoaderModule::ORIGIN_ALL = 10 |
Definition at line 50 of file ResourceLoaderModule.php.
Referenced by OutputPage\getAllowedModules().
const ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL = 2 |
Definition at line 40 of file ResourceLoaderModule.php.
Referenced by OutputPage\disallowUserJs().
const ResourceLoaderModule::ORIGIN_CORE_SITEWIDE = 1 |
Definition at line 37 of file ResourceLoaderModule.php.
const ResourceLoaderModule::ORIGIN_USER_INDIVIDUAL = 4 |
Definition at line 47 of file ResourceLoaderModule.php.
Referenced by OutputPage\isUserJsAllowed().
const ResourceLoaderModule::ORIGIN_USER_SITEWIDE = 3 |
Definition at line 44 of file ResourceLoaderModule.php.
const ResourceLoaderModule::TYPE_COMBINED = 'combined' |
Definition at line 34 of file ResourceLoaderModule.php.
Referenced by OutputPage\getAllowedModules(), OutputPage\getHeadScripts(), OutputPage\getScriptsForBottomQueue(), and OutputPage\makeResourceLoaderLink().
const ResourceLoaderModule::TYPE_MESSAGES = 'messages' |
Definition at line 33 of file ResourceLoaderModule.php.
Referenced by OutputPage\getHeadScripts(), and OutputPage\getScriptsForBottomQueue().
const ResourceLoaderModule::TYPE_SCRIPTS = 'scripts' |
Definition at line 31 of file ResourceLoaderModule.php.
Referenced by OutputPage\disallowUserJs(), OutputPage\getHeadScripts(), OutputPage\getScriptsForBottomQueue(), OutputPage\isUserJsAllowed(), and OutputPage\makeResourceLoaderLink().
const ResourceLoaderModule::TYPE_STYLES = 'styles' |
Definition at line 32 of file ResourceLoaderModule.php.
Referenced by OutputPage\buildCssLinks(), and OutputPage\makeResourceLoaderLink().