MediaWiki  REL1_19
ResourceLoaderFileModule Class Reference

ResourceLoader module based on local JavaScript/CSS files. More...

Inheritance diagram for ResourceLoaderFileModule:
Collaboration diagram for ResourceLoaderFileModule:

List of all members.

Public Member Functions

 __construct ($options=array(), $localBasePath=null, $remoteBasePath=null)
 Constructs a new module from an options array.
 getDependencies ()
 Gets list of names of modules this module depends on.
 getFlip ($context)
 Get whether CSS for this module should be flipped.
 getGroup ()
 Gets the name of the group this module should be loaded in.
 getLoaderScript ()
 Gets loader script.
 getMessages ()
 Gets list of message keys used by this module.
 getModifiedTime (ResourceLoaderContext $context)
 Get the last modified timestamp of this module.
 getPosition ()
 getScript (ResourceLoaderContext $context)
 Gets all scripts for a given context concatenated together.
 getScriptURLsForDebug (ResourceLoaderContext $context)
 getStyles (ResourceLoaderContext $context)
 Gets all styles for a given context concatenated together.
 getStyleURLsForDebug (ResourceLoaderContext $context)
 supportsURLLoading ()

Protected Member Functions

 getLocalPath ($path)
 getRemotePath ($path)
 getScriptFiles (ResourceLoaderContext $context)
 Gets a list of file paths for all scripts in this module, in order of propper execution.
 getStyleFiles (ResourceLoaderContext $context)
 Gets a list of file paths for all styles in this module, in order of propper inclusion.
 readScriptFiles (array $scripts)
 Gets the contents of a list of JavaScript files.
 readStyleFile ($path, $flip)
 Reads a style file.
 readStyleFiles (array $styles, $flip)
 Gets the contents of a list of CSS files.

Static Protected Member Functions

static collateFilePathListByOption (array $list, $option, $default)
 Collates file paths by option (where provided).
static safeFilemtime ($filename)
 Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist but returns 1 instead.
static tryForKey (array $list, $key, $fallback=null)
 Gets a list of element that match a key, optionally using a fallback key.

Protected Attributes

 $debugRaw = true
 Boolean: Link to raw files in debug mode.
 $debugScripts = array()
 Array: List of paths to JavaScript files to include in debug mode.
 $dependencies = array()
 Array: List of modules this module depends on.
 $group
 String: Name of group to load this module in.
 $languageScripts = array()
 Array: List of JavaScript files to include when using a specific language.
 $loaderScripts = array()
 Array: List of paths to JavaScript files to include in the startup module.
 $localBasePath = ''
 String: Local base path, see __construct()
 $localFileRefs = array()
 Array: Place where readStyleFile() tracks file dependencies.
 $messages = array()
 Array: List of message keys used by this module.
 $modifiedTime = array()
 Array: Cache for mtime.
 $position = 'bottom'
 String: Position on the page to load this module at.
 $remoteBasePath = ''
 String: Remote base path, see __construct()
 $scripts = array()
 Array: List of paths to JavaScript files to always include.
 $skinScripts = array()
 Array: List of JavaScript files to include when using a specific skin.
 $skinStyles = array()
 Array: List of paths to CSS files to include when using specific skins.
 $styles = array()
 Array: List of paths to CSS files to always include.

Detailed Description

ResourceLoader module based on local JavaScript/CSS files.

Definition at line 26 of file ResourceLoaderFileModule.php.


Constructor & Destructor Documentation

ResourceLoaderFileModule::__construct ( options = array(),
localBasePath = null,
remoteBasePath = null 
)

Constructs a new module from an options array.

Parameters:
$optionsArray: List of options; if not given or empty, an empty module will be constructed
$localBasePathString: Base path to prepend to all local paths in $options. Defaults to $IP
$remoteBasePathString: Base path to prepend to all remote paths in $options. Defaults to $wgScriptPath

Below is a description for the $options array:

