MediaWiki
REL1_22
|
ResourceLoader module based on local JavaScript/CSS files. More...
Public Member Functions | |
__construct ($options=array(), $localBasePath=null, $remoteBasePath=null) | |
Constructs a new module from an options array. | |
getAllStyleFiles () | |
Returns all style files used by 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 () | |
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. | |
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 () | |
supportsURLLoading () | |
Protected Member Functions | |
compileLESSFile ($fileName) | |
Compile a LESS file into CSS. | |
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 | getLESSCacheKey ($fileName) |
Generate a cache key for a LESS file. | |
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. | |
$hasGeneratedStyles = false | |
Boolean: Whether getStyleURLsForDebug should return raw file paths, or return load.php urls. | |
$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. | |
$raw = false | |
Boolean: Whether mw.loader.state() call should be omitted. | |
$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. | |
$targets = array( 'desktop' ) |
ResourceLoader module based on local JavaScript/CSS files.
Definition at line 28 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::__construct | ( | $ | options = array() , |
$ | localBasePath = null , |
||
$ | remoteBasePath = null |
||
) |
Constructs a new module from an options array.
array | $options | List of options; if not given or empty, an empty module will be constructed |
string | $localBasePath | Base path to prepend to all local paths in $options. Defaults to $IP |
string | $remoteBasePath | Base path to prepend to all remote paths in $options. Defaults to $wgScriptPath |
Below is a description for the $options array:
MWException |
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' => [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'] )
Definition at line 195 of file ResourceLoaderFileModule.php.
References $IP, $key, $localBasePath, $options, $remoteBasePath, $value, array(), as, global, and wfExpandUrl().
static ResourceLoaderFileModule::collateFilePathListByOption | ( | array $ | list, |
$ | option, | ||
$ | default | ||
) | [static, protected] |
Collates file paths by option (where provided).
array | $list | List of file paths in any combination of index/path or path/options pairs |
string | $option | option name |
mixed | $default | default value if the option isn't set |
Definition at line 506 of file ResourceLoaderFileModule.php.
References $key, $value, array(), and as.
Referenced by getModifiedTime().
ResourceLoaderFileModule::compileLESSFile | ( | $ | fileName | ) | [protected] |
Compile a LESS file into CSS.
If invalid, returns replacement CSS source consisting of the compilation error message encoded as a comment. To save work, we cache a result object which comprises the compiled CSS and the names & mtimes of the files that were processed. lessphp compares the cached & current mtimes and recompiles as necessary.
string | $fileName | File path of LESS source |
Definition at line 751 of file ResourceLoaderFileModule.php.
References $cache, $key, $result, $source, getLESSCacheKey(), ResourceLoader\getLessCompiler(), and wfGetCache().
Referenced by readStyleFile().
Returns all style files used by this module.
Definition at line 586 of file ResourceLoaderFileModule.php.
References $files, $key, $path, $value, array(), as, and getLocalPath().
Gets list of names of modules this module depends on.
Reimplemented from ResourceLoaderModule.
Definition at line 390 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::getFlip | ( | $ | context | ) |
Get whether CSS for this module should be flipped.
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Definition at line 709 of file ResourceLoaderFileModule.php.
Referenced by getStyles().
Gets the name of the group this module should be loaded in.
Reimplemented from ResourceLoaderModule.
Definition at line 374 of file ResourceLoaderFileModule.php.
static ResourceLoaderFileModule::getLESSCacheKey | ( | $ | fileName | ) | [static, protected] |
Generate a cache key for a LESS file.
The cache key varies on the file name and the names and values of global LESS variables.
string | $fileName | File name of root LESS file. |
Definition at line 732 of file ResourceLoaderFileModule.php.
References $hash, $vars, ResourceLoader\getLESSVars(), and wfMemcKey().
Referenced by compileLESSFile().
Gets loader script.
Reimplemented from ResourceLoaderModule.
Definition at line 300 of file ResourceLoaderFileModule.php.
References readScriptFiles().
ResourceLoaderFileModule::getLocalPath | ( | $ | path | ) | [protected] |
string | $path |
Definition at line 474 of file ResourceLoaderFileModule.php.
Referenced by getAllStyleFiles(), readScriptFiles(), and readStyleFile().
Gets list of message keys used by this module.
Reimplemented from ResourceLoaderModule.
Definition at line 365 of file ResourceLoaderFileModule.php.
References messages.
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.
ResourceLoaderContext | $context | Context in which to calculate the modified time |
Reimplemented from ResourceLoaderModule.
Definition at line 415 of file ResourceLoaderFileModule.php.
References $files, $styles, array(), as, collateFilePathListByOption(), ResourceLoaderContext\getDebug(), ResourceLoaderModule\getFileDependencies(), ResourceLoaderContext\getHash(), ResourceLoaderContext\getLanguage(), ResourceLoaderModule\getMsgBlobMtime(), ResourceLoaderContext\getSkin(), scripts, tryForKey(), wfProfileIn(), and wfProfileOut().
Reimplemented from ResourceLoaderModule.
Definition at line 381 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::getRemotePath | ( | $ | path | ) | [protected] |
string | $path |
Definition at line 482 of file ResourceLoaderFileModule.php.
Referenced by getScriptURLsForDebug(), getStyleURLsForDebug(), and readStyleFile().
ResourceLoaderFileModule::getScript | ( | ResourceLoaderContext $ | context | ) |
Gets all scripts for a given context concatenated together.
ResourceLoaderContext | $context | Context in which to generate script |
Reimplemented from ResourceLoaderModule.
Definition at line 271 of file ResourceLoaderFileModule.php.
References $files, getScriptFiles(), and readScriptFiles().
ResourceLoaderFileModule::getScriptFiles | ( | ResourceLoaderContext $ | context | ) | [protected] |
Gets a list of file paths for all scripts in this module, in order of propper execution.
ResourceLoaderContext | $context |
Definition at line 554 of file ResourceLoaderFileModule.php.
References $files, ResourceLoaderContext\getDebug(), ResourceLoaderContext\getLanguage(), ResourceLoaderContext\getSkin(), and scripts.
Referenced by getScript(), and getScriptURLsForDebug().
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Definition at line 280 of file ResourceLoaderFileModule.php.
References $file, $urls, array(), as, getRemotePath(), and getScriptFiles().
ResourceLoaderFileModule::getStyleFiles | ( | ResourceLoaderContext $ | context | ) | [protected] |
Gets a list of file paths for all styles in this module, in order of propper inclusion.
ResourceLoaderContext | $context |
Definition at line 573 of file ResourceLoaderFileModule.php.
References ResourceLoaderContext\getSkin().
Referenced by getStyles(), and getStyleURLsForDebug().
ResourceLoaderFileModule::getStyles | ( | ResourceLoaderContext $ | context | ) |
Gets all styles for a given context concatenated together.
ResourceLoaderContext | $context | Context in which to generate styles |
Reimplemented from ResourceLoaderModule.
Definition at line 313 of file ResourceLoaderFileModule.php.
References $styles, array(), FormatJson\encode(), ResourceLoaderModule\getFileDependencies(), getFlip(), ResourceLoaderModule\getName(), ResourceLoaderContext\getSkin(), getStyleFiles(), readStyleFiles(), wfDebugLog(), and wfGetDB().
Infer the stylesheet language from a stylesheet file path.
string | $path |
Definition at line 493 of file ResourceLoaderFileModule.php.
References $path.
Referenced by readStyleFile().
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Definition at line 342 of file ResourceLoaderFileModule.php.
References $file, $urls, array(), as, getRemotePath(), and getStyleFiles().
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Reimplemented from ResourceLoaderModule.
Definition at line 718 of file ResourceLoaderFileModule.php.
Reimplemented from ResourceLoaderModule.
Definition at line 397 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::readScriptFiles | ( | array $ | scripts | ) | [protected] |
Gets the contents of a list of JavaScript files.
array | $scripts | List of file paths to scripts to read, remap and concetenate |
MWException |
Definition at line 606 of file ResourceLoaderFileModule.php.
References as, empty, getLocalPath(), global, and ResourceLoaderModule\validateScriptFile().
Referenced by getLoaderScript(), and getScript().
ResourceLoaderFileModule::readStyleFile | ( | $ | path, |
$ | flip | ||
) | [protected] |
Reads a style file.
This method can be used as a callback for array_map()
string | $path | File path of style file to read |
bool | $flip |
MWException | if the file doesn't exist |
Definition at line 669 of file ResourceLoaderFileModule.php.
References $dir, $path, compileLESSFile(), CSSMin\getLocalFileReferences(), getLocalPath(), getRemotePath(), getStyleSheetLang(), CSSMin\remap(), CSSJanus\transform(), and wfDebugLog().
ResourceLoaderFileModule::readStyleFiles | ( | array $ | styles, |
$ | flip | ||
) | [protected] |
Gets the contents of a list of CSS files.
array | $styles | List of media type/list of file paths pairs, to read, remap and concetenate |
bool | $flip |
Definition at line 640 of file ResourceLoaderFileModule.php.
References $files, $styles, array(), as, and empty.
Referenced by getStyles().
Reimplemented from ResourceLoaderModule.
Definition at line 291 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.
array | $list | List of lists to select from |
string | $key | Key to look for in $map |
string | $fallback | Key to look for in $list if $key doesn't exist |
Definition at line 536 of file ResourceLoaderFileModule.php.
References $fallback, $key, and array().
Referenced by getModifiedTime().
ResourceLoaderFileModule::$debugRaw = true [protected] |
Boolean: Link to raw files in debug mode.
Definition at line 113 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$debugScripts = array() [protected] |
ResourceLoaderFileModule::$dependencies = array() [protected] |
Array: List of modules this module depends on.
Definition at line 99 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$group [protected] |
String: Name of group to load this module in.
Definition at line 109 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$hasGeneratedStyles = false [protected] |
Boolean: Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
Definition at line 122 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$languageScripts = array() [protected] |
ResourceLoaderFileModule::$loaderScripts = array() [protected] |
Array: List of paths to JavaScript files to include in the startup module.
Definition at line 75 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$localBasePath = '' [protected] |
String: Local base path, see __construct()
Definition at line 33 of file ResourceLoaderFileModule.php.
Referenced by __construct().
ResourceLoaderFileModule::$localFileRefs = array() [protected] |
Array: Place where readStyleFile() tracks file dependencies.
Definition at line 139 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$modifiedTime = array() [protected] |
Array: Cache for mtime.
array( [hash] => [mtime], [hash] => [mtime], ... )
Definition at line 131 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$position = 'bottom' [protected] |
String: Position on the page to load this module at.
Definition at line 111 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$raw = false [protected] |
Boolean: Whether mw.loader.state() call should be omitted.
Definition at line 115 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$remoteBasePath = '' [protected] |
String: Remote base path, see __construct()
Definition at line 35 of file ResourceLoaderFileModule.php.
Referenced by __construct().
Array: List of paths to JavaScript files to always include.
Definition at line 43 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$skinScripts = array() [protected] |
ResourceLoaderFileModule::$skinStyles = array() [protected] |
Array: List of paths to CSS files to include when using specific skins.
Definition at line 91 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::$styles = array() [protected] |
Array: List of paths to CSS files to always include.
Definition at line 83 of file ResourceLoaderFileModule.php.
Referenced by getModifiedTime(), getStyles(), and readStyleFiles().
ResourceLoaderFileModule::$targets = array( 'desktop' ) [protected] |
Reimplemented from ResourceLoaderModule.
Definition at line 116 of file ResourceLoaderFileModule.php.