222 $hasTemplates =
false;
225 list( $this->localBasePath, $this->remoteBasePath ) =
235 $this->{$member} = (
array)$option;
238 $hasTemplates =
true;
239 $this->{$member} = (
array)$option;
242 case 'languageScripts':
245 if ( !is_array( $option ) ) {
247 "Invalid collated file path list error. " .
248 "'$option' given, array expected."
251 foreach ( $option
as $key =>
$value ) {
252 if ( !is_string( $key ) ) {
254 "Invalid collated file path list key error. " .
255 "'$key' given, string expected."
262 $this->deprecated = $option;
269 $option = array_values( array_unique( (
array)$option ) );
272 $this->{$member} = $option;
278 $this->{$member} = (
string)$option;
284 $this->{$member} = (bool)$option;
288 if ( $hasTemplates ) {
289 $this->dependencies[] =
'mediawiki.template';
291 foreach ( $this->templates
as $alias => $templatePath ) {
292 if ( is_int( $alias ) ) {
293 $alias = $templatePath;
295 $suffix = explode(
'.', $alias );
296 $suffix = end( $suffix );
297 $compilerModule =
'mediawiki.template.' . $suffix;
298 if ( $suffix !==
'html' && !in_array( $compilerModule, $this->dependencies ) ) {
299 $this->dependencies[] = $compilerModule;
333 if ( isset(
$options[
'remoteExtPath'] ) ) {
338 if ( isset(
$options[
'remoteSkinPath'] ) ) {
343 if ( array_key_exists(
'localBasePath',
$options ) ) {
347 if ( array_key_exists(
'remoteBasePath',
$options ) ) {
410 if ( $this->hasGeneratedStyles ) {
413 return parent::getStyleURLsForDebug( $context );
419 $urls[$mediaType] = [];
420 foreach ( $list
as $file ) {
470 if ( !$this->skipFunction ) {
474 $localPath = $this->
getLocalPath( $this->skipFunction );
475 if ( !file_exists( $localPath ) ) {
476 throw new MWException( __METHOD__ .
": skip function file not found: \"$localPath\"" );
479 if ( $this->
getConfig()->
get(
'ResourceLoaderValidateStaticJS' ) ) {
518 $styles = self::collateFilePathListByOption( $this->styles,
'media',
'all' );
523 $skinFiles = self::collateFilePathListByOption(
524 self::tryForKey( $this->skinStyles, $context->
getSkin(),
'default' ),
528 foreach ( $skinFiles
as $styleFiles ) {
537 $context->
getDebug() ? $this->debugScripts : [],
539 self::tryForKey( $this->skinScripts, $context->
getSkin(),
'default' )
541 if ( $this->skipFunction ) {
544 $files = array_map( [ $this,
'getLocalPath' ],
$files );
555 return array_map( [ __CLASS__,
'safeFileHash' ],
$files );
565 $summary = parent::getDefinitionSummary( $context );
589 $options[$member] = $this->{$member};
606 return $path->getLocalPath();
609 return "{$this->localBasePath}/$path";
618 return $path->getRemotePath();
621 return "{$this->remoteBasePath}/$path";
632 return preg_match(
'/\.less$/i',
$path ) ?
'less' :
'css';
647 if ( is_int( $key ) ) {
649 if ( !isset( $collatedFiles[$default] ) ) {
650 $collatedFiles[$default] = [];
652 $collatedFiles[$default][] =
$value;
653 } elseif ( is_array(
$value ) ) {
655 $optionValue = isset(
$value[$option] ) ?
$value[$option] : $default;
656 if ( !isset( $collatedFiles[$optionValue] ) ) {
657 $collatedFiles[$optionValue] = [];
659 $collatedFiles[$optionValue][] = $key;
662 return $collatedFiles;
675 if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
679 && is_array( $list[$fallback] )
696 self::tryForKey( $this->skinScripts, $context->
getSkin(),
'default' )
702 return array_unique(
$files, SORT_REGULAR );
718 foreach ( $fallbacks
as $lang ) {
719 $scripts = self::tryForKey( $this->languageScripts, $lang );
735 return array_merge_recursive(
736 self::collateFilePathListByOption( $this->styles,
'media',
'all' ),
737 self::collateFilePathListByOption(
738 self::tryForKey( $this->skinStyles, $context->
getSkin(),
'default' ),
753 return self::collateFilePathListByOption(
754 self::tryForKey( $this->skinStyles, $skinName ),
769 $internalSkinNames[] =
'default';
771 foreach ( $internalSkinNames
as $internalSkinName ) {
772 $styleFiles = array_merge_recursive(
787 $collatedStyleFiles = array_merge_recursive(
788 self::collateFilePathListByOption( $this->styles,
'media',
'all' ),
794 foreach ( $collatedStyleFiles
as $media => $styleFiles ) {
795 foreach ( $styleFiles
as $styleFile ) {
811 if ( empty( $scripts ) ) {
815 foreach ( array_unique( $scripts, SORT_REGULAR )
as $fileName ) {
817 if ( !file_exists( $localPath ) ) {
818 throw new MWException( __METHOD__ .
": script file not found: \"$localPath\"" );
821 if ( $this->
getConfig()->
get(
'ResourceLoaderValidateStaticJS' ) ) {
849 wfDeprecated( __METHOD__ .
' without a ResourceLoader context',
'1.27' );
853 if ( empty( $styles ) ) {
856 foreach ( $styles
as $media =>
$files ) {
857 $uniqueFiles = array_unique(
$files, SORT_REGULAR );
859 foreach ( $uniqueFiles
as $file ) {
862 $styles[$media] = implode(
"\n", $styleFiles );
882 if ( !file_exists( $localPath ) ) {
883 $msg = __METHOD__ .
": style file not found: \"$localPath\"";
890 $this->hasGeneratedStyles =
true;
892 $style = $this->
stripBom( file_get_contents( $localPath ) );
896 $style = CSSJanus::transform( $style,
true,
false );
898 $localDir = dirname( $localPath );
899 $remoteDir = dirname( $remotePath );
903 if ( file_exists( $file ) ) {
904 $this->localFileRefs[] = $file;
906 $this->missingLocalFileRefs[] = $file;
939 $canBeStylesOnly = !(
942 || $this->debugScripts
944 || $this->languageScripts
945 || $this->skinScripts
946 || $this->dependencies
948 || $this->skipFunction
951 return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
978 $cacheKey =
$cache->makeGlobalKey(
'LESS', $fileName, $varsHash );
979 $cachedCompile =
$cache->get( $cacheKey );
984 if ( isset( $cachedCompile[
'hash'] ) ) {
986 if ( $contentHash === $cachedCompile[
'hash'] ) {
987 $this->localFileRefs = array_merge( $this->localFileRefs, $cachedCompile[
'files'] );
988 return $cachedCompile[
'css'];
993 $css = $compiler->parseFile( $fileName )->getCss();
994 $files = $compiler->AllParsedFiles();
995 $this->localFileRefs = array_merge( $this->localFileRefs,
$files );
1014 foreach ( $this->templates
as $alias => $templatePath ) {
1016 if ( is_int( $alias ) ) {
1017 $alias = $templatePath;
1020 if ( file_exists( $localPath ) ) {
1021 $content = file_get_contents( $localPath );
1024 $msg = __METHOD__ .
": template file not found: \"$localPath\"";
1042 if ( substr_compare(
"\xef\xbb\xbf", $input, 0, 3 ) === 0 ) {
1043 return substr( $input, 3 );
getScriptURLsForDebug(ResourceLoaderContext $context)
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.
string $position
Position on the page to load this module at.
getDeprecationInformation()
Get JS representing deprecation information for the current module if available.
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
array $dependencies
List of modules this module depends on.
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
array $skinStyles
List of paths to CSS files to include when using specific skins.
getSkinStyleFiles($skinName)
Gets a list of file paths for all skin styles in the module used by the skin.
getStyleFiles(ResourceLoaderContext $context)
Get a list of file paths for all styles in this module, in order of proper inclusion.
if(!isset($args[0])) $lang
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
readStyleFile($path, $flip, $context)
Reads a style file.
static getSkinNames()
Fetch the set of available skins.
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
getAllStyleFiles()
Returns all style files and all skin style files used by this module.
getSkipFunction()
Get the skip function.
compileLessFile($fileName, ResourceLoaderContext $context)
Compile a LESS file into CSS.
when a variable name is used in a it is silently declared as a new local masking the global
array $debugScripts
List of paths to JavaScript files to include in debug mode.
static getFallbacksFor($code)
Get the ordered list of fallback languages.
getStyles(ResourceLoaderContext $context)
Get all styles for a given context.
getFlip($context)
Get whether CSS for this module should be flipped.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
array $templates
Saves a list of the templates named by the modules.
passed in as a query string parameter to the various URLs constructed here(i.e.$prevlink) $ldel you ll need to handle error messages
static getFileContentsHash($filePaths, $algo= 'md4')
Get a hash of the combined contents of one or more files, either by retrieving a previously-computed ...
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
bool $raw
Whether mw.loader.state() call should be omitted.
stripBom($input)
Takes an input string and removes the UTF-8 BOM character if present.
getFileHashes(ResourceLoaderContext $context)
Helper method to gather file hashes for getDefinitionSummary.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
bool $debugRaw
Link to raw files in debug mode.
static array static getLocalFileReferences($source, $path)
Get a list of local files referenced in a stylesheet (includes non-existent files).
$wgStylePath
The URL path of the skins directory.
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.
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. ...
string $skipFunction
File name containing the body of the skip function.
bool $hasGeneratedStyles
Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
static transformResourcePath(Config $config, $path)
Transform path to web-accessible static resource.
getDependencies(ResourceLoaderContext $context=null)
Gets list of names of modules this module depends on.
ResourceLoader module based on local JavaScript/CSS files.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
readScriptFiles(array $scripts)
Gets the contents of a list of JavaScript files.
string $group
Name of group to load this module in.
readStyleFiles(array $styles, $flip, $context=null)
Gets the contents of a list of CSS files.
array $localFileRefs
Place where readStyleFile() tracks file dependencies.
string $localBasePath
Local base path, see __construct()
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getTemplates()
Takes named templates by the module and returns an array mapping.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getGroup()
Gets the name of the group this module should be loaded in.
static remap($source, $local, $remote, $embedData=true)
Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an ...
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path...
getMessages()
Gets list of message keys used by this module.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getStyleURLsForDebug(ResourceLoaderContext $context)
string $remoteBasePath
Remote base path, see __construct()
array $messages
List of message keys used by this module.
getAllSkinStyleFiles()
Gets a list of file paths for all skin style files in the module, for all available skins...
array $scripts
List of paths to JavaScript files to always include.
static getLocalServerInstance($fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
$wgExtensionAssetsPath
The URL path of the extensions directory.
array $languageScripts
List of JavaScript files to include when using a specific language.
getStyleSheetLang($path)
Infer the stylesheet language from a stylesheet file path.
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
getType()
Get the module's load type.
getScript(ResourceLoaderContext $context)
Gets all scripts for a given context concatenated together.
__construct($options=[], $localBasePath=null, $remoteBasePath=null)
Constructs a new module from an options array.
array $missingLocalFileRefs
Place where readStyleFile() tracks file dependencies for non-existent files.
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.
static collateFilePathListByOption(array $list, $option, $default)
Collates file paths by option (where provided).
array $skinScripts
List of JavaScript files to include when using a specific skin.
getScriptFiles(ResourceLoaderContext $context)
Get a list of file paths for all scripts in this module, in order of proper execution.
saveFileDependencies(ResourceLoaderContext $context, $localFileRefs)
Set the files this module depends on indirectly for a given skin.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
bool $noflip
Whether CSSJanus flipping should be skipped for this module.
Object passed around to modules which contains information about the state of a specific loader reque...
static tryForKey(array $list, $key, $fallback=null)
Get a list of element that match a key, optionally using a fallback key.