Construction options:
        array(
                // Base path to prepend to all local paths in $options. Defaults to $IP
                'localBasePath' => [base path],
                // Base path to prepend to all remote paths in $options. Defaults to $wgScriptPath
                'remoteBasePath' => [base path],
                // Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath
                'remoteExtPath' => [base path],
                // Scripts to always include
                'scripts' => [file path string or array of file path strings],
                // Scripts to include in specific language contexts
                'languageScripts' => array(
                        [language code] => [file path string or array of file path strings],
                ),
                // Scripts to include in specific skin contexts
                'skinScripts' => array(
                        [skin name] => [file path string or array of file path strings],
                ),
                // Scripts to include in debug contexts
                'debugScripts' => [file path string or array of file path strings],
                // Scripts to include in the startup module
                'loaderScripts' => [file path string or array of file path strings],
                // Modules which must be loaded before this module
                'dependencies' => [modile name string or array of module name strings],
                // Styles to always load
                'styles' => [file path string or array of file path strings],
                // Styles to include in specific skin contexts
                'skinStyles' => array(
                        [skin name] => [file path string or array of file path strings],
                ),
                // Messages to always load
                'messages' => [array of message key strings],
                // Group which this module should be loaded together with
                'group' => [group name string],
                // Position on the page to load this module at
                'position' => ['bottom' (default) or 'top']
        )

Definition at line 182 of file ResourceLoaderFileModule.php.

References $IP, $localBasePath, $options, $remoteBasePath, $wgExtensionAssetsPath, $wgResourceBasePath, $wgScriptPath, and wfExpandUrl().

Here is the call graph for this function:


Member Function Documentation

static ResourceLoaderFileModule::collateFilePathListByOption ( array $  list,
option,
default 
) [static, protected]

Collates file paths by option (where provided).

Parameters:
$listArray: List of file paths in any combination of index/path or path/options pairs
$optionString: option name
$defaultMixed: default value if the option isn't set
Returns:
Array: List of file paths, collated by $option

Definition at line 462 of file ResourceLoaderFileModule.php.

Referenced by getModifiedTime().

Here is the caller graph for this function:

Gets list of names of modules this module depends on.

Returns:
Array: List of module names

Reimplemented from ResourceLoaderModule.

Definition at line 364 of file ResourceLoaderFileModule.php.

Get whether CSS for this module should be flipped.

Parameters:
$contextResourceLoaderContext
Returns:
bool

Reimplemented from ResourceLoaderModule.

Definition at line 653 of file ResourceLoaderFileModule.php.

Referenced by getStyles().

Here is the caller graph for this function:

Gets the name of the group this module should be loaded in.

Returns:
String: Group name

Reimplemented from ResourceLoaderModule.

Definition at line 348 of file ResourceLoaderFileModule.php.

Gets loader script.

Returns:
String: JavaScript code to be added to startup module

Reimplemented from ResourceLoaderModule.

Definition at line 285 of file ResourceLoaderFileModule.php.

References readScriptFiles().

Here is the call graph for this function:

ResourceLoaderFileModule::getLocalPath ( path) [protected]
Parameters:
$pathstring
Returns:
string

Definition at line 441 of file ResourceLoaderFileModule.php.

Referenced by readScriptFiles(), and readStyleFile().

Here is the caller graph for this function:

Gets list of message keys used by this module.

Returns:
Array: List of message keys

Reimplemented from ResourceLoaderModule.

Definition at line 339 of file ResourceLoaderFileModule.php.

Get the last modified timestamp of this module.

Last modified timestamps are calculated from the highest last modified timestamp of this module's constituent files as well as the files it depends on. This function is context-sensitive, only performing calculations on files relevant to the given language, skin and debug mode.

Parameters:
$contextResourceLoaderContext: Context in which to calculate the modified time
Returns:
Integer: UNIX timestamp
See also:
ResourceLoaderModule::getFileDependencies

Reimplemented from ResourceLoaderModule.

Definition at line 382 of file ResourceLoaderFileModule.php.

References $files, $styles, collateFilePathListByOption(), ResourceLoaderContext\getDebug(), ResourceLoaderModule\getFileDependencies(), ResourceLoaderContext\getHash(), ResourceLoaderContext\getLanguage(), ResourceLoaderModule\getMsgBlobMtime(), ResourceLoaderContext\getSkin(), tryForKey(), wfProfileIn(), and wfProfileOut().

