Go to the documentation of this file.
81 if ( self::$instance ===
null ) {
82 self::$instance =
new self();
95 if ( $mtime ===
false ) {
96 if ( file_exists(
$path ) ) {
97 $mtime = filemtime(
$path );
99 throw new Exception(
"$path does not exist!" );
102 $err = error_get_last();
103 throw new Exception(
"Couldn't stat $path: {$err['message']}" );
106 $this->queued[
$path] = $mtime;
115 if ( !$this->queued ) {
119 if ( $this->finished ) {
121 "The following paths tried to load late: "
122 . implode(
', ', array_keys( $this->queued ) )
135 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
142 md5( json_encode( $this->queued + $versions ) )
144 $data =
$cache->get( $key );
152 $data[
'globals'][
'wgAutoloadClasses'] += $data[
'autoload'];
153 unset( $data[
'autoload'] );
156 $cache->set( $key, $data, 60 * 60 * 24 );
186 $this->finished =
true;
198 $autoloadClasses = [];
199 $autoloaderPaths = [];
202 $extDependencies = [];
206 $json = file_get_contents(
$path );
207 if ( $json ===
false ) {
208 throw new Exception(
"Unable to read $path, does it exist?" );
210 $info = json_decode( $json,
true );
211 if ( !is_array( $info ) ) {
212 throw new Exception(
"$path is not a valid JSON file." );
215 if ( !isset( $info[
'manifest_version'] ) ) {
217 "{$info['name']}'s extension.json or skin.json does not have manifest_version",
222 $info[
'manifest_version'] = 1;
224 $version = $info[
'manifest_version'];
225 if ( $version < self::OLDEST_MANIFEST_VERSION || $version > self::MANIFEST_VERSION ) {
226 $incompatible[] =
"$path: unsupported manifest_version: {$version}";
231 $GLOBALS[
'wgAutoloadClasses'] += $autoload;
232 $autoloadClasses += $autoload;
235 $requires = $processor->getRequirements( $info );
238 if ( is_array( $requires ) && $requires && isset( $info[
'name'] ) ) {
239 $extDependencies[$info[
'name']] = $requires;
243 $autoloaderPaths = array_merge( $autoloaderPaths,
244 $processor->getExtraAutoloaderPaths( dirname(
$path ), $info ) );
246 $processor->extractInfo(
$path, $info, $version );
248 $data = $processor->getExtractedInfo();
249 $data[
'warnings'] = $warnings;
252 $incompatible = array_merge(
255 ->setLoadedExtensionsAndSkins( $data[
'credits'] )
256 ->checkArray( $extDependencies )
259 if ( $incompatible ) {
260 if (
count( $incompatible ) === 1 ) {
261 throw new Exception( $incompatible[0] );
263 throw new Exception( implode(
"\n", $incompatible ) );
268 $data[
'globals'][
'wgAutoloadClasses'] = [];
269 $data[
'autoload'] = $autoloadClasses;
270 $data[
'autoloaderPaths'] = $autoloaderPaths;
275 foreach ( $info[
'globals']
as $key => $val ) {
278 if ( is_array( $val ) && isset( $val[self::MERGE_STRATEGY] ) ) {
280 unset( $val[self::MERGE_STRATEGY] );
282 $mergeStrategy =
'array_merge';
292 if ( !is_array(
$GLOBALS[$key] ) || !is_array( $val ) ) {
297 switch ( $mergeStrategy ) {
298 case 'array_merge_recursive':
301 case 'array_replace_recursive':
304 case 'array_plus_2d':
314 throw new UnexpectedValueException(
"Unknown merge strategy '$mergeStrategy'" );
318 foreach ( $info[
'defines']
as $name => $val ) {
319 define(
$name, $val );
321 foreach ( $info[
'autoloaderPaths']
as $path ) {
325 $this->loaded += $info[
'credits'];
326 if ( $info[
'attributes'] ) {
327 if ( !$this->attributes ) {
328 $this->attributes = $info[
'attributes'];
330 $this->attributes = array_merge_recursive( $this->attributes, $info[
'attributes'] );
334 foreach ( $info[
'callbacks']
as $name => $cb ) {
335 if ( !is_callable( $cb ) ) {
336 if ( is_array( $cb ) ) {
337 $cb =
'[ ' . implode(
', ', $cb ) .
' ]';
339 throw new UnexpectedValueException(
"callback '$cb' is not callable" );
341 call_user_func( $cb, $info[
'credits'][
$name] );
365 return isset( $this->loaded[
$name] );
373 if ( isset( $this->attributes[
$name] ) ) {
374 return $this->attributes[
$name];
396 $this->loaded[
$name] = $credits;
407 if ( isset( $info[
'AutoloadClasses'] ) ) {
409 return array_map(
function ( $file )
use (
$dir ) {
411 }, $info[
'AutoloadClasses'] );
getQueue()
Get the current load queue.
bool $finished
Whether we are done loading things.
const MANIFEST_VERSION
Version of the highest supported manifest version.
A BagOStuff object with no objects in it.
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
exportExtractedData(array $info)
processAutoLoader( $dir, array $info)
Register classes with the autoloader.
$wgVersion
MediaWiki version number.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
getAllThings()
Get information about all things.
array $loaded
Array of loaded things, keyed by name, values are credits information.
Allows to change the fields on the form that will be generated $name
clearQueue()
Clear the current load queue.
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
const MERGE_STRATEGY
Special key that defines the merge strategy.
isLoaded( $name)
Whether a thing has been loaded.
const CACHE_VERSION
Bump whenever the registration cache needs resetting.
array $attributes
Items in the JSON file that aren't being set as globals.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
load( $path)
Loads and processes the given JSON file without delay.
finish()
After this is called, no more extensions can be loaded.
when a variable name is used in a it is silently declared as a new masking the global
$GLOBALS['wgAutoloadClasses']['LocalisationUpdate']
const OLDEST_MANIFEST_VERSION
Version of the oldest supported manifest version.
const MEDIAWIKI_CORE
"requires" key that applies to MediaWiki core/$wgVersion
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
readFromQueue(array $queue)
Process a queue of extensions and return their extracted data.
array $queued
List of paths that should be loaded.
$wgDevelopmentWarnings
If set to true MediaWiki will throw notices for some possible error conditions and for deprecated fun...
Provides functions to check a set of extensions with dependencies against a set of loaded extensions ...
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
int bool $wgExtensionInfoMTime
When loading extensions through the extension registration system, this can be used to invalidate the...
markLoaded( $name, array $credits)
Mark a thing as loaded.
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 MediaWikiServices
static ExtensionRegistry $instance
the array() calling protocol came about after MediaWiki 1.4rc1.