MediaWiki  REL1_24
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.
 getAllStyleFiles ()
 Returns all style files and all skin style files used by this module.
 getDefinitionSummary (ResourceLoaderContext $context)
 Get the definition summary for this module.
 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 ()
 Get 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)
 getSkipFunction ()
 Get the skip function.
 getStyleFiles (ResourceLoaderContext $context)
 Get a list of file paths for all styles in this module, in order of proper inclusion.
 getStyles (ResourceLoaderContext $context)
 Get all styles for a given context.
 getStyleSheetLang ($path)
 Infer the stylesheet language from a stylesheet file path.
 getStyleURLsForDebug (ResourceLoaderContext $context)
 getTargets ()
 Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
 isRaw ()
 readStyleFiles (array $styles, $flip, $context=null)
 Gets the contents of a list of CSS files.
 supportsURLLoading ()

Static Public Member Functions

static extractBasePaths ($options=array(), $localBasePath=null, $remoteBasePath=null)
 Extract a pair of local and remote base paths from module definition information.

Protected Member Functions

 compileLessFile ($fileName, $compiler=null)
 Compile a LESS file into CSS.
 getAllSkinStyleFiles ()
 Gets a list of file paths for all skin style files in the module, for all available skins.
 getLessCompiler (ResourceLoaderContext $context=null)
 Get a LESS compiler instance for this module in given context.
 getLocalPath ($path)
 getRemotePath ($path)
 getScriptFiles (ResourceLoaderContext $context)
 Get a list of file paths for all scripts in this module, in order of proper execution.
 getSkinStyleFiles ($skinName)
 Gets a list of file paths for all skin styles in the module used by the skin.
 readScriptFiles (array $scripts)
 Gets the contents of a list of JavaScript files.
 readStyleFile ($path, $flip, $context=null)
 Reads a style file.

Static Protected Member Functions

static collateFilePathListByOption (array $list, $option, $default)
 Collates file paths by option (where provided).
static tryForKey (array $list, $key, $fallback=null)
 Get a list of element that match a key, optionally using a fallback key.

Protected Attributes

bool $debugRaw = true
 Link to raw files in debug mode *.
array $debugScripts = array()
 List of paths to JavaScript files to include in debug mode.
array $dependencies = array()
 List of modules this module depends on.
string $group
 Name of group to load this module in *.
bool $hasGeneratedStyles = false
 Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
array $languageScripts = array()
 List of JavaScript files to include when using a specific language.
array $loaderScripts = array()
 List of paths to JavaScript files to include in the startup module.
string $localBasePath = ''
 Local base path, see __construct() *.
array $localFileRefs = array()
 Place where readStyleFile() tracks file dependencies.
array $messages = array()
 List of message keys used by this module.
array $modifiedTime = array()
 Cache for mtime.
string $position = 'bottom'
 Position on the page to load this module at *.
bool $raw = false
 Whether mw.loader.state() call should be omitted *.
string $remoteBasePath = ''
 Remote base path, see __construct() *.
array $scripts = array()
 List of paths to JavaScript files to always include.
array $skinScripts = array()
 List of JavaScript files to include when using a specific skin.
array $skinStyles = array()
 List of paths to CSS files to include when using specific skins.
string $skipFunction = null
 File name containing the body of the skip function.
array $styles = array()
 List of paths to CSS files to always include.
 $targets = array( 'desktop' )

Detailed Description

ResourceLoader module based on local JavaScript/CSS files.

Definition at line 28 of file ResourceLoaderFileModule.php.


Constructor & Destructor Documentation

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

Constructs a new module from an options array.

Parameters:
array$optionsList of options; if not given or empty, an empty module will be constructed
string$localBasePathBase path to prepend to all local paths in $options. Defaults to $IP
string$remoteBasePathBase path to prepend to all remote paths in $options. Defaults to $wgResourceBasePath

Below is a description for the $options array:

Exceptions:
MWException
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 $wgResourceBasePath
         'remoteBasePath' => [base path],
         // Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath
         'remoteExtPath' => [base path],
         // Equivalent of remoteBasePath, but relative to $wgStylePath
         'remoteSkinPath' => [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' => [module 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']
         // Function that, if it returns true, makes the loader skip this module.
         // The file must contain valid JavaScript for execution in a private function.
         // The file must not contain the "function () {" and "}" wrapper though.
         'skipFunction' => [file path]
     )

Definition at line 202 of file ResourceLoaderFileModule.php.


Member Function Documentation

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

Collates file paths by option (where provided).

