MediaWiki  REL1_24
ResourceLoaderModule Class Reference

Abstraction for resource loader modules, with name registration and maxage functionality. More...

Inheritance diagram for ResourceLoaderModule:
Collaboration diagram for ResourceLoaderModule:

List of all members.

Public Member Functions

 getConfig ()
 getDefinitionMtime (ResourceLoaderContext $context)
 Helper method for calculating when this module's definition summary was last changed.
 getDefinitionSummary (ResourceLoaderContext $context)
 Get the definition summary for this module.
 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.
 getHashMtime (ResourceLoaderContext $context)
 Helper method for calculating when the module's hash (if it has one) changed.
 getLoaderScript ()
 Get the loader JS for this module, if set.
 getMessages ()
 Get the messages needed for this module.
 getModifiedHash (ResourceLoaderContext $context)
 Get the hash for whatever this module may contain.
 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?
 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.
 getSkipFunction ()
 Get the skip function.
 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.
 getTargets ()
 Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
 isKnownEmpty (ResourceLoaderContext $context)
 Check whether this module is known to be empty.
 isRaw ()
 Whether this module's JS expects to work without the client-side ResourceLoader module.
 setConfig (Config $config)
 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 ()
static safeFilemtime ($filename)
 Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist but returns 1 instead.

Protected Attributes

Config $config
 $fileDeps = array()
 $msgBlobMtime = array()
 $name = null
 $origin = self::ORIGIN_CORE_SITEWIDE
 $targets = array( 'desktop' )

Static Private Attributes

static $jsParser
static $parseCacheVersion = 1

Detailed Description

Abstraction for resource loader modules, with name registration and maxage functionality.

Definition at line 28 of file ResourceLoaderModule.php.


Member Function Documentation

Helper method for calculating when this module's definition summary was last changed.

Since:
1.23
Parameters:
ResourceLoaderContext$context
Returns:
int UNIX timestamp or 0 if no definition summary was provided by getDefinitionSummary()

Definition at line 492 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderWikiModule\getModifiedTime().

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.

Since:
1.23
Parameters:
ResourceLoaderContext$context
Returns:
array|null

Reimplemented in ResourceLoaderFileModule, and ResourceLoaderWikiModule.

Definition at line 559 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.

To add dependencies dynamically on the client side, use a custom loader script, see getLoaderScript()

Returns:
array List of module names as strings

Reimplemented in ResourceLoaderFileModule, ResourceLoaderUserCSSPrefsModule, ResourceLoaderLanguageDataModule, ResourceLoaderTestModule, and ResourceLoaderLanguageNamesModule.

Definition at line 307 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.

Parameters:
string$skinSkin name
Returns:
array List of files

Definition at line 346 of file ResourceLoaderModule.php.

Parameters:
ResourceLoaderContext$context
Returns:
bool

Reimplemented in ResourceLoaderFileModule.

Definition at line 118 of file ResourceLoaderModule.php.

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

Helper method for calculating when the module's hash (if it has one) changed.

Parameters:
ResourceLoaderContext$context
Returns:
int UNIX timestamp or 0 if no hash was provided by getModifiedHash()

Definition at line 446 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderLanguageDataModule\getModifiedTime(), ResourceLoaderLanguageNamesModule\getModifiedTime(), ResourceLoaderEditToolbarModule\getModifiedTime(), and ResourceLoaderStartUpModule\getModifiedTime().

Get the loader JS for this module, if set.

Returns:
mixed JavaScript loader code as a string or boolean false if no custom loader set

Reimplemented in ResourceLoaderFileModule.

Definition at line 292 of file ResourceLoaderModule.php.

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.

Definition at line 240 of file ResourceLoaderModule.php.

Referenced by MessageBlobStore\generateMessageBlob(), and MessageBlobStore\insertMessageBlob().

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().

Parameters:
ResourceLoaderContext$context
Returns:
string|null Hash

Reimplemented in ResourceLoaderStartUpModule, ResourceLoaderEditToolbarModule, ResourceLoaderLanguageNamesModule, and ResourceLoaderLanguageDataModule.

Definition at line 479 of file ResourceLoaderModule.php.

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.

Parameters:
ResourceLoaderContext$contextContext object
Returns:
int UNIX timestamp

Reimplemented in ResourceLoaderFileModule, ResourceLoaderStartUpModule, ResourceLoaderWikiModule, ResourceLoaderEditToolbarModule, ResourceLoaderLanguageNamesModule, ResourceLoaderLanguageDataModule, ResourceLoaderUserOptionsModule, and ResourceLoaderUserCSSPrefsModule.