Here is the call graph for this function:

Returns:
string

Reimplemented from ResourceLoaderModule.

Definition at line 355 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::getRemotePath ( path) [protected]
Parameters:
$pathstring
Returns:
string

Definition at line 449 of file ResourceLoaderFileModule.php.

Referenced by getScriptURLsForDebug(), getStyleURLsForDebug(), and readStyleFile().

Here is the caller graph for this function:

Gets all scripts for a given context concatenated together.

Parameters:
$contextResourceLoaderContext: Context in which to generate script
Returns:
String: JavaScript code for $context

Reimplemented from ResourceLoaderModule.

Definition at line 256 of file ResourceLoaderFileModule.php.

References $files, getScriptFiles(), and readScriptFiles().

Here is the call graph for this function:

Gets a list of file paths for all scripts in this module, in order of propper execution.

Parameters:
$contextResourceLoaderContext: Context
Returns:
Array: List of file paths

Definition at line 510 of file ResourceLoaderFileModule.php.

References $files, ResourceLoaderContext\getDebug(), ResourceLoaderContext\getLanguage(), and ResourceLoaderContext\getSkin().

Referenced by getScript(), and getScriptURLsForDebug().

Here is the call graph for this function:

Here is the caller graph for this function:

Parameters:
$contextResourceLoaderContext
Returns:
array

Reimplemented from ResourceLoaderModule.

Definition at line 265 of file ResourceLoaderFileModule.php.

References $file, $urls, getRemotePath(), and getScriptFiles().

Here is the call graph for this function:

Gets a list of file paths for all styles in this module, in order of propper inclusion.

Parameters:
$contextResourceLoaderContext: Context
Returns:
Array: List of file paths

Definition at line 528 of file ResourceLoaderFileModule.php.

References ResourceLoaderContext\getSkin().

Referenced by getStyles(), and getStyleURLsForDebug().

Here is the call graph for this function:

Here is the caller graph for this function:

Gets all styles for a given context concatenated together.

Parameters:
$contextResourceLoaderContext: Context in which to generate styles
Returns:
String: CSS code for $context

Reimplemented from ResourceLoaderModule.

Definition at line 298 of file ResourceLoaderFileModule.php.

References $styles, FormatJson\encode(), ResourceLoaderModule\getFileDependencies(), getFlip(), ResourceLoaderModule\getName(), ResourceLoaderContext\getSkin(), getStyleFiles(), readStyleFiles(), wfGetDB(), and wfReadOnly().

Here is the call graph for this function:

Parameters:
$contextResourceLoaderContext
Returns:
array

Reimplemented from ResourceLoaderModule.

Definition at line 323 of file ResourceLoaderFileModule.php.

References $file, $urls, getRemotePath(), and getStyleFiles().

Here is the call graph for this function:

ResourceLoaderFileModule::readScriptFiles ( array $  scripts) [protected]

Gets the contents of a list of JavaScript files.

Parameters:
$scriptsArray: List of file paths to scripts to read, remap and concetenate
Returns:
String: Concatenated and remapped JavaScript data from $scripts

Definition at line 543 of file ResourceLoaderFileModule.php.

References $wgResourceLoaderValidateStaticJS, getLocalPath(), and ResourceLoaderModule\validateScriptFile().

Referenced by getLoaderScript(), and getScript().

Here is the call graph for this function:

Here is the caller graph for this function:

ResourceLoaderFileModule::readStyleFile ( path,
flip 
) [protected]

Reads a style file.

This method can be used as a callback for array_map()

Parameters:
$pathString: File path of style file to read
$flipbool
Returns:
String: CSS data in script file
Exceptions:
MWExceptionif the file doesn't exist

Definition at line 606 of file ResourceLoaderFileModule.php.

References $dir, $path, CSSMin\getLocalFileReferences(), getLocalPath(), getRemotePath(), CSSMin\remap(), and CSSJanus\transform().

Here is the call graph for this function:

