238 $localBasePath =
null,
239 $remoteBasePath =
null
242 $hasTemplates =
false;
245 list( $this->localBasePath, $this->remoteBasePath ) =
249 foreach (
$options as $member => $option ) {
256 $this->{$member} = (
array)$option;
259 $hasTemplates =
true;
260 $this->{$member} = (
array)$option;
263 case 'languageScripts':
267 throw new InvalidArgumentException(
268 "Invalid collated file path list error. " .
269 "'$option' given, array expected."
272 foreach ( $option as $key =>
$value ) {
274 throw new InvalidArgumentException(
275 "Invalid collated file path list key error. " .
276 "'$key' given, string expected."
298 $this->{$member} = (
string)$option;
304 $this->{$member} = (
bool)$option;
309 throw new InvalidArgumentException(
"A module may not set both 'scripts' and 'packageFiles'" );
311 if ( $hasTemplates ) {
312 $this->dependencies[] =
'mediawiki.template';
314 foreach ( $this->templates as $alias => $templatePath ) {
318 $suffix = explode(
'.', $alias );
319 $suffix = end( $suffix );
320 $compilerModule =
'mediawiki.template.' . $suffix;
321 if ( $suffix !==
'html' && !
in_array( $compilerModule, $this->dependencies ) ) {
341 $localBasePath =
null,
342 $remoteBasePath =
null
385 if ( $this->packageFiles !==
null ) {
387 if ( $deprecationScript ) {
389 $mainFile[
'content'] = $deprecationScript . $mainFile[
'content'];
405 $urls[] = OutputPage::transformResourcePath(
419 return $this->debugRaw && !$this->packageFiles;
445 if ( $this->hasGeneratedStyles ) {
448 return parent::getStyleURLsForDebug(
$context );
455 foreach ( $list as $file ) {
489 return $this->dependencies;
498 if ( !$this->skipFunction ) {
502 $localPath = $this->
getLocalPath( $this->skipFunction );
504 throw new MWException( __METHOD__ .
": skip function file not found: \"$localPath\"" );
540 $styles = self::collateFilePathListByOption( $this->styles,
'media',
'all' );
541 foreach (
$styles as $styleFiles ) {
545 $skinFiles = self::collateFilePathListByOption(
546 self::tryForKey( $this->skinStyles,
$context->getSkin(),
'default' ),
550 foreach ( $skinFiles as $styleFiles ) {
558 return $fileInfo[
'filePath'] ??
null;
568 $context->getDebug() ? $this->debugScripts : [],
570 self::tryForKey( $this->skinScripts,
$context->getSkin(),
'default' )
572 if ( $this->skipFunction ) {
573 $files[] = $this->skipFunction;
575 $files =
array_map( [ $this,
'getLocalPath' ], $files );
586 return array_map( [ __CLASS__,
'safeFileHash' ], $files );
596 $summary = parent::getDefinitionSummary(
$context );
631 $summary[] = [
'lessVars' => $lessVars ];
643 return $path->getLocalPath();
646 return "{$this->localBasePath}/$path";
655 return $path->getRemotePath();
658 return "{$this->remoteBasePath}/$path";
669 return preg_match(
'/\.less$/i', $path ) ?
'less' :
'css';
698 if ( !
isset( $collatedFiles[$default] ) ) {
699 $collatedFiles[$default] = [];
701 $collatedFiles[$default][] =
$value;
705 if ( !
isset( $collatedFiles[$optionValue] ) ) {
745 self::tryForKey( $this->skinScripts,
$context->getSkin(),
'default' )
748 $files =
array_merge( $files, $this->debugScripts );
766 $fallbacks = Language::getFallbacksFor(
$lang );
767 foreach ( $fallbacks as
$lang ) {
788 self::collateFilePathListByOption( $this->styles,
'media',
'all' ),
789 self::collateFilePathListByOption(
790 self::tryForKey( $this->skinStyles,
$context->getSkin(),
'default' ),
805 return self::collateFilePathListByOption(
806 self::tryForKey( $this->skinStyles, $skinName ),
820 $internalSkinNames =
array_keys( Skin::getSkinNames() );
821 $internalSkinNames[] =
'default';
823 foreach ( $internalSkinNames as $internalSkinName ) {
840 self::collateFilePathListByOption( $this->styles,
'media',
'all' ),
846 foreach ( $collatedStyleFiles as $media => $styleFiles ) {
847 foreach ( $styleFiles as $styleFile ) {
863 if ( empty( $scripts ) ) {
867 foreach (
array_unique( $scripts, SORT_REGULAR ) as $fileName ) {
870 throw new MWException( __METHOD__ .
": script file not found: \"$localPath\"" );
893 foreach ( $styles as $media => $files ) {
896 foreach ( $uniqueFiles as $file ) {
899 $styles[
$media] = implode(
"\n", $styleFiles );
920 $msg = __METHOD__ .
": style file not found: \"$localPath\"";
927 $this->hasGeneratedStyles =
true;
933 $style = CSSJanus::transform( $style,
true,
false );
935 $localDir =
dirname( $localPath );
936 $remoteDir =
dirname( $remotePath );
938 $localFileRefs = CSSMin::getLocalFileReferences( $style, $localDir );
941 $this->localFileRefs[] =
$file;
943 $this->missingLocalFileRefs[] =
$file;
948 return CSSMin::remap( $style, $localDir, $remoteDir,
true );
957 return $context->getDirection() ===
'rtl' && !$this->noflip;
966 return $this->targets;
976 $canBeStylesOnly = !(
979 || $this->debugScripts
981 || $this->languageScripts
982 || $this->skinScripts
983 || $this->dependencies
985 || $this->skipFunction
988 return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
1015 $cacheKey =
$cache->makeGlobalKey(
'LESS', $fileName, $varsHash );
1016 $cachedCompile =
$cache->get( $cacheKey );
1021 if (
isset( $cachedCompile[
'hash'] ) ) {
1023 if ( $contentHash === $cachedCompile[
'hash'] ) {
1024 $this->localFileRefs =
array_merge( $this->localFileRefs, $cachedCompile[
'files'] );
1025 return $cachedCompile[
'css'];
1029 $compiler =
$context->getResourceLoader()->getLessCompiler(
$vars );
1030 $css = $compiler->parseFile( $fileName )->getCss();
1031 $files = $compiler->AllParsedFiles();
1032 $this->localFileRefs =
array_merge( $this->localFileRefs, $files );
1035 $cache->set( $cacheKey, [
1052 foreach ( $this->templates as $alias => $templatePath ) {
1054 if (
is_int( $alias ) ) {
1062 $msg = __METHOD__ .
": template file not found: \"$localPath\"";
1084 if (
isset( $this->expandedPackageFiles[$hash] ) ) {
1085 return $this->expandedPackageFiles[$hash];
1087 if ( $this->packageFiles ===
null ) {
1090 $expandedFiles = [];
1093 foreach ( $this->packageFiles as $alias => $fileInfo ) {
1095 $fileInfo = [
'name' => $fileInfo,
'file' => $fileInfo ];
1097 $msg = __METHOD__ .
": invalid package file definition for module " .
1098 "\"{$this->getName()}\": 'name' key is required when value is not a string";
1104 $type = $fileInfo[
'type'] ?? self::getPackageFileType( $fileInfo[
'name'] );
1105 $expanded = [
'type' =>
$type ];
1106 if ( !empty( $fileInfo[
'main'] ) ) {
1107 $mainFile = $fileInfo[
'name'];
1108 if (
$type !==
'script' ) {
1109 $msg = __METHOD__ .
": invalid package file definition for module " .
1110 "\"{$this->getName()}\": main file \"$mainFile\" must be of type \"script\", not \"$type\"";
1116 if (
isset( $fileInfo[
'content'] ) ) {
1117 $expanded[
'content'] = $fileInfo[
'content'];
1119 $expanded[
'filePath'] = $fileInfo[
'file'];
1122 $expanded[
'content'] = $fileInfo[
'callback'](
$context );
1124 $msg = __METHOD__ .
": invalid callback for package file \"{$fileInfo['name']}\"" .
1125 " in module \"{$this->getName()}\"";
1130 if (
$type !==
'data' ) {
1131 $msg = __METHOD__ .
": invalid use of \"config\" for package file \"{$fileInfo['name']}\" " .
1132 "in module \"{$this->getName()}\": type must be \"data\" but is \"$type\"";
1136 $expandedConfig = [];
1137 foreach ( $fileInfo[
'config'] as $key => $var ) {
1141 }
elseif ( !empty( $fileInfo[
'main'] ) ) {
1143 $expanded[
'filePath'] = $fileInfo[
'name'];
1145 $msg = __METHOD__ .
": invalid package file definition for \"{$fileInfo['name']}\" " .
1146 "in module \"{$this->getName()}\": one of \"file\", \"content\", \"callback\" or \"config\" " .
1152 $expandedFiles[$fileInfo[
'name']] =
$expanded;
1155 if ( $expandedFiles && $mainFile ===
null ) {
1157 foreach ( $expandedFiles as $path => &$file ) {
1158 if ( $file[
'type'] ===
'script' ) {
1170 $this->expandedPackageFiles[$hash] =
$result;
1180 if ( $this->packageFiles ===
null ) {
1187 if (
isset( $fileInfo[
'filePath'] ) ) {
1188 $localPath = $this->
getLocalPath( $fileInfo[
'filePath'] );
1190 $msg = __METHOD__ .
": package file not found: \"$localPath\"" .
1191 " in module \"{$this->getName()}\"";
1196 if ( $fileInfo[
'type'] ===
'data' ) {
1200 unset( $fileInfo[
'filePath'] );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$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.
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 script file paths for 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'].
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 for getDefinitionSummary.
string $skipFunction
File name containing the body of the skip function.
static getPackageFileType( $path)
Infer the file type from a package file path.
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)
Get 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.
array $packageFiles
List of packaged files to make available through require()
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.
expandPackageFiles(ResourceLoaderContext $context)
Expand the packageFiles definition into something that's (almost) the right format for getPackageFile...
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
array $expandedPackageFiles
Expanded versions of $packageFiles, lazy-computed by expandPackageFiles(); keyed by context hash.
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.
getPackageFiles(ResourceLoaderContext $context)
Resolves the package files defintion and generates the content of each package file.
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()
readStyleFiles(array $styles, $flip, $context)
Get the contents of a list of CSS files.
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.
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
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
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error messages
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(is_array($mode)) switch( $mode) $input
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
if(!isset( $args[0])) $lang