MediaWiki  master
ResourceLoaderFileModule Class Reference

Module based on local JavaScript/CSS files. More...

Inheritance diagram for ResourceLoaderFileModule:
Collaboration diagram for ResourceLoaderFileModule:

Public Member Functions

 __construct (array $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 (ResourceLoaderContext $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...
 
 getPackageFiles (ResourceLoaderContext $context)
 Resolves the package files definition and generates the content of each package file. More...
 
 getScript (ResourceLoaderContext $context)
 Gets all scripts for a given context concatenated together. More...
 
 getScriptURLsForDebug (ResourceLoaderContext $context)
 
 getSkipFunction ()
 
 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...
 
 readStyleFiles (array $styles, ResourceLoaderContext $context)
 Get the contents of a list of CSS files. More...
 
 requiresES6 ()
 Whether the module requires ES6 support in the client. More...
 
 setSkinStylesOverride (array $moduleSkinStyles)
 Provide overrides for skinStyles to modules that support that. More...
 
 supportsURLLoading ()
 
- Public Member Functions inherited from ResourceLoaderModule
 getConfig ()
 
 getDeprecationInformation (ResourceLoaderContext $context)
 Get JS representing deprecation information for the current module if available. More...
 
 getHeaders (ResourceLoaderContext $context)
 Get headers to send as part of a module web response. More...
 
 getModuleContent (ResourceLoaderContext $context)
 Get an array of this module's resources. More...
 
 getName ()
 Get this module's name. More...
 
 getOrigin ()
 Get this module's origin. More...
 
 getSkins ()
 Get list of skins for which this module must be available to load. More...
 
 getSource ()
 Get the source of this module. More...
 
 getVersionHash (ResourceLoaderContext $context)
 Get a string identifying the current version of this module in a given context. More...
 
 isKnownEmpty (ResourceLoaderContext $context)
 Check whether this module is known to be empty. More...
 
 setConfig (Config $config)
 
 setDependencyAccessCallbacks (callable $loadCallback, callable $saveCallback)
 Inject the functions that load/save the indirect file path dependency list from storage. More...
 
 setFileDependencies (ResourceLoaderContext $context, array $paths)
 Set the indirect dependencies for this module pursuant to the skin/language context. More...
 
 setHookContainer (HookContainer $hookContainer)
 
 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 embedded rather than linked. More...
 

Static Public Member Functions

static extractBasePaths (array $options=[], $localBasePath=null, $remoteBasePath=null)
 Extract a pair of local and remote base paths from module definition information. More...
 
static getPackageFileType ( $path)
 Infer the file type from a package file path. 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...
 
static getVary (ResourceLoaderContext $context)
 Get vary string. More...
 

Protected Member Functions

 compileLessFile ( $fileName, ResourceLoaderContext $context)
 
 compileLessString ( $style, $stylePath, ResourceLoaderContext $context)
 Compile a LESS string into CSS. More...
 
 getAllSkinStyleFiles ()
 Gets a list of file paths for all skin style files in the module, for all available skins. More...
 
 getLocalPath ( $path)
 
 getPath ( $path)
 
 getRemotePath ( $path)
 
 getSkinStyleFiles ( $skinName)
 Gets a list of file paths for all skin styles in the module used by the skin. More...
 
 getVueComponentParser ()
 
 processStyle ( $style, $styleLang, $path, ResourceLoaderContext $context)
 Process a CSS/LESS string. More...
 
 readStyleFile ( $path, ResourceLoaderContext $context)
 Read and process 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
 buildContent (ResourceLoaderContext $context)
 Bundle all resources attached to this module into an array. More...
 
 getFileDependencies (ResourceLoaderContext $context)
 Get the indirect dependencies for this module pursuant to the skin/language context. More...
 
 getHookRunner ()
 Get a HookRunner for running core hooks. More...
 
 getLessVars (ResourceLoaderContext $context)
 Get module-specific LESS variables, if any. More...
 
 getLogger ()
 
 getMessageBlob (ResourceLoaderContext $context)
 Get the hash of the message blob. More...
 
 getPreloadLinks (ResourceLoaderContext $context)
 Get a list of resources that web browsers may preload. More...
 
 saveFileDependencies (ResourceLoaderContext $context, array $curFileRefs)
 Save the indirect dependencies for this module pursuant to the skin/language context. More...
 
 validateScriptFile ( $fileName, $contents)
 Validate a user-provided JavaScript blob. 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 safeFileHash ( $filePath)
 Compute a non-cryptographic string hash of a file's contents. 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...
 
bool $es6 = false
 Whether this module requires the client to support ES6. 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...
 
array $packageFiles = null
 List of packaged files to make available through require() 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...
 
string[] $targets = [ 'desktop' ]
 
array $templates = []
 Saves a list of the templates named by the modules. More...
 
VueComponentParser null $vueComponentParser = null
 Lazy-created by getVueComponentParser() More...
 
- Protected Attributes inherited from ResourceLoaderModule
Config $config
 
array $contents = []
 Map of (context hash => cached module content) More...
 
string bool $deprecated = false
 Deprecation string or true if deprecated; false otherwise. More...
 
array $fileDeps = []
 Map of (variant => indirect file dependencies) More...
 
LoggerInterface $logger
 
array $msgBlobs = []
 Map of (language => in-object cache for message blob) More...
 
string null $name = null
 Module name. More...
 
int $origin = self::ORIGIN_CORE_SITEWIDE
 Script and style modules form a hierarchy of trustworthiness, with core modules like skins and jQuery as most trustworthy, and user scripts as least trustworthy. More...
 
string[] null $skins = null
 Skin names. More...
 
string[] $targets = [ 'desktop' ]
 What client platforms the module targets (e.g. More...
 
array $versionHash = []
 Map of (context hash => cached module version hash) More...
 

Private Member Functions

 expandPackageFiles (ResourceLoaderContext $context)
 Internal helper for use by getPackageFiles(), getFileHashes() and getDefinitionSummary(). More...
 
 getFileContents ( $localPath, $type)
 Helper method for getting a file. More...
 
 getFileHashes (ResourceLoaderContext $context)
 Helper method for getDefinitionSummary. More...
 
 getLanguageScripts (string $lang)
 Get the set of language scripts for the given language, possibly using a fallback language. More...
 
 getScriptFiles (ResourceLoaderContext $context)
 Get a list of script file paths for this module, in order of proper execution. More...
 
 readScriptFiles (array $scripts)
 Get the contents of a list of JavaScript files. More...
 

Private Attributes

array $expandedPackageFiles = []
 Expanded versions of $packageFiles, lazy-computed by expandPackageFiles(); keyed by context hash. More...
 
array $fullyExpandedPackageFiles = []
 Further expanded versions of $expandedPackageFiles, lazy-computed by getPackageFiles(); keyed by context hash. More...
 

Detailed Description

Module based on local JavaScript/CSS files.

The following public methods can query the database:

See also
$wgResourceModules
Since
1.17

Definition at line 42 of file ResourceLoaderFileModule.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructs a new module from an options array.

Parameters
array$optionsSee $wgResourceModules for the available options.
string | null$localBasePathBase path to prepend to all local paths in $options. Defaults to $IP
string | null$remoteBasePathBase path to prepend to all remote paths in $options. Defaults to $wgResourceBasePath
Exceptions
InvalidArgumentException
See also
$wgResourceModules

Reimplemented in ResourceLoaderSkinModule, ResourceLoaderLessVarFileModule, and ResourceLoaderCodexModule.

Definition at line 202 of file ResourceLoaderFileModule.php.

References $localBasePath, $remoteBasePath, extractBasePaths(), and getPath().

Member Function Documentation

◆ collateFilePathListByOption()

static ResourceLoaderFileModule::collateFilePathListByOption ( array  $list,
  $option,
  $default 
)
staticprotected

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
string[][] List of file paths, collated by $option

Definition at line 753 of file ResourceLoaderFileModule.php.

◆ compileLessFile()

ResourceLoaderFileModule::compileLessFile (   $fileName,
ResourceLoaderContext  $context 
)
protected
Deprecated:
since 1.35 Use compileLessString() instead
Parameters
string$fileName
ResourceLoaderContext$context
Returns
string

Definition at line 1119 of file ResourceLoaderFileModule.php.

References wfDeprecated().

◆ compileLessString()

ResourceLoaderFileModule::compileLessString (   $style,
  $stylePath,
ResourceLoaderContext  $context 
)
protected

Compile a LESS string into CSS.

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

Since
1.35
Exceptions
ExceptionIf less.php encounters a parse error
Parameters
string$styleLESS source to compile
string$stylePathFile path of LESS source, used for resolving relative file paths
ResourceLoaderContext$contextContext in which to generate script
Returns
string CSS source

Definition at line 1138 of file ResourceLoaderFileModule.php.

References $cache, $path, CACHE_ANYTHING, ResourceLoaderModule\expandRelativePaths(), FileContentsHasher\getFileContentsHash(), ExtensionRegistry\getInstance(), ObjectCache\getLocalServerInstance(), ResourceLoaderModule\getRelativePaths(), ResourceLoaderContext\getResourceLoader(), ResourceLoaderContext\getSkin(), and serialize().

◆ enableModuleContentVersion()

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.

Returns
bool

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderLanguageDataModule.

Definition at line 542 of file ResourceLoaderFileModule.php.

◆ expandPackageFiles()

ResourceLoaderFileModule::expandPackageFiles ( ResourceLoaderContext  $context)
private

Internal helper for use by getPackageFiles(), getFileHashes() and getDefinitionSummary().

This expands the 'packageFiles' definition into something that's (almost) the right format for getPackageFiles() to return. It expands shorthands, resolves config vars, and handles summarising any non-file data for getVersionHash(). For file-based data, getFileHashes() handles it instead, which also ends up in getDefinitionSummary().

What it does not do is reading the actual contents of any specified files, nor invoking the computation callbacks. Those things are done by getPackageFiles() instead to improve backend performance by only doing this work when the module response is needed, and not when merely computing the version hash for StartupModule, or when checking If-None-Match headers for a HTTP 304 response.

Parameters
ResourceLoaderContext$context
Returns
array|null
Exceptions
LogicExceptionIf the 'packageFiles' definition is invalid.

Definition at line 1236 of file ResourceLoaderFileModule.php.

References $file, $path, $type, and ResourceLoaderContext\getHash().

Referenced by getDefinitionSummary(), and getFileHashes().

◆ extractBasePaths()

static ResourceLoaderFileModule::extractBasePaths ( array  $options = [],
  $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 | null$localBasePathPath to use if not provided in module definition. Defaults to $IP
string | null$remoteBasePathPath to use if not provided in module definition. Defaults to $wgResourceBasePath
Returns
string[] [ localBasePath, remoteBasePath ]

Definition at line 308 of file ResourceLoaderFileModule.php.

References $IP, $localBasePath, and $remoteBasePath.

Referenced by __construct(), ResourceLoaderSkinModule\getStyleFiles(), and getThemePaths().

◆ getAllSkinStyleFiles()

ResourceLoaderFileModule::getAllSkinStyleFiles ( )
protected

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 920 of file ResourceLoaderFileModule.php.

◆ getAllStyleFiles()

ResourceLoaderFileModule::getAllStyleFiles ( )

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

Returns
array

Definition at line 942 of file ResourceLoaderFileModule.php.

◆ getDefinitionSummary()

ResourceLoaderFileModule::getDefinitionSummary ( ResourceLoaderContext  $context)

Get the definition summary for this module.

Parameters
ResourceLoaderContext$context
Returns
array

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderSkinModule.

Definition at line 612 of file ResourceLoaderFileModule.php.

References $packageFiles, expandPackageFiles(), getFileHashes(), ResourceLoaderModule\getLessVars(), and ResourceLoaderModule\getMessageBlob().

◆ getDependencies()

ResourceLoaderFileModule::getDependencies ( ResourceLoaderContext  $context = null)

Gets list of names of modules this module depends on.

Parameters
ResourceLoaderContext | null$context
Returns
string[] List of module names

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderForeignApiModule.

Definition at line 497 of file ResourceLoaderFileModule.php.

References $dependencies.

◆ getFileContents()

ResourceLoaderFileModule::getFileContents (   $localPath,
  $type 
)
private

Helper method for getting a file.

Parameters
string$localPathThe path to the resource to load
string$typeThe type of resource being loaded (for error reporting only)
Exceptions
RuntimeExceptionIf the supplied path is not found, or not a path
Returns
string

Definition at line 509 of file ResourceLoaderFileModule.php.

References stripBom().

Referenced by getSkipFunction().

◆ getFileHashes()

◆ getFlip()

ResourceLoaderFileModule::getFlip ( ResourceLoaderContext  $context)

Get whether CSS for this module should be flipped.

Parameters
ResourceLoaderContext$context
Returns
bool

Reimplemented from ResourceLoaderModule.

Definition at line 1077 of file ResourceLoaderFileModule.php.

References ResourceLoaderContext\getDirection().

◆ getGroup()

ResourceLoaderFileModule::getGroup ( )

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

Returns
string Group name

Reimplemented from ResourceLoaderModule.

Definition at line 488 of file ResourceLoaderFileModule.php.

References $group.

◆ getLanguageScripts()

ResourceLoaderFileModule::getLanguageScripts ( string  $lang)
private

Get the set of language scripts for the given language, possibly using a fallback language.

Parameters
string$lang
Returns
string[]

Definition at line 823 of file ResourceLoaderFileModule.php.

References $scripts.

Referenced by getScriptFiles().

◆ getLocalPath()

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

Definition at line 694 of file ResourceLoaderFileModule.php.

References $path.

Referenced by getSkipFunction().

◆ getMessages()

ResourceLoaderFileModule::getMessages ( )

Gets list of message keys used by this module.

Returns
string[] List of message keys

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderLessVarFileModule.

Definition at line 479 of file ResourceLoaderFileModule.php.

References $messages.

◆ getPackageFiles()

ResourceLoaderFileModule::getPackageFiles ( ResourceLoaderContext  $context)

Resolves the package files definition and generates the content of each package file.

Parameters
ResourceLoaderContext$context
Returns
array|null Package files data structure, see ResourceLoaderModule::getScript()
Exceptions
RuntimeExceptionIf a file doesn't exist, or parsing a .vue file fails

Definition at line 1373 of file ResourceLoaderFileModule.php.

References $content, ResourceLoaderContext\getDebug(), and ResourceLoaderContext\getHash().

Referenced by getScript(), and getStyles().

◆ getPackageFileType()

static ResourceLoaderFileModule::getPackageFileType (   $path)
static

Infer the file type from a package file path.

Parameters
string$path
Returns
string 'script', 'script-vue', or 'data'

Definition at line 734 of file ResourceLoaderFileModule.php.

References $path.

◆ getPath()

ResourceLoaderFileModule::getPath (   $path)
protected
Parameters
string | ResourceLoaderFilePath$path
Returns
string

Definition at line 682 of file ResourceLoaderFileModule.php.

References $path.

Referenced by __construct().

◆ getRemotePath()

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

Definition at line 706 of file ResourceLoaderFileModule.php.

References $path.

Referenced by getScriptURLsForDebug(), and getStyleURLsForDebug().

◆ getScript()

ResourceLoaderFileModule::getScript ( ResourceLoaderContext  $context)

Gets all scripts for a given context concatenated together.

Parameters
ResourceLoaderContext$contextContext in which to generate script
Returns
string|array JavaScript code for $context, or package files data structure

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderLanguageDataModule.

Definition at line 366 of file ResourceLoaderFileModule.php.

References $file, $packageFiles, ResourceLoaderModule\getDeprecationInformation(), getPackageFiles(), getScriptFiles(), and readScriptFiles().

◆ getScriptFiles()

ResourceLoaderFileModule::getScriptFiles ( ResourceLoaderContext  $context)
private

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

Parameters
ResourceLoaderContext$context
Returns
string[] List of file paths

Definition at line 801 of file ResourceLoaderFileModule.php.

References ResourceLoaderContext\getDebug(), ResourceLoaderContext\getLanguage(), getLanguageScripts(), and ResourceLoaderContext\getSkin().

Referenced by getScript(), and getScriptURLsForDebug().

◆ getScriptURLsForDebug()

◆ getSkinStyleFiles()

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 906 of file ResourceLoaderFileModule.php.

◆ getSkipFunction()

ResourceLoaderFileModule::getSkipFunction ( )
Returns
null|string
Exceptions
RuntimeExceptionIf the file doesn't exist

Reimplemented from ResourceLoaderModule.

Definition at line 522 of file ResourceLoaderFileModule.php.

References getFileContents(), and getLocalPath().

◆ getStyleFiles()

ResourceLoaderFileModule::getStyleFiles ( ResourceLoaderContext  $context)

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

Access: internal
Exposed only for use by structure phpunit tests.
Parameters
ResourceLoaderContext$context
Returns
string[][] List of file paths

Reimplemented in ResourceLoaderSkinModule, and ResourceLoaderCodexModule.

Definition at line 888 of file ResourceLoaderFileModule.php.

References ResourceLoaderContext\getSkin().

Referenced by getFileHashes(), getStyles(), and getStyleURLsForDebug().

◆ getStyles()

ResourceLoaderFileModule::getStyles ( ResourceLoaderContext  $context)

Get all styles for a given context.

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

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderSkinModule.

Definition at line 421 of file ResourceLoaderFileModule.php.

References $file, $packageFiles, $styles, getPackageFiles(), getStyleFiles(), processStyle(), readStyleFiles(), and ResourceLoaderModule\saveFileDependencies().

◆ getStyleSheetLang()

ResourceLoaderFileModule::getStyleSheetLang (   $path)

Infer the stylesheet language from a stylesheet file path.

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

Definition at line 725 of file ResourceLoaderFileModule.php.

References $path.

◆ getStyleURLsForDebug()

ResourceLoaderFileModule::getStyleURLsForDebug ( ResourceLoaderContext  $context)

◆ getTargets()

ResourceLoaderFileModule::getTargets ( )

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

Returns
string[]

Reimplemented from ResourceLoaderModule.

Definition at line 1086 of file ResourceLoaderFileModule.php.

◆ getTemplates()

ResourceLoaderFileModule::getTemplates ( )

Takes named templates by the module and returns an array mapping.

Returns
array Templates mapping template alias to content
Exceptions
RuntimeExceptionIf a file doesn't exist

Reimplemented from ResourceLoaderModule.

Definition at line 1201 of file ResourceLoaderFileModule.php.

References $content.

◆ getType()

ResourceLoaderFileModule::getType ( )

Get the module's load type.

Since
1.28
Returns
string

Reimplemented from ResourceLoaderModule.

Definition at line 1096 of file ResourceLoaderFileModule.php.

◆ getVueComponentParser()

ResourceLoaderFileModule::getVueComponentParser ( )
protected
Returns
VueComponentParser

Definition at line 671 of file ResourceLoaderFileModule.php.

References $vueComponentParser.

◆ processStyle()

ResourceLoaderFileModule::processStyle (   $style,
  $styleLang,
  $path,
ResourceLoaderContext  $context 
)
protected

Process a CSS/LESS string.

This method performs the following processing steps:

  • LESS compilation (if $styleLang = 'less')
  • RTL flipping with CSSJanus (if getFlip() returns true)
  • Registration of references to local files in $localFileRefs and $missingLocalFileRefs
  • URL remapping and data URI embedding
Access: internal
Parameters
string$styleCSS/LESS string
string$styleLangLanguage of $style ('css' or 'less')
string$pathFile path where the CSS/LESS lives, used for resolving relative file paths
ResourceLoaderContext$context
Returns
string Processed CSS

Definition at line 1039 of file ResourceLoaderFileModule.php.

References $file, and $path.

Referenced by getStyles().

◆ readScriptFiles()

ResourceLoaderFileModule::readScriptFiles ( array  $scripts)
private

Get the contents of a list of JavaScript files.

Helper for getScript().

Parameters
string[]$scriptsList of file paths to scripts to read, remap and concatenate
Returns
string Concatenated JavaScript data from $scripts
Exceptions
RuntimeException

Definition at line 966 of file ResourceLoaderFileModule.php.

References ResourceLoader\ensureNewline().

Referenced by getScript().

◆ readStyleFile()

ResourceLoaderFileModule::readStyleFile (   $path,
ResourceLoaderContext  $context 
)
protected

Read and process a style file.

Reads a file from disk and runs it through processStyle().

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

Access: internal
Parameters
string$pathFile path of style file to read
ResourceLoaderContext$context
Returns
string CSS data in script file
Exceptions
RuntimeExceptionIf the file doesn't exist

Definition at line 1015 of file ResourceLoaderFileModule.php.

References $path.

◆ readStyleFiles()

ResourceLoaderFileModule::readStyleFiles ( array  $styles,
ResourceLoaderContext  $context 
)

Get the contents of a list of CSS files.

Access: internal
This is considered a private method. Exposed for internal use by WebInstallerOutput.
Parameters
array$stylesMap of media type to file paths to read, remap, and concatenate
ResourceLoaderContext$context
Returns
string[] List of concatenated and remapped CSS data from $styles, keyed by media type
Exceptions
RuntimeException

Definition at line 989 of file ResourceLoaderFileModule.php.

References $file.

Referenced by getStyles().

◆ requiresES6()

ResourceLoaderFileModule::requiresES6 ( )

Whether the module requires ES6 support in the client.

If the client does not support ES6, attempting to load a module that requires ES6 will result in an error.

Stability: stable
to override
Since
1.36
Returns
bool

Reimplemented from ResourceLoaderModule.

Definition at line 530 of file ResourceLoaderFileModule.php.

References $es6.

◆ setSkinStylesOverride()

ResourceLoaderFileModule::setSkinStylesOverride ( array  $moduleSkinStyles)

Provide overrides for skinStyles to modules that support that.

This MUST be called after self::setName().

Since
1.37
See also
$wgResourceModuleSkinStyles
Parameters
array$moduleSkinStyles

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderOOUIFileModule.

Definition at line 846 of file ResourceLoaderFileModule.php.

References $path.

◆ stripBom()

ResourceLoaderFileModule::stripBom (   $input)
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.

Parameters
string$input
Returns
string Input minus the initial BOM char

Definition at line 1469 of file ResourceLoaderFileModule.php.

Referenced by getFileContents().

◆ supportsURLLoading()

ResourceLoaderFileModule::supportsURLLoading ( )
Returns
bool

Reimplemented from ResourceLoaderModule.

Reimplemented in ResourceLoaderLanguageDataModule.

Definition at line 409 of file ResourceLoaderFileModule.php.

References $packageFiles.

◆ tryForKey()

static ResourceLoaderFileModule::tryForKey ( array  $list,
  $key,
  $fallback = null 
)
staticprotected

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 $list
string | null$fallbackKey to look for in $list if $key doesn't exist
Returns
array List of elements from $list which matched $key or $fallback, or an empty list in case of no match

Definition at line 783 of file ResourceLoaderFileModule.php.

References $fallback.

Member Data Documentation

◆ $debugRaw

bool ResourceLoaderFileModule::$debugRaw = true
protected

Link to raw files in debug mode.

Definition at line 154 of file ResourceLoaderFileModule.php.

◆ $debugScripts

array ResourceLoaderFileModule::$debugScripts = []
protected

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

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

Definition at line 86 of file ResourceLoaderFileModule.php.

◆ $dependencies

array ResourceLoaderFileModule::$dependencies = []
protected

List of modules this module depends on.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 134 of file ResourceLoaderFileModule.php.

Referenced by getDependencies(), and ResourceLoaderForeignApiModule\getDependencies().

◆ $es6

bool ResourceLoaderFileModule::$es6 = false
protected

Whether this module requires the client to support ES6.

Definition at line 163 of file ResourceLoaderFileModule.php.

Referenced by requiresES6().

◆ $expandedPackageFiles

array ResourceLoaderFileModule::$expandedPackageFiles = []
private

Expanded versions of $packageFiles, lazy-computed by expandPackageFiles(); keyed by context hash.

Definition at line 119 of file ResourceLoaderFileModule.php.

Referenced by getFileHashes().

◆ $fullyExpandedPackageFiles

array ResourceLoaderFileModule::$fullyExpandedPackageFiles = []
private

Further expanded versions of $expandedPackageFiles, lazy-computed by getPackageFiles(); keyed by context hash.

Definition at line 125 of file ResourceLoaderFileModule.php.

◆ $group

string ResourceLoaderFileModule::$group
protected

Name of group to load this module in.

Definition at line 151 of file ResourceLoaderFileModule.php.

Referenced by getGroup().

◆ $hasGeneratedStyles

bool ResourceLoaderFileModule::$hasGeneratedStyles = false
protected

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

Definition at line 169 of file ResourceLoaderFileModule.php.

◆ $languageScripts

array ResourceLoaderFileModule::$languageScripts = []
protected

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

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

Definition at line 68 of file ResourceLoaderFileModule.php.

◆ $localBasePath

string ResourceLoaderFileModule::$localBasePath = ''
protected

◆ $localFileRefs

array ResourceLoaderFileModule::$localFileRefs = []
protected

Place where readStyleFile() tracks file dependencies.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 178 of file ResourceLoaderFileModule.php.

◆ $messages

array ResourceLoaderFileModule::$messages = []
protected

List of message keys used by this module.

Usage:
[ [message-key], [message-key], ... ]

Definition at line 148 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderSkinModule\__construct(), ResourceLoaderSkinModule\applyFeaturesCompatibility(), and getMessages().

◆ $missingLocalFileRefs

array ResourceLoaderFileModule::$missingLocalFileRefs = []
protected

Place where readStyleFile() tracks file dependencies for non-existent files.

Used in tests to detect missing dependencies.

Definition at line 184 of file ResourceLoaderFileModule.php.

◆ $noflip

bool ResourceLoaderFileModule::$noflip = false
protected

Whether CSSJanus flipping should be skipped for this module.

Definition at line 160 of file ResourceLoaderFileModule.php.

◆ $packageFiles

array ResourceLoaderFileModule::$packageFiles = null
protected

List of packaged files to make available through require()

Usage:
[ [file-path-or-object], [file-path-or-object], ... ]

Definition at line 113 of file ResourceLoaderFileModule.php.

Referenced by getDefinitionSummary(), getFileHashes(), getScript(), getStyles(), and supportsURLLoading().

◆ $remoteBasePath

string ResourceLoaderFileModule::$remoteBasePath = ''
protected

◆ $scripts

array ResourceLoaderFileModule::$scripts = []
protected

List of paths to JavaScript files to always include.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 59 of file ResourceLoaderFileModule.php.

Referenced by getLanguageScripts().

◆ $skinScripts

array ResourceLoaderFileModule::$skinScripts = []
protected

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

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

Definition at line 77 of file ResourceLoaderFileModule.php.

Referenced by ResourceLoaderOOUIFileModule\__construct().

◆ $skinStyles

array ResourceLoaderFileModule::$skinStyles = []
protected

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

Usage:
[ [file-path], [file-path], ... ]

Definition at line 104 of file ResourceLoaderFileModule.php.

◆ $skipFunction

string ResourceLoaderFileModule::$skipFunction = null
protected

File name containing the body of the skip function.

Definition at line 139 of file ResourceLoaderFileModule.php.

Referenced by getFileHashes().

◆ $styles

array ResourceLoaderFileModule::$styles = []
protected

List of paths to CSS files to always include.

Usage:
[ [file-path], [file-path], ... ]

Definition at line 95 of file ResourceLoaderFileModule.php.

Referenced by getStyles().

◆ $targets

string [] ResourceLoaderFileModule::$targets = [ 'desktop' ]
protected

Definition at line 157 of file ResourceLoaderFileModule.php.

◆ $templates

array ResourceLoaderFileModule::$templates = []
protected

Saves a list of the templates named by the modules.

Definition at line 50 of file ResourceLoaderFileModule.php.

◆ $vueComponentParser

VueComponentParser null ResourceLoaderFileModule::$vueComponentParser = null
protected

Lazy-created by getVueComponentParser()

Definition at line 189 of file ResourceLoaderFileModule.php.

Referenced by getVueComponentParser().


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