MediaWiki
REL1_19
|
Abstraction for resource loader modules, with name registration and maxage functionality. More...
Public Member Functions | |
getDependencies () | |
Get a list of modules this module depends on. | |
getFileDependencies ($skin) | |
Get the files this module depends on indirectly for a given skin. | |
getFlip ($context) | |
getGroup () | |
Get the group this module is in. | |
getLoaderScript () | |
Get the loader JS for this module, if set. | |
getMessages () | |
Get the messages needed for this module. | |
getModifiedTime (ResourceLoaderContext $context) | |
Get this module's last modification timestamp for a given combination of language, skin and debug mode flag. | |
getMsgBlobMtime ($lang) | |
Get the last modification timestamp of the message blob for this module in a given language. | |
getName () | |
Get this module's name. | |
getOrigin () | |
Get this module's origin. | |
getPosition () | |
Where on the HTML page should this module's JS be loaded? 'top': in the <head> 'bottom': at the bottom of the <body> | |
getScript (ResourceLoaderContext $context) | |
Get all JS for this module for a given language and skin. | |
getScriptURLsForDebug (ResourceLoaderContext $context) | |
Get the URL or URLs to load for this module's JS in debug mode. | |
getSource () | |
Get the origin of this module. | |
getStyles (ResourceLoaderContext $context) | |
Get all CSS for this module for a given skin. | |
getStyleURLsForDebug (ResourceLoaderContext $context) | |
Get the URL or URLs to load for this module's CSS in debug mode. | |
isKnownEmpty (ResourceLoaderContext $context) | |
Check whether this module is known to be empty. | |
setFileDependencies ($skin, $deps) | |
Set preloaded file dependency information. | |
setMsgBlobMtime ($lang, $mtime) | |
Set a preloaded message blob last modification timestamp. | |
setName ($name) | |
Set this module's name. | |
setOrigin ($origin) | |
Set this module's origin. | |
supportsURLLoading () | |
Whether this module supports URL loading. | |
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. | |
Static Protected Member Functions | |
static | javaScriptParser () |
Protected Attributes | |
$fileDeps = array() | |
$msgBlobMtime = array() | |
$name = null | |
$origin = self::ORIGIN_CORE_SITEWIDE | |
Static Private Attributes | |
static | $jsParser |
static | $parseCacheVersion = 1 |
Abstraction for resource loader modules, with name registration and maxage functionality.
Definition at line 26 of file ResourceLoaderModule.php.
Get a list of modules this module depends on.
Dependency information is taken into account when loading a module on the client side. When adding a module on the server side, dependency information is NOT taken into account and YOU are responsible for adding dependent modules as well. If you don't do this, the client side loader will send a second request back to the server to fetch the missing modules, which kind of defeats the purpose of the resource loader.
To add dependencies dynamically on the client side, use a custom loader script, see getLoaderScript()
Reimplemented in ResourceLoaderFileModule, and ResourceLoaderUserCSSPrefsModule.
Definition at line 272 of file ResourceLoaderModule.php.
Get the files this module depends on indirectly for a given skin.
Currently these are only image files referenced by the module's CSS.
$skin | String: Skin name |
Definition at line 284 of file ResourceLoaderModule.php.
References $dbr, FormatJson\decode(), getName(), and wfGetDB().
Referenced by ResourceLoaderFileModule\getModifiedTime(), and ResourceLoaderFileModule\getStyles().
ResourceLoaderModule::getFlip | ( | $ | context | ) |
$context | ResourceLoaderContext |
Reimplemented in ResourceLoaderFileModule.
Definition at line 112 of file ResourceLoaderModule.php.
References $wgContLang.
Referenced by ResourceLoaderUserCSSPrefsModule\getStyles(), and ResourceLoaderWikiModule\getStyles().
Get the group this module is in.
Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, ResourceLoaderUserCSSPrefsModule, ResourceLoaderUserModule, ResourceLoaderUserOptionsModule, ResourceLoaderSiteModule, ResourceLoaderUserTokensModule, ResourceLoaderUserGroupsModule, and ResourceLoaderNoscriptModule.
Definition at line 221 of file ResourceLoaderModule.php.
Get the loader JS for this module, if set.
Reimplemented in ResourceLoaderFileModule.
Definition at line 252 of file ResourceLoaderModule.php.
Get the messages needed for this module.
To get a JSON blob with messages, use MessageBlobStore::get()
Reimplemented in ResourceLoaderFileModule.
Definition at line 211 of file ResourceLoaderModule.php.
Referenced by MessageBlobStore\generateMessageBlob(), getMsgBlobMtime(), and MessageBlobStore\insertMessageBlob().
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.
$context | ResourceLoaderContext: Context object |
Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, ResourceLoaderWikiModule, ResourceLoaderUserCSSPrefsModule, and ResourceLoaderUserOptionsModule.
Definition at line 367 of file ResourceLoaderModule.php.
ResourceLoaderModule::getMsgBlobMtime | ( | $ | lang | ) |
Get the last modification timestamp of the message blob for this module in a given language.
$lang | String: Language code |
Definition at line 320 of file ResourceLoaderModule.php.
References $dbr, $msgBlobMtime, getMessages(), getName(), wfGetDB(), wfTimestamp(), and wfTimestampNow().
Referenced by ResourceLoaderWikiModule\getModifiedTime(), and ResourceLoaderFileModule\getModifiedTime().
Get this module's name.
This is set when the module is registered with ResourceLoader::register()
Definition at line 73 of file ResourceLoaderModule.php.
Referenced by getFileDependencies(), getMsgBlobMtime(), getScriptURLsForDebug(), ResourceLoaderFileModule\getStyles(), and getStyleURLsForDebug().
Get this module's origin.
This is set when the module is registered with ResourceLoader::register()
Definition at line 94 of file ResourceLoaderModule.php.
Referenced by OutputPage\filterModules().
Where on the HTML page should this module's JS be loaded? 'top': in the <head> 'bottom': at the bottom of the <body>
Reimplemented in ResourceLoaderFileModule.
Definition at line 243 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.
$context | ResourceLoaderContext: Context object |
Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, ResourceLoaderWikiModule, ResourceLoaderUserOptionsModule, and ResourceLoaderUserTokensModule.
Definition at line 125 of file ResourceLoaderModule.php.
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.
$context | ResourceLoaderContext: Context object |
Reimplemented in ResourceLoaderFileModule.
Definition at line 144 of file ResourceLoaderModule.php.
References $url, ResourceLoaderContext\getLanguage(), getName(), ResourceLoaderContext\getRequest(), ResourceLoaderContext\getSkin(), ResourceLoaderContext\getUser(), ResourceLoaderContext\getVersion(), and ResourceLoader\makeLoaderURL().
Get the origin of this module.
Should only be overridden for foreign modules.
Definition at line 231 of file ResourceLoaderModule.php.
ResourceLoaderModule::getStyles | ( | ResourceLoaderContext $ | context | ) |
Get all CSS for this module for a given skin.
$context | ResourceLoaderContext: Context object |
Reimplemented in ResourceLoaderFileModule, ResourceLoaderWikiModule, and ResourceLoaderUserCSSPrefsModule.
Definition at line 175 of file ResourceLoaderModule.php.
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()
$context | ResourceLoaderContext: Context object |
Reimplemented in ResourceLoaderFileModule.
Definition at line 189 of file ResourceLoaderModule.php.
References $url, ResourceLoaderContext\getLanguage(), getName(), ResourceLoaderContext\getRequest(), ResourceLoaderContext\getSkin(), ResourceLoaderContext\getUser(), ResourceLoaderContext\getVersion(), and ResourceLoader\makeLoaderURL().
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.
$context | ResourceLoaderContext: Context object |
Reimplemented in ResourceLoaderWikiModule.
Definition at line 381 of file ResourceLoaderModule.php.
static ResourceLoaderModule::javaScriptParser | ( | ) | [static, protected] |
Definition at line 430 of file ResourceLoaderModule.php.
References $jsParser.
Referenced by validateScriptFile().
ResourceLoaderModule::setFileDependencies | ( | $ | skin, |
$ | deps | ||
) |
Set preloaded file dependency information.
Used so we can load this information for all modules at once.
$skin | String: Skin name |
$deps | Array: Array of file names |
Definition at line 310 of file ResourceLoaderModule.php.
ResourceLoaderModule::setMsgBlobMtime | ( | $ | lang, |
$ | mtime | ||
) |
Set a preloaded message blob last modification timestamp.
Used so we can load this information for all modules at once.
$lang | String: Language code |
$mtime | Integer: UNIX timestamp or 0 if there is no such blob |
Definition at line 347 of file ResourceLoaderModule.php.
ResourceLoaderModule::setName | ( | $ | name | ) |
Set this module's name.
This is called by ResourceLodaer::register() when registering the module. Other code should not call this.
$name | String: Name |
Definition at line 83 of file ResourceLoaderModule.php.
References $name.
ResourceLoaderModule::setOrigin | ( | $ | origin | ) |
Set this module's origin.
This is called by ResourceLodaer::register() when registering the module. Other code should not call this.
$origin | Int origin |
Definition at line 104 of file ResourceLoaderModule.php.
References $origin.
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 ResourceLoaderFileModule, and ResourceLoaderStartUpModule.
Definition at line 165 of file ResourceLoaderModule.php.
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.
string | $fileName | |
string | $contents |
Definition at line 398 of file ResourceLoaderModule.php.
References $result, $wgResourceLoaderValidateJS, Xml\encodeJsVar(), javaScriptParser(), wfGetCache(), and wfMemcKey().
Referenced by ResourceLoaderWikiModule\getScript(), and ResourceLoaderFileModule\readScriptFiles().
ResourceLoaderModule::$fileDeps = array() [protected] |
Definition at line 61 of file ResourceLoaderModule.php.
ResourceLoaderModule::$jsParser [static, private] |
Definition at line 387 of file ResourceLoaderModule.php.
Referenced by javaScriptParser().
ResourceLoaderModule::$msgBlobMtime = array() [protected] |
Definition at line 63 of file ResourceLoaderModule.php.
Referenced by getMsgBlobMtime().
ResourceLoaderModule::$name = null [protected] |
Definition at line 58 of file ResourceLoaderModule.php.
Referenced by ResourceLoaderStartUpModule\getConfig(), ResourceLoaderStartUpModule\getModifiedTime(), ResourceLoaderStartUpModule\getModuleRegistrations(), and setName().
ResourceLoaderModule::$origin = self::ORIGIN_CORE_SITEWIDE [protected] |
Reimplemented in ResourceLoaderWikiModule, ResourceLoaderUserCSSPrefsModule, ResourceLoaderUserOptionsModule, ResourceLoaderUserModule, ResourceLoaderUserTokensModule, and ResourceLoaderUserGroupsModule.
Definition at line 54 of file ResourceLoaderModule.php.
Referenced by setOrigin().
ResourceLoaderModule::$parseCacheVersion = 1 [static, private] |
Definition at line 388 of file ResourceLoaderModule.php.
const ResourceLoaderModule::ORIGIN_ALL = 10 |
Definition at line 48 of file ResourceLoaderModule.php.
Definition at line 38 of file ResourceLoaderModule.php.
Referenced by OutputPage\disallowUserJs().
Definition at line 35 of file ResourceLoaderModule.php.
Definition at line 45 of file ResourceLoaderModule.php.
Referenced by OutputPage\isUserJsAllowed().
Definition at line 42 of file ResourceLoaderModule.php.
const ResourceLoaderModule::TYPE_COMBINED = 'combined' |
Definition at line 32 of file ResourceLoaderModule.php.
Referenced by OutputPage\getHeadScripts(), OutputPage\getScriptsForBottomQueue(), and OutputPage\makeResourceLoaderLink().
const ResourceLoaderModule::TYPE_MESSAGES = 'messages' |
Definition at line 31 of file ResourceLoaderModule.php.
Referenced by OutputPage\getHeadScripts(), and OutputPage\getScriptsForBottomQueue().
const ResourceLoaderModule::TYPE_SCRIPTS = 'scripts' |
Definition at line 29 of file ResourceLoaderModule.php.
Referenced by OutputPage\getHeadScripts(), OutputPage\getScriptsForBottomQueue(), OutputPage\isUserJsAllowed(), and OutputPage\makeResourceLoaderLink().
const ResourceLoaderModule::TYPE_STYLES = 'styles' |
Definition at line 30 of file ResourceLoaderModule.php.
Referenced by OutputPage\buildCssLinks(), and OutputPage\makeResourceLoaderLink().