MediaWiki
1.30.0
|
ResourceLoader module based on local JavaScript/CSS files. More...
Public Member Functions | |
__construct ( $options=[], $localBasePath=null, $remoteBasePath=null) | |
Constructs a new module from an options array. More... | |
enableModuleContentVersion () | |
Disable module content versioning. More... | |
getAllStyleFiles () | |
Returns all style files and all skin style files used by this module. More... | |
getDefinitionSummary (ResourceLoaderContext $context) | |
Get the definition summary for this module. More... | |
getDependencies (ResourceLoaderContext $context=null) | |
Gets list of names of modules this module depends on. More... | |
getFlip ( $context) | |
Get whether CSS for this module should be flipped. More... | |
getGroup () | |
Gets the name of the group this module should be loaded in. More... | |
getMessages () | |
Gets list of message keys used by this module. More... | |
getScript (ResourceLoaderContext $context) | |
Gets all scripts for a given context concatenated together. More... | |
getScriptURLsForDebug (ResourceLoaderContext $context) | |
getSkipFunction () | |
Get the skip function. More... | |
getStyleFiles (ResourceLoaderContext $context) | |
Get a list of file paths for all styles in this module, in order of proper inclusion. More... | |
getStyles (ResourceLoaderContext $context) | |
Get all styles for a given context. More... | |
getStyleSheetLang ( $path) | |
Infer the stylesheet language from a stylesheet file path. More... | |
getStyleURLsForDebug (ResourceLoaderContext $context) | |
getTargets () | |
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile']. More... | |
getTemplates () | |
Takes named templates by the module and returns an array mapping. More... | |
getType () | |
Get the module's load type. More... | |
isRaw () | |
readStyleFiles (array $styles, $flip, $context=null) | |
Gets the contents of a list of CSS files. More... | |
supportsURLLoading () | |
Public Member Functions inherited from ResourceLoaderModule | |
getConfig () | |
getDefinitionMtime (ResourceLoaderContext $context) | |
Back-compat dummy for old subclass implementations of getModifiedTime(). More... | |
getHashMtime (ResourceLoaderContext $context) | |
Back-compat dummy for old subclass implementations of getModifiedTime(). More... | |
getHeaders (ResourceLoaderContext $context) | |
Get headers to send as part of a module web response. More... | |
getModifiedHash (ResourceLoaderContext $context) | |
Helper method for providing a version hash to getVersionHash(). More... | |
getModifiedTime (ResourceLoaderContext $context) | |
Get this module's last modification timestamp for a given context. More... | |
getName () | |
Get this module's name. More... | |
getOrigin () | |
Get this module's origin. More... | |
getPosition () | |
From where in the page HTML should this module be loaded? More... | |
getSource () | |
Get the origin of this module. More... | |
isKnownEmpty (ResourceLoaderContext $context) | |
Check whether this module is known to be empty. More... | |
setConfig (Config $config) | |
setFileDependencies (ResourceLoaderContext $context, $files) | |
Set in-object cache for file dependencies. More... | |
setLogger (LoggerInterface $logger) | |
setMessageBlob ( $blob, $lang) | |
Set in-object cache for message blobs. More... | |
setName ( $name) | |
Set this module's name. More... | |
shouldEmbedModule (ResourceLoaderContext $context) | |
Check whether this module should be embeded rather than linked. More... | |
Static Public Member Functions | |
static | extractBasePaths ( $options=[], $localBasePath=null, $remoteBasePath=null) |
Extract a pair of local and remote base paths from module definition information. More... | |
Static Public Member Functions inherited from ResourceLoaderModule | |
static | expandRelativePaths (array $filePaths) |
Expand directories relative to $IP. More... | |
static | getRelativePaths (array $filePaths) |
Make file paths relative to MediaWiki directory. More... | |
Protected Member Functions | |
compileLessFile ( $fileName, ResourceLoaderContext $context) | |
Compile a LESS file into CSS. More... | |
getAllSkinStyleFiles () | |
Gets a list of file paths for all skin style files in the module, for all available skins. More... | |
getFileHashes (ResourceLoaderContext $context) | |
Helper method to gather file hashes for getDefinitionSummary. More... | |
getLocalPath ( $path) | |
getRemotePath ( $path) | |
getScriptFiles (ResourceLoaderContext $context) | |
Get a list of file paths for all scripts in this module, in order of proper execution. More... | |
getSkinStyleFiles ( $skinName) | |
Gets a list of file paths for all skin styles in the module used by the skin. More... | |
readScriptFiles (array $scripts) | |
Gets the contents of a list of JavaScript files. More... | |
readStyleFile ( $path, $flip, $context) | |
Reads a style file. More... | |
stripBom ( $input) | |
Takes an input string and removes the UTF-8 BOM character if present. More... | |
Protected Member Functions inherited from ResourceLoaderModule | |
getDeprecationInformation () | |
Get JS representing deprecation information for the current module if available. More... | |
getFileDependencies (ResourceLoaderContext $context) | |
Get the files this module depends on indirectly for a given skin. More... | |
getLogger () | |
getMessageBlob (ResourceLoaderContext $context) | |
Get the hash of the message blob. More... | |
saveFileDependencies (ResourceLoaderContext $context, $localFileRefs) | |
Set the files this module depends on indirectly for a given skin. More... | |
validateScriptFile ( $fileName, $contents) | |
Validate a given script file; if valid returns the original source. More... | |
Static Protected Member Functions | |
static | collateFilePathListByOption (array $list, $option, $default) |
Collates file paths by option (where provided). More... | |
static | tryForKey (array $list, $key, $fallback=null) |
Get a list of element that match a key, optionally using a fallback key. More... | |
Static Protected Member Functions inherited from ResourceLoaderModule | |
static | javaScriptParser () |
static | safeFileHash ( $filePath) |
Compute a non-cryptographic string hash of a file's contents. More... | |
static | safeFilemtime ( $filePath) |
Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist. More... | |
Protected Attributes | |
bool | $debugRaw = true |
Link to raw files in debug mode. More... | |
array | $debugScripts = [] |
List of paths to JavaScript files to include in debug mode. More... | |
array | $dependencies = [] |
List of modules this module depends on. More... | |
string | $group |
Name of group to load this module in. More... | |
bool | $hasGeneratedStyles = false |
Whether getStyleURLsForDebug should return raw file paths, or return load.php urls. More... | |
array | $languageScripts = [] |
List of JavaScript files to include when using a specific language. More... | |
string | $localBasePath = '' |
Local base path, see __construct() More... | |
array | $localFileRefs = [] |
Place where readStyleFile() tracks file dependencies. More... | |
array | $messages = [] |
List of message keys used by this module. More... | |
array | $missingLocalFileRefs = [] |
Place where readStyleFile() tracks file dependencies for non-existent files. More... | |
bool | $noflip = false |
Whether CSSJanus flipping should be skipped for this module. More... | |
bool | $raw = false |
Whether mw.loader.state() call should be omitted. More... | |
string | $remoteBasePath = '' |
Remote base path, see __construct() More... | |
array | $scripts = [] |
List of paths to JavaScript files to always include. More... | |
array | $skinScripts = [] |
List of JavaScript files to include when using a specific skin. More... | |
array | $skinStyles = [] |
List of paths to CSS files to include when using specific skins. More... | |
string | $skipFunction = null |
File name containing the body of the skip function. More... | |
array | $styles = [] |
List of paths to CSS files to always include. More... | |
$targets = [ 'desktop' ] | |
array | $templates = [] |
Saves a list of the templates named by the modules. More... | |
Protected Attributes inherited from ResourceLoaderModule | |
Config | $config |
$contents = [] | |
array bool | $deprecated = false |
$fileDeps = [] | |
LoggerInterface | $logger |
$msgBlobs = [] | |
$name = null | |
$origin = self::ORIGIN_CORE_SITEWIDE | |
$targets = [ 'desktop' ] | |
$versionHash = [] | |
Private Member Functions | |
getLanguageScripts ( $lang) | |
Get the set of language scripts for the given language, possibly using a fallback language. More... | |
Additional Inherited Members | |
Public Attributes inherited from ResourceLoaderModule | |
const | LOAD_GENERAL = 'general' |
const | LOAD_STYLES = 'styles' |
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_SCRIPTS = 'scripts' |
const | TYPE_STYLES = 'styles' |
ResourceLoader module based on local JavaScript/CSS files.
Definition at line 28 of file ResourceLoaderFileModule.php.
ResourceLoaderFileModule::__construct | ( | $options = [] , |
|
$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 $wgResourceBasePath |
Below is a description for the $options array:
InvalidArgumentException |
Reimplemented in CiteCSSFileModule.
Definition at line 211 of file ResourceLoaderFileModule.php.
References $localBasePath, $options, $remoteBasePath, $value, array(), as, extractBasePaths(), list, and string.
|
staticprotected |
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 636 of file ResourceLoaderFileModule.php.
References $value, array(), and as.
Referenced by getFileHashes(), and getSkinStyleFiles().
|
protected |
Compile a LESS file into CSS.
Keeps track of all used files and adds them to localFileRefs.
Exception | If less.php encounters a parse error |
string | $fileName | File path of LESS source |
ResourceLoaderContext | $context | Context in which to generate script |
Definition at line 958 of file ResourceLoaderFileModule.php.
References $cache, $context, $css, $vars, CACHE_ANYTHING, FileContentsHasher\getFileContentsHash(), ObjectCache\getLocalServerInstance(), and serialize().
Referenced by readStyleFile().
ResourceLoaderFileModule::enableModuleContentVersion | ( | ) |
Disable module content versioning.
This class uses getDefinitionSummary() instead, to avoid filesystem overhead involved with building the full module content inside a startup request.
Reimplemented in ResourceLoaderJqueryMsgModule, ResourceLoaderSyntaxHighlightVisualEditorModule, and ResourceLoaderMediaWikiUtilModule.
Definition at line 487 of file ResourceLoaderFileModule.php.
|
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.
array | $options | Module definition |
string | $localBasePath | Path to use if not provided in module definition. Defaults to $IP |
string | $remoteBasePath | Path to use if not provided in module definition. Defaults to $wgResourceBasePath |
Definition at line 310 of file ResourceLoaderFileModule.php.
References $IP, $localBasePath, $options, $remoteBasePath, $wgExtensionAssetsPath, $wgResourceBasePath, $wgStylePath, global, and string.
Referenced by __construct().
|
protected |
Gets a list of file paths for all skin style files in the module, for all available skins.
Definition at line 758 of file ResourceLoaderFileModule.php.
References as, Skin\getSkinNames(), and getSkinStyleFiles().
Referenced by getAllStyleFiles().
ResourceLoaderFileModule::getAllStyleFiles | ( | ) |
Returns all style files and all skin style files used by this module.
Definition at line 778 of file ResourceLoaderFileModule.php.
References as, getAllSkinStyleFiles(), and getLocalPath().
ResourceLoaderFileModule::getDefinitionSummary | ( | ResourceLoaderContext | $context | ) |
Get the definition summary for this module.
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Reimplemented in ResourceLoaderSkinModule.
Definition at line 551 of file ResourceLoaderFileModule.php.
References $context, $options, as, getFileHashes(), and ResourceLoaderModule\getMessageBlob().
ResourceLoaderFileModule::getDependencies | ( | ResourceLoaderContext | $context = null | ) |
Gets list of names of modules this module depends on.
ResourceLoaderContext | null | $context |
Reimplemented from ResourceLoaderModule.
Reimplemented in ResourceLoaderForeignApiModule.
Definition at line 447 of file ResourceLoaderFileModule.php.
References $dependencies.
|
protected |
Helper method to gather file hashes for getDefinitionSummary.
This function is context-sensitive, only computing hashes of files relevant to the given language, skin, etc.
ResourceLoaderContext | $context |
Definition at line 501 of file ResourceLoaderFileModule.php.
References $context, $skipFunction, $styles, as, collateFilePathListByOption(), ResourceLoaderModule\getFileDependencies(), ResourceLoaderContext\getLanguage(), getLanguageScripts(), and scripts.
Referenced by getDefinitionSummary().
ResourceLoaderFileModule::getFlip | ( | $context | ) |
Get whether CSS for this module should be flipped.
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Definition at line 911 of file ResourceLoaderFileModule.php.
References $context, and $noflip.
Referenced by getStyles().
ResourceLoaderFileModule::getGroup | ( | ) |
Gets the name of the group this module should be loaded in.
Reimplemented from ResourceLoaderModule.
Definition at line 438 of file ResourceLoaderFileModule.php.
References $group.
|
private |
Get the set of language scripts for the given language, possibly using a fallback language.
string | $lang |
Definition at line 704 of file ResourceLoaderFileModule.php.
References $lang, $scripts, as, Language\getFallbacksFor(), and tryForKey().
Referenced by getFileHashes(), and getScriptFiles().
|
protected |
string | ResourceLoaderFilePath | $path |
Definition at line 596 of file ResourceLoaderFileModule.php.
References $path.
Referenced by CiteCSSFileModule\__construct(), getAllStyleFiles(), getSkipFunction(), getTemplates(), readScriptFiles(), and readStyleFile().
ResourceLoaderFileModule::getMessages | ( | ) |
Gets list of message keys used by this module.
Reimplemented from ResourceLoaderModule.
Definition at line 429 of file ResourceLoaderFileModule.php.
References $messages.
|
protected |
string | ResourceLoaderFilePath | $path |
Definition at line 608 of file ResourceLoaderFileModule.php.
References $path.
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.
Reimplemented in ResourceLoaderRawFileModule, ResourceLoaderJqueryMsgModule, ResourceLoaderMediaWikiUtilModule, and ResourceLoaderSyntaxHighlightVisualEditorModule.
Definition at line 354 of file ResourceLoaderFileModule.php.
References ResourceLoaderModule\getDeprecationInformation(), getScriptFiles(), and readScriptFiles().
|
protected |
Get a list of file paths for all scripts in this module, in order of proper execution.
ResourceLoaderContext | $context |
Definition at line 684 of file ResourceLoaderFileModule.php.
References $context, ResourceLoaderContext\getLanguage(), getLanguageScripts(), and scripts.
Referenced by getScript(), and getScriptURLsForDebug().
ResourceLoaderFileModule::getScriptURLsForDebug | ( | ResourceLoaderContext | $context | ) |
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Reimplemented in ResourceLoaderJqueryMsgModule, and ResourceLoaderSyntaxHighlightVisualEditorModule.
Definition at line 363 of file ResourceLoaderFileModule.php.
References as, ResourceLoaderModule\getConfig(), getRemotePath(), getScriptFiles(), and OutputPage\transformResourcePath().
|
protected |
Gets a list of file paths for all skin styles in the module used by the skin.
string | $skinName | The name of the skin |
Definition at line 744 of file ResourceLoaderFileModule.php.
References collateFilePathListByOption().
Referenced by getAllSkinStyleFiles().
ResourceLoaderFileModule::getSkipFunction | ( | ) |
Get the skip function.
MWException |
Reimplemented from ResourceLoaderModule.
Definition at line 456 of file ResourceLoaderFileModule.php.
References ResourceLoaderModule\$contents, ResourceLoaderModule\getConfig(), getLocalPath(), stripBom(), and ResourceLoaderModule\validateScriptFile().
ResourceLoaderFileModule::getStyleFiles | ( | ResourceLoaderContext | $context | ) |
Get a list of file paths for all styles in this module, in order of proper inclusion.
ResourceLoaderContext | $context |
Definition at line 726 of file ResourceLoaderFileModule.php.
References $context.
Referenced by getStyles(), and getStyleURLsForDebug().
ResourceLoaderFileModule::getStyles | ( | ResourceLoaderContext | $context | ) |
Get all styles for a given context.
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Reimplemented in ResourceLoaderSkinModule.
Definition at line 387 of file ResourceLoaderFileModule.php.
References $context, $styles, getFlip(), getStyleFiles(), readStyleFiles(), and ResourceLoaderModule\saveFileDependencies().
ResourceLoaderFileModule::getStyleSheetLang | ( | $path | ) |
Infer the stylesheet language from a stylesheet file path.
string | $path |
Definition at line 623 of file ResourceLoaderFileModule.php.
References $path.
Referenced by readStyleFile().
ResourceLoaderFileModule::getStyleURLsForDebug | ( | ResourceLoaderContext | $context | ) |
ResourceLoaderContext | $context |
Reimplemented from ResourceLoaderModule.
Definition at line 403 of file ResourceLoaderFileModule.php.
References $context, as, ResourceLoaderModule\getConfig(), getRemotePath(), getStyleFiles(), and OutputPage\transformResourcePath().
ResourceLoaderFileModule::getTargets | ( | ) |
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Reimplemented from ResourceLoaderModule.
Definition at line 920 of file ResourceLoaderFileModule.php.
References $targets.
ResourceLoaderFileModule::getTemplates | ( | ) |
Takes named templates by the module and returns an array mapping.
MWException |
Reimplemented from ResourceLoaderModule.
Definition at line 1004 of file ResourceLoaderFileModule.php.
References $templates, as, getLocalPath(), stripBom(), and wfDebugLog().
ResourceLoaderFileModule::getType | ( | ) |
Get the module's load type.
Reimplemented from ResourceLoaderModule.
Definition at line 930 of file ResourceLoaderFileModule.php.
References $raw, ResourceLoaderModule\LOAD_GENERAL, ResourceLoaderModule\LOAD_STYLES, messages, and scripts.
ResourceLoaderFileModule::isRaw | ( | ) |
Reimplemented from ResourceLoaderModule.
Definition at line 475 of file ResourceLoaderFileModule.php.
References $raw.
|
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 802 of file ResourceLoaderFileModule.php.
References ResourceLoaderModule\$contents, $scripts, as, ResourceLoaderModule\getConfig(), getLocalPath(), stripBom(), and ResourceLoaderModule\validateScriptFile().
Referenced by getScript().
|
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 | |
ResourceLoaderContext | $context |
MWException | If the file doesn't exist |
Definition at line 871 of file ResourceLoaderFileModule.php.
References $context, $localFileRefs, $path, as, compileLessFile(), CSSMin\getLocalFileReferences(), getLocalPath(), getRemotePath(), getStyleSheetLang(), CSSMin\remap(), stripBom(), and wfDebugLog().
Referenced by readStyleFiles().
ResourceLoaderFileModule::readStyleFiles | ( | array | $styles, |
$flip, | |||
$context = null |
|||
) |
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 | |
ResourceLoaderContext | $context |
MWException |
Definition at line 839 of file ResourceLoaderFileModule.php.
References $context, $styles, as, ResourceLoaderContext\newDummyContext(), readStyleFile(), and wfDeprecated().
Referenced by getStyles().
|
protected |
Takes an input string and removes the UTF-8 BOM character if present.
We need to remove these after reading a file, because we concatenate our files and the BOM character is not valid in the middle of a string. We already assume UTF-8 everywhere, so this should be safe.
string | $input |
Definition at line 1035 of file ResourceLoaderFileModule.php.
References $input.
Referenced by getSkipFunction(), getTemplates(), readScriptFiles(), and readStyleFile().
ResourceLoaderFileModule::supportsURLLoading | ( | ) |
Reimplemented from ResourceLoaderModule.
Reimplemented in ResourceLoaderMediaWikiUtilModule.
Definition at line 377 of file ResourceLoaderFileModule.php.
References $debugRaw.
|
staticprotected |
Get 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 666 of file ResourceLoaderFileModule.php.
References $fallback.
Referenced by getLanguageScripts().
|
protected |
Link to raw files in debug mode.
Definition at line 121 of file ResourceLoaderFileModule.php.
Referenced by supportsURLLoading().
|
protected |
|
protected |
List of modules this module depends on.
Definition at line 101 of file ResourceLoaderFileModule.php.
Referenced by ResourceLoaderForeignApiModule\getDependencies(), and getDependencies().
|
protected |
Name of group to load this module in.
Definition at line 118 of file ResourceLoaderFileModule.php.
Referenced by getGroup().
|
protected |
Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
Definition at line 135 of file ResourceLoaderFileModule.php.
|
protected |
|
protected |
Local base path, see __construct()
Definition at line 32 of file ResourceLoaderFileModule.php.
Referenced by CiteCSSFileModule\__construct(), __construct(), and extractBasePaths().
|
protected |
Place where readStyleFile() tracks file dependencies.
Definition at line 144 of file ResourceLoaderFileModule.php.
Referenced by readStyleFile().
|
protected |
List of message keys used by this module.
Definition at line 115 of file ResourceLoaderFileModule.php.
Referenced by getMessages().
|
protected |
Place where readStyleFile() tracks file dependencies for non-existent files.
Used in tests to detect missing dependencies.
Definition at line 150 of file ResourceLoaderFileModule.php.
|
protected |
Whether CSSJanus flipping should be skipped for this module.
Definition at line 129 of file ResourceLoaderFileModule.php.
Referenced by getFlip().
|
protected |
Whether mw.loader.state() call should be omitted.
Definition at line 124 of file ResourceLoaderFileModule.php.
|
protected |
Remote base path, see __construct()
Definition at line 35 of file ResourceLoaderFileModule.php.
Referenced by CiteCSSFileModule\__construct(), __construct(), and extractBasePaths().
|
protected |
List of paths to JavaScript files to always include.
Definition at line 47 of file ResourceLoaderFileModule.php.
Referenced by getLanguageScripts(), ResourceLoaderSyntaxHighlightVisualEditorModule\getScript(), and readScriptFiles().
|
protected |
List of JavaScript files to include when using a specific skin.
Definition at line 65 of file ResourceLoaderFileModule.php.
Referenced by ResourceLoaderOOUIFileModule\__construct().
|
protected |
List of paths to CSS files to include when using specific skins.
Definition at line 92 of file ResourceLoaderFileModule.php.
Referenced by ResourceLoaderOOUIFileModule\__construct().
|
protected |
File name containing the body of the skip function.
Definition at line 106 of file ResourceLoaderFileModule.php.
Referenced by getFileHashes().
|
protected |
List of paths to CSS files to always include.
Definition at line 83 of file ResourceLoaderFileModule.php.
Referenced by getFileHashes(), ResourceLoaderSkinModule\getStyles(), getStyles(), ResourceLoaderSkinModule\normalizeStyles(), and readStyleFiles().
|
protected |
Definition at line 126 of file ResourceLoaderFileModule.php.
Referenced by getTargets().
|
protected |
Saves a list of the templates named by the modules.
Definition at line 38 of file ResourceLoaderFileModule.php.
Referenced by getTemplates().