Definition at line 434 of file ResourceLoaderModule.php.

Get the last modification timestamp of the message blob for this module in a given language.

Parameters:
string$langLanguage code
Returns:
int UNIX timestamp, or 0 if the module doesn't have messages

Definition at line 382 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderWikiModule\getModifiedTime().

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

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

Referenced by OutputPage\getModuleScripts().

Where on the HTML page should this module's JS be loaded?

  • 'top': in the "<head>"
  • 'bottom': at the bottom of the "<body>"
Returns:
string

Reimplemented in ResourceLoaderFileModule.

Definition at line 272 of file ResourceLoaderModule.php.

Get all JS for this module for a given language and skin.

Includes all relevant JS except loader scripts.

Parameters:
ResourceLoaderContext$context
Returns:
string JavaScript code

Reimplemented in ResourceLoaderStartUpModule, ResourceLoaderFileModule, ResourceLoaderWikiModule, ResourceLoaderUserOptionsModule, ResourceLoaderTestModule, ResourceLoaderUserTokensModule, ResourceLoaderLanguageDataModule, and ResourceLoaderLanguageNamesModule.

Definition at line 131 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.

Parameters:
ResourceLoaderContext$context
Returns:
array Array of URLs

Reimplemented in ResourceLoaderFileModule.

Definition at line 171 of file ResourceLoaderModule.php.

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

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

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 array( 'screen' => '.foo { width: 0 }' ); or array( 'screen' => array( '.foo { width: 0 }' ) );

Reimplemented in ResourceLoaderFileModule, ResourceLoaderWikiModule, ResourceLoaderTestModule, and ResourceLoaderUserCSSPrefsModule.

Definition at line 204 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()

Parameters:
ResourceLoaderContext$context
Returns:
array Array( mediaType => array( URL1, URL2, ... ), ... )

Reimplemented in ResourceLoaderFileModule.

Definition at line 218 of file ResourceLoaderModule.php.

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

Returns:
array Array of strings

Reimplemented in ResourceLoaderFileModule.

Definition at line 317 of file ResourceLoaderModule.php.

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.

Definition at line 574 of file ResourceLoaderModule.php.

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

static ResourceLoaderModule::javaScriptParser ( ) [static, protected]
Returns:
JSParser

Definition at line 621 of file ResourceLoaderModule.php.

static ResourceLoaderModule::safeFilemtime ( filename) [static, protected]

Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist but returns 1 instead.

Parameters:
string$filenameFile name
Returns:
int UNIX timestamp, or 1 if the file doesn't exist

Definition at line 634 of file ResourceLoaderModule.php.

Parameters:
Config$config
Since:
1.24

Definition at line 153 of file ResourceLoaderModule.php.

Set preloaded file dependency information.

Used so we can load this information for all modules at once.

Parameters:
string$skinSkin name
array$depsArray of file names

Definition at line 372 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.

Parameters:
string$langLanguage code
int$mtimeUNIX timestamp or 0 if there is no such blob

Definition at line 410 of file ResourceLoaderModule.php.

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

Set this module's origin.

This is called by ResourceLoader::register() when registering the module. Other code should not call this.

Parameters:
int$originOrigin

Definition at line 110 of file ResourceLoaderModule.php.

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 ResourceLoaderStartUpModule, ResourceLoaderFileModule, ResourceLoaderUserOptionsModule, and ResourceLoaderUserTokensModule.

Definition at line 192 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.

Parameters:
string$fileName
string$contents
Returns:
string JS with the original, or a replacement error

Definition at line 590 of file ResourceLoaderModule.php.

Referenced by ResourceLoaderWikiModule\getScript(), and ResourceLoaderFileModule\isRaw().


Member Data Documentation

Config ResourceLoaderModule::$config [protected]

Definition at line 69 of file ResourceLoaderModule.php.

ResourceLoaderModule::$fileDeps = array() [protected]

Definition at line 63 of file ResourceLoaderModule.php.

ResourceLoaderModule::$jsParser [static, private]

Definition at line 579 of file ResourceLoaderModule.php.

ResourceLoaderModule::$msgBlobMtime = array() [protected]

Definition at line 65 of file ResourceLoaderModule.php.

ResourceLoaderModule::$origin = self::ORIGIN_CORE_SITEWIDE [protected]
ResourceLoaderModule::$parseCacheVersion = 1 [static, private]

Definition at line 580 of file ResourceLoaderModule.php.

Definition at line 49 of file ResourceLoaderModule.php.


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