210 $localBasePath =
null,
211 $remoteBasePath =
null
214 $hasTemplates =
false;
217 list( $this->localBasePath, $this->remoteBasePath ) =
221 foreach (
$options as $member => $option ) {
227 $this->{$member} = (
array)$option;
230 $hasTemplates =
true;
231 $this->{$member} = (
array)$option;
234 case 'languageScripts':
237 if ( !is_array( $option ) ) {
238 throw new InvalidArgumentException(
239 "Invalid collated file path list error. " .
240 "'$option' given, array expected."
243 foreach ( $option as $key =>
$value ) {
244 if ( !is_string( $key ) ) {
245 throw new InvalidArgumentException(
246 "Invalid collated file path list key error. " .
247 "'$key' given, string expected."
254 $this->deprecated = $option;
261 $option = array_values( array_unique( (array)$option ) );
264 $this->{$member} = $option;
269 $this->{$member} = (
string)$option;
275 $this->{$member} = (bool)$option;
279 if ( $hasTemplates ) {
280 $this->dependencies[] =
'mediawiki.template';
282 foreach ( $this->templates as $alias => $templatePath ) {
283 if ( is_int( $alias ) ) {
284 $alias = $templatePath;
286 $suffix = explode(
'.', $alias );
287 $suffix = end( $suffix );
288 $compilerModule =
'mediawiki.template.' . $suffix;
289 if ( $suffix !==
'html' && !in_array( $compilerModule, $this->dependencies ) ) {
290 $this->dependencies[] = $compilerModule;
309 $localBasePath =
null,
310 $remoteBasePath =
null
324 if ( isset(
$options[
'remoteExtPath'] ) ) {
329 if ( isset(
$options[
'remoteSkinPath'] ) ) {
334 if ( array_key_exists(
'localBasePath',
$options ) ) {
338 if ( array_key_exists(
'remoteBasePath',
$options ) ) {
363 $urls[] = OutputPage::transformResourcePath(
375 return $this->debugRaw;
401 if ( $this->hasGeneratedStyles ) {
404 return parent::getStyleURLsForDebug(
$context );
410 $urls[$mediaType] = [];
411 foreach ( $list as $file ) {
412 $urls[$mediaType][] = OutputPage::transformResourcePath(
445 return $this->dependencies;
454 if ( !$this->skipFunction ) {
458 $localPath = $this->
getLocalPath( $this->skipFunction );
459 if ( !file_exists( $localPath ) ) {
460 throw new MWException( __METHOD__ .
": skip function file not found: \"$localPath\"" );
463 if ( $this->
getConfig()->
get(
'ResourceLoaderValidateStaticJS' ) ) {
502 $styles = self::collateFilePathListByOption( $this->styles,
'media',
'all' );
503 foreach (
$styles as $styleFiles ) {
504 $files = array_merge( $files, $styleFiles );
507 $skinFiles = self::collateFilePathListByOption(
508 self::tryForKey( $this->skinStyles,
$context->getSkin(),
'default' ),
512 foreach ( $skinFiles as $styleFiles ) {
513 $files = array_merge( $files, $styleFiles );
517 $files = array_merge(
521 $context->getDebug() ? $this->debugScripts : [],
523 self::tryForKey( $this->skinScripts,
$context->getSkin(),
'default' )
525 if ( $this->skipFunction ) {
526 $files[] = $this->skipFunction;
528 $files = array_map( [ $this,
'getLocalPath' ], $files );
534 $files = array_values( array_unique( $files ) );
539 return array_map( [ __CLASS__,
'safeFileHash' ], $files );
549 $summary = parent::getDefinitionSummary(
$context );
572 $options[$member] = $this->{$member};
583 $summary[] = [
'lessVars' => $lessVars ];
595 return $path->getLocalPath();
598 return "{$this->localBasePath}/$path";
607 return $path->getRemotePath();
610 return "{$this->remoteBasePath}/$path";
621 return preg_match(
'/\.less$/i', $path ) ?
'less' :
'css';
635 foreach ( (array)$list as $key =>
$value ) {
636 if ( is_int( $key ) ) {
638 if ( !isset( $collatedFiles[$default] ) ) {
639 $collatedFiles[$default] = [];
641 $collatedFiles[$default][] =
$value;
642 } elseif ( is_array(
$value ) ) {
644 $optionValue = isset(
$value[$option] ) ?
$value[$option] : $default;
645 if ( !isset( $collatedFiles[$optionValue] ) ) {
646 $collatedFiles[$optionValue] = [];
648 $collatedFiles[$optionValue][] = $key;
651 return $collatedFiles;
664 if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
682 $files = array_merge(
685 self::tryForKey( $this->skinScripts,
$context->getSkin(),
'default' )
688 $files = array_merge( $files, $this->debugScripts );
691 return array_unique( $files, SORT_REGULAR );
706 $fallbacks = Language::getFallbacksFor(
$lang );
707 foreach ( $fallbacks as
$lang ) {
724 return array_merge_recursive(
725 self::collateFilePathListByOption( $this->styles,
'media',
'all' ),
726 self::collateFilePathListByOption(
727 self::tryForKey( $this->skinStyles,
$context->getSkin(),
'default' ),
742 return self::collateFilePathListByOption(
743 self::tryForKey( $this->skinStyles, $skinName ),
757 $internalSkinNames = array_keys( Skin::getSkinNames() );
758 $internalSkinNames[] =
'default';
760 foreach ( $internalSkinNames as $internalSkinName ) {
761 $styleFiles = array_merge_recursive(
776 $collatedStyleFiles = array_merge_recursive(
777 self::collateFilePathListByOption( $this->styles,
'media',
'all' ),
783 foreach ( $collatedStyleFiles as $media => $styleFiles ) {
784 foreach ( $styleFiles as $styleFile ) {
800 if ( empty( $scripts ) ) {
804 foreach ( array_unique( $scripts, SORT_REGULAR ) as $fileName ) {
806 if ( !file_exists( $localPath ) ) {
807 throw new MWException( __METHOD__ .
": script file not found: \"$localPath\"" );
810 if ( $this->
getConfig()->
get(
'ResourceLoaderValidateStaticJS' ) ) {
838 wfDeprecated( __METHOD__ .
' without a ResourceLoader context',
'1.27' );
839 $context = ResourceLoaderContext::newDummyContext();
842 if ( empty( $styles ) ) {
845 foreach ( $styles as $media => $files ) {
846 $uniqueFiles = array_unique( $files, SORT_REGULAR );
848 foreach ( $uniqueFiles as $file ) {
851 $styles[$media] = implode(
"\n", $styleFiles );
871 if ( !file_exists( $localPath ) ) {
872 $msg = __METHOD__ .
": style file not found: \"$localPath\"";
879 $this->hasGeneratedStyles =
true;
881 $style = $this->
stripBom( file_get_contents( $localPath ) );
885 $style = CSSJanus::transform( $style,
true,
false );
887 $localDir = dirname( $localPath );
888 $remoteDir = dirname( $remotePath );
890 $localFileRefs = CSSMin::getLocalFileReferences( $style, $localDir );
892 if ( file_exists( $file ) ) {
893 $this->localFileRefs[] = $file;
895 $this->missingLocalFileRefs[] = $file;
900 return CSSMin::remap( $style, $localDir, $remoteDir,
true );
909 return $context->getDirection() ===
'rtl' && !$this->noflip;
918 return $this->targets;
928 $canBeStylesOnly = !(
931 || $this->debugScripts
933 || $this->languageScripts
934 || $this->skinScripts
935 || $this->dependencies
937 || $this->skipFunction
940 return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
967 $cacheKey =
$cache->makeGlobalKey(
'LESS', $fileName, $varsHash );
968 $cachedCompile =
$cache->get( $cacheKey );
973 if ( isset( $cachedCompile[
'hash'] ) ) {
975 if ( $contentHash === $cachedCompile[
'hash'] ) {
976 $this->localFileRefs = array_merge( $this->localFileRefs, $cachedCompile[
'files'] );
977 return $cachedCompile[
'css'];
981 $compiler =
$context->getResourceLoader()->getLessCompiler(
$vars );
982 $css = $compiler->parseFile( $fileName )->getCss();
983 $files = $compiler->AllParsedFiles();
984 $this->localFileRefs = array_merge( $this->localFileRefs, $files );
1004 foreach ( $this->templates as $alias => $templatePath ) {
1006 if ( is_int( $alias ) ) {
1007 $alias = $templatePath;
1010 if ( file_exists( $localPath ) ) {
1011 $content = file_get_contents( $localPath );
1014 $msg = __METHOD__ .
": template file not found: \"$localPath\"";
1033 if ( substr_compare(
"\xef\xbb\xbf",
$input, 0, 3 ) === 0 ) {
1034 return substr(
$input, 3 );
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
$wgExtensionAssetsPath
The URL path of the extensions directory.
$wgStylePath
The URL path of the skins directory.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
static getFileContentsHash( $filePaths, $algo='md4')
Get a hash of the combined contents of one or more files, either by retrieving a previously-computed ...
Object passed around to modules which contains information about the state of a specific loader reque...
ResourceLoader module based on local JavaScript/CSS files.
array $dependencies
List of modules this module depends on.
array $skinStyles
List of paths to CSS files to include when using specific skins.
getScriptFiles(ResourceLoaderContext $context)
Get a list of file paths for all scripts in this module, in order of proper execution.
getStyleFiles(ResourceLoaderContext $context)
Get a list of file paths for all styles in this module, in order of proper inclusion.
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
readStyleFiles(array $styles, $flip, $context=null)
Gets the contents of a list of CSS files.
getStyles(ResourceLoaderContext $context)
Get all styles for a given context.
array $skinScripts
List of JavaScript files to include when using a specific skin.
getFileHashes(ResourceLoaderContext $context)
Helper method to gather file hashes for getDefinitionSummary.
string $skipFunction
File name containing the body of the skip function.
array $languageScripts
List of JavaScript files to include when using a specific language.
bool $raw
Whether mw.loader.state() call should be omitted.
readScriptFiles(array $scripts)
Gets the contents of a list of JavaScript files.
array $scripts
List of paths to JavaScript files to always include.
getSkipFunction()
Get the skip function.
getScriptURLsForDebug(ResourceLoaderContext $context)
getGroup()
Gets the name of the group this module should be loaded in.
getStyleURLsForDebug(ResourceLoaderContext $context)
bool $debugRaw
Link to raw files in debug mode.
readStyleFile( $path, $flip, $context)
Reads a style file.
array $templates
Saves a list of the templates named by the modules.
getTemplates()
Takes named templates by the module and returns an array mapping.
static tryForKey(array $list, $key, $fallback=null)
Get a list of element that match a key, optionally using a fallback key.
getFlip( $context)
Get whether CSS for this module should be flipped.
string $localBasePath
Local base path, see __construct()
getMessages()
Gets list of message keys used by this module.
string $group
Name of group to load this module in.
compileLessFile( $fileName, ResourceLoaderContext $context)
Compile a LESS file into CSS.
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
array $debugScripts
List of paths to JavaScript files to include in debug mode.
getSkinStyleFiles( $skinName)
Gets a list of file paths for all skin styles in the module used by the skin.
__construct( $options=[], $localBasePath=null, $remoteBasePath=null)
Constructs a new module from an options array.
getStyleSheetLang( $path)
Infer the stylesheet language from a stylesheet file path.
getDependencies(ResourceLoaderContext $context=null)
Gets list of names of modules this module depends on.
enableModuleContentVersion()
Disable module content versioning.
static extractBasePaths( $options=[], $localBasePath=null, $remoteBasePath=null)
Extract a pair of local and remote base paths from module definition information.
bool $hasGeneratedStyles
Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
array $missingLocalFileRefs
Place where readStyleFile() tracks file dependencies for non-existent files.
static collateFilePathListByOption(array $list, $option, $default)
Collates file paths by option (where provided).
getScript(ResourceLoaderContext $context)
Gets all scripts for a given context concatenated together.
getType()
Get the module's load type.
stripBom( $input)
Takes an input string and removes the UTF-8 BOM character if present.
getAllSkinStyleFiles()
Gets a list of file paths for all skin style files in the module, for all available skins.
getLanguageScripts( $lang)
Get the set of language scripts for the given language, possibly using a fallback language.
array $styles
List of paths to CSS files to always include.
bool $noflip
Whether CSSJanus flipping should be skipped for this module.
getAllStyleFiles()
Returns all style files and all skin style files used by this module.
array $localFileRefs
Place where readStyleFile() tracks file dependencies.
string $remoteBasePath
Remote base path, see __construct()
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path,...
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
getFileDependencies(ResourceLoaderContext $context)
Get the files this module depends on indirectly for a given skin.
validateScriptFile( $fileName, $contents)
Validate a given script file; if valid returns the original source.
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
getDeprecationInformation()
Get JS representing deprecation information for the current module if available.
saveFileDependencies(ResourceLoaderContext $context, $localFileRefs)
Set the files this module depends on indirectly for a given skin.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
the array() calling protocol came about after MediaWiki 1.4rc1.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
namespace being checked & $result
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
if(is_array($mode)) switch( $mode) $input
if(!isset( $args[0])) $lang