ResourceLoaderFileModule::readStyleFiles ( array $  styles,
flip 
) [protected]

Gets the contents of a list of CSS files.

Parameters:
$stylesArray: List of media type/list of file paths pairs, to read, remap and concetenate
$flipbool
Returns:
Array: List of concatenated and remapped CSS data from $styles, keyed by media type

Definition at line 577 of file ResourceLoaderFileModule.php.

References $files, and $styles.

Referenced by getStyles().

Here is the caller graph for this function:

static ResourceLoaderFileModule::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:
$filenamestring File name
Returns:
int UNIX timestamp, or 1 if the file doesn't exist

Definition at line 637 of file ResourceLoaderFileModule.php.

Returns:
bool

Reimplemented from ResourceLoaderModule.

Definition at line 276 of file ResourceLoaderFileModule.php.

static ResourceLoaderFileModule::tryForKey ( array $  list,
key,
fallback = null 
) [static, protected]

Gets a list of element that match a key, optionally using a fallback key.

Parameters:
$listArray: List of lists to select from
$keyString: Key to look for in $map
$fallbackString: Key to look for in $list if $key doesn't exist
Returns:
Array: List of elements from $map which matched $key or $fallback, or an empty list in case of no match

Definition at line 492 of file ResourceLoaderFileModule.php.

References $fallback.

Referenced by getModifiedTime().

Here is the caller graph for this function:


Member Data Documentation

ResourceLoaderFileModule::$debugRaw = true [protected]

Boolean: Link to raw files in debug mode.

Definition at line 111 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$debugScripts = array() [protected]

Array: List of paths to JavaScript files to include in debug mode.

Usage:
 array( [skin-name] => array( [file-path], [file-path], ... ), ... )

Definition at line 65 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$dependencies = array() [protected]

Array: List of modules this module depends on.

Usage:
 array( [file-path], [file-path], ... )

Definition at line 97 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$group [protected]

String: Name of group to load this module in.

Definition at line 107 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$languageScripts = array() [protected]

Array: List of JavaScript files to include when using a specific language.

Usage:
 array( [language-code] => array( [file-path], [file-path], ... ), ... )

Definition at line 49 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$loaderScripts = array() [protected]

Array: List of paths to JavaScript files to include in the startup module.

Usage:
 array( [file-path], [file-path], ... )

Definition at line 73 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$localBasePath = '' [protected]

String: Local base path, see __construct()

Definition at line 31 of file ResourceLoaderFileModule.php.

Referenced by __construct().

ResourceLoaderFileModule::$localFileRefs = array() [protected]

Array: Place where readStyleFile() tracks file dependencies.

Usage:
 array( [file-path], [file-path], ... )

Definition at line 127 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$messages = array() [protected]

Array: List of message keys used by this module.

Usage:
 array( [message-key], [message-key], ... )

Definition at line 105 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$modifiedTime = array() [protected]

Array: Cache for mtime.

Usage:
 array( [hash] => [mtime], [hash] => [mtime], ... )

Definition at line 119 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$position = 'bottom' [protected]

String: Position on the page to load this module at.

Definition at line 109 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$remoteBasePath = '' [protected]

String: Remote base path, see __construct()

Definition at line 33 of file ResourceLoaderFileModule.php.

Referenced by __construct().

ResourceLoaderFileModule::$scripts = array() [protected]

Array: List of paths to JavaScript files to always include.

Usage:
 array( [file-path], [file-path], ... )

Definition at line 41 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$skinScripts = array() [protected]

Array: List of JavaScript files to include when using a specific skin.

Usage:
 array( [skin-name] => array( [file-path], [file-path], ... ), ... )

Definition at line 57 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$skinStyles = array() [protected]

Array: List of paths to CSS files to include when using specific skins.

Usage:
 array( [file-path], [file-path], ... )

Definition at line 89 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$styles = array() [protected]

Array: List of paths to CSS files to always include.

Usage:
 array( [file-path], [file-path], ... )

Definition at line 81 of file ResourceLoaderFileModule.php.

Referenced by getModifiedTime(), getStyles(), and readStyleFiles().


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