Parameters:
array$listList of file paths in any combination of index/path or path/options pairs
string$optionOption name
mixed$defaultDefault value if the option isn't set
Returns:
array List of file paths, collated by $option

Definition at line 631 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::compileLessFile ( fileName,
compiler = null 
) [protected]

Compile a LESS file into CSS.

Keeps track of all used files and adds them to localFileRefs.

Since:
1.22
Exceptions:
ExceptionIf lessc encounters a parse error
Parameters:
string$fileNameFile path of LESS source
lessc$compilerCompiler to use, if not default
Returns:
string CSS source

Definition at line 896 of file ResourceLoaderFileModule.php.

static ResourceLoaderFileModule::extractBasePaths ( options = array(),
localBasePath = null,
remoteBasePath = null 
) [static]

Extract a pair of local and remote base paths from module definition information.

Implementation note: the amount of global state used in this function is staggering.

Parameters:
array$optionsModule definition
string$localBasePathPath to use if not provided in module definition. Defaults to $IP
string$remoteBasePathPath to use if not provided in module definition. Defaults to $wgResourceBasePath
Returns:
array Array( localBasePath, remoteBasePath )

Definition at line 278 of file ResourceLoaderFileModule.php.

Gets a list of file paths for all skin style files in the module, for all available skins.

Returns:
array A list of file paths collated by media type

Definition at line 730 of file ResourceLoaderFileModule.php.

Returns all style files and all skin style files used by this module.

Returns:
array

Definition at line 750 of file ResourceLoaderFileModule.php.

Get the definition summary for this module.

Parameters:
ResourceLoaderContext$context
Returns:
array

Reimplemented from ResourceLoaderModule.

Definition at line 557 of file ResourceLoaderFileModule.php.

Gets list of names of modules this module depends on.

Returns:
array List of module names

Reimplemented from ResourceLoaderModule.

Definition at line 444 of file ResourceLoaderFileModule.php.

Get whether CSS for this module should be flipped.

Parameters:
ResourceLoaderContext$context
Returns:
bool

Reimplemented from ResourceLoaderModule.

Definition at line 872 of file ResourceLoaderFileModule.php.

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

Returns:
string Group name

Reimplemented from ResourceLoaderModule.

Definition at line 428 of file ResourceLoaderFileModule.php.

Get a LESS compiler instance for this module in given context.

Just calls ResourceLoader::getLessCompiler() by default to get a global compiler.

Parameters:
ResourceLoaderContext$context
Exceptions:
MWException
Since:
1.24
Returns:
lessc

Reimplemented in ResourceLoaderEditToolbarModule.

Definition at line 915 of file ResourceLoaderFileModule.php.

References $result.

Get loader script.

Returns:
string|bool JavaScript code to be added to startup module

Reimplemented from ResourceLoaderModule.

Definition at line 353 of file ResourceLoaderFileModule.php.

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

Definition at line 591 of file ResourceLoaderFileModule.php.

References $summary.

Referenced by isRaw().

Gets list of message keys used by this module.

Returns:
array List of message keys

Reimplemented from ResourceLoaderModule.

Definition at line 419 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:
ResourceLoaderContext$contextContext in which to calculate the modified time
Returns:
int UNIX timestamp
See also:
ResourceLoaderModule::getFileDependencies

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderEditToolbarModule.

Definition at line 490 of file ResourceLoaderFileModule.php.

Returns:
string

Reimplemented from ResourceLoaderModule.

Definition at line 435 of file ResourceLoaderFileModule.php.

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

Definition at line 603 of file ResourceLoaderFileModule.php.

References $path.

Gets all scripts for a given context concatenated together.

Parameters:
ResourceLoaderContext$contextContext in which to generate script
Returns:
string JavaScript code for $context

Reimplemented from ResourceLoaderModule.

Definition at line 324 of file ResourceLoaderFileModule.php.

Get a list of file paths for all scripts in this module, in order of proper execution.

Parameters:
ResourceLoaderContext$context
Returns:
array List of file paths

Definition at line 679 of file ResourceLoaderFileModule.php.

Parameters:
ResourceLoaderContext$context
Returns:
array

Reimplemented from ResourceLoaderModule.

Definition at line 333 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::getSkinStyleFiles ( skinName) [protected]

Gets a list of file paths for all skin styles in the module used by the skin.

Parameters:
string$skinNameThe name of the skin
Returns:
array A list of file paths collated by media type

Definition at line 716 of file ResourceLoaderFileModule.php.

Get the skip function.

Returns:
string|null

Reimplemented from ResourceLoaderModule.

Definition at line 453 of file ResourceLoaderFileModule.php.

Get a list of file paths for all styles in this module, in order of proper inclusion.

Parameters:
ResourceLoaderContext$context
Returns:
array List of file paths

Definition at line 698 of file ResourceLoaderFileModule.php.

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

Get all styles for a given context.

Parameters:
ResourceLoaderContext$context
Returns:
array CSS code for $context as an associative array mapping media type to CSS text.

Reimplemented from ResourceLoaderModule.

Definition at line 366 of file ResourceLoaderFileModule.php.

References readScriptFiles().

Infer the stylesheet language from a stylesheet file path.

Since:
1.22
Parameters:
string$path
Returns:
string The stylesheet language name

Definition at line 618 of file ResourceLoaderFileModule.php.

Parameters:
ResourceLoaderContext$context
Returns:
array

Reimplemented from ResourceLoaderModule.

Definition at line 396 of file ResourceLoaderFileModule.php.

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

Returns:
array Array of strings

Reimplemented from ResourceLoaderModule.

Definition at line 881 of file ResourceLoaderFileModule.php.

Gets the contents of a list of JavaScript files.

Parameters:
array$scriptsList of file paths to scripts to read, remap and concetenate
Exceptions:
MWException
Returns:
string Concatenated and remapped JavaScript data from $scripts

Definition at line 774 of file ResourceLoaderFileModule.php.

Referenced by getStyles().

ResourceLoaderFileModule::readStyleFile ( path,
flip,
context = null 
) [protected]

Reads a style file.

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

Parameters:
string$pathFile path of style file to read
bool$flip
ResourceLoaderContext$context(optional)
Returns:
string CSS data in script file
Exceptions:
MWExceptionIf the file doesn't exist

Definition at line 835 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::readStyleFiles ( array styles,
flip,
context = null 
)

Gets the contents of a list of CSS files.

Parameters:
array$stylesList of media type/list of file paths pairs, to read, remap and concetenate
bool$flip
ResourceLoaderContext$context(optional)
Exceptions:
MWException
Returns:
array List of concatenated and remapped CSS data from $styles, keyed by media type

Definition at line 808 of file ResourceLoaderFileModule.php.

Returns:
bool

Reimplemented from ResourceLoaderModule.

Definition at line 344 of file ResourceLoaderFileModule.php.

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

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

Parameters:
array$listList of lists to select from
string$keyKey to look for in $map
string$fallbackKey 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 661 of file ResourceLoaderFileModule.php.

References array().


Member Data Documentation

bool ResourceLoaderFileModule::$debugRaw = true [protected]

Link to raw files in debug mode *.

Definition at line 115 of file ResourceLoaderFileModule.php.

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

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.

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

List of modules this module depends on.

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

Definition at line 97 of file ResourceLoaderFileModule.php.

string ResourceLoaderFileModule::$group [protected]

Name of group to load this module in *.

Definition at line 111 of file ResourceLoaderFileModule.php.

bool ResourceLoaderFileModule::$hasGeneratedStyles = false [protected]

Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.

Definition at line 124 of file ResourceLoaderFileModule.php.

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

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.

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

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.

string ResourceLoaderFileModule::$localBasePath = '' [protected]

Local base path, see __construct() *.

Definition at line 31 of file ResourceLoaderFileModule.php.

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

Place where readStyleFile() tracks file dependencies.

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

Definition at line 140 of file ResourceLoaderFileModule.php.

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

List of message keys used by this module.

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

Definition at line 109 of file ResourceLoaderFileModule.php.

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

Cache for mtime.

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

Definition at line 132 of file ResourceLoaderFileModule.php.

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

Position on the page to load this module at *.

Definition at line 113 of file ResourceLoaderFileModule.php.

bool ResourceLoaderFileModule::$raw = false [protected]

Whether mw.loader.state() call should be omitted *.

Definition at line 117 of file ResourceLoaderFileModule.php.

string ResourceLoaderFileModule::$remoteBasePath = '' [protected]

Remote base path, see __construct() *.

Definition at line 33 of file ResourceLoaderFileModule.php.

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

List of paths to JavaScript files to always include.

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

Definition at line 41 of file ResourceLoaderFileModule.php.

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

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.

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

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.

string ResourceLoaderFileModule::$skipFunction = null [protected]

File name containing the body of the skip function.

Definition at line 101 of file ResourceLoaderFileModule.php.

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

List of paths to CSS files to always include.

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

Definition at line 81 of file ResourceLoaderFileModule.php.

ResourceLoaderFileModule::$targets = array( 'desktop' ) [protected]

Reimplemented from ResourceLoaderModule.

Definition at line 119 of file ResourceLoaderFileModule.php.


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