81 if ( self::$instance ===
null ) {
82 self::$instance =
new self();
91 public function queue( $path ) {
95 if ( $mtime ===
false ) {
96 if ( file_exists( $path ) ) {
97 $mtime = filemtime( $path );
99 throw new Exception(
"$path does not exist!" );
102 if ( $mtime ===
false ) {
103 $err = error_get_last();
104 throw new Exception(
"Couldn't stat $path: {$err['message']}" );
107 $this->queued[
$path] = $mtime;
116 if ( !$this->queued ) {
120 if ( $this->finished ) {
122 "The following paths tried to load late: "
123 . implode(
', ', array_keys( $this->queued ) )
136 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
143 md5( json_encode( $this->queued + $versions ) )
145 $data =
$cache->get( $key );
153 $data[
'globals'][
'wgAutoloadClasses'] += $data[
'autoload'];
154 unset( $data[
'autoload'] );
157 $cache->set( $key, $data, 60 * 60 * 24 );
187 $this->finished =
true;
199 $autoloadClasses = [];
200 $autoloaderPaths = [];
203 $extDependencies = [];
206 foreach (
$queue as $path => $mtime ) {
207 $json = file_get_contents( $path );
208 if ( $json ===
false ) {
209 throw new Exception(
"Unable to read $path, does it exist?" );
211 $info = json_decode( $json,
true );
212 if ( !is_array( $info ) ) {
213 throw new Exception(
"$path is not a valid JSON file." );
216 if ( !isset( $info[
'manifest_version'] ) ) {
218 "{$info['name']}'s extension.json or skin.json does not have manifest_version",
223 $info[
'manifest_version'] = 1;
225 $version = $info[
'manifest_version'];
226 if ( $version < self::OLDEST_MANIFEST_VERSION || $version > self::MANIFEST_VERSION ) {
227 $incompatible[] =
"$path: unsupported manifest_version: {$version}";
232 $GLOBALS[
'wgAutoloadClasses'] += $autoload;
233 $autoloadClasses += $autoload;
236 $requires = $processor->getRequirements( $info );
239 if ( is_array( $requires ) && $requires && isset( $info[
'name'] ) ) {
240 $extDependencies[$info[
'name']] = $requires;
244 $autoloaderPaths = array_merge( $autoloaderPaths,
245 $processor->getExtraAutoloaderPaths( dirname( $path ), $info ) );
247 $processor->extractInfo( $path, $info, $version );
249 $data = $processor->getExtractedInfo();
250 $data[
'warnings'] = $warnings;
253 $incompatible = array_merge(
256 ->setLoadedExtensionsAndSkins( $data[
'credits'] )
257 ->checkArray( $extDependencies )
260 if ( $incompatible ) {
261 if ( count( $incompatible ) === 1 ) {
262 throw new Exception( $incompatible[0] );
264 throw new Exception( implode(
"\n", $incompatible ) );
269 $data[
'globals'][
'wgAutoloadClasses'] = [];
270 $data[
'autoload'] = $autoloadClasses;
271 $data[
'autoloaderPaths'] = $autoloaderPaths;
276 foreach ( $info[
'globals'] as $key => $val ) {
279 if ( is_array( $val ) && isset( $val[self::MERGE_STRATEGY] ) ) {
281 unset( $val[self::MERGE_STRATEGY] );
283 $mergeStrategy =
'array_merge';
293 if ( !is_array(
$GLOBALS[$key] ) || !is_array( $val ) ) {
298 switch ( $mergeStrategy ) {
299 case 'array_merge_recursive':
302 case 'array_replace_recursive':
305 case 'array_plus_2d':
315 throw new UnexpectedValueException(
"Unknown merge strategy '$mergeStrategy'" );
319 foreach ( $info[
'defines'] as $name => $val ) {
320 define( $name, $val );
322 foreach ( $info[
'autoloaderPaths'] as $path ) {
326 $this->loaded += $info[
'credits'];
327 if ( $info[
'attributes'] ) {
328 if ( !$this->attributes ) {
329 $this->attributes = $info[
'attributes'];
331 $this->attributes = array_merge_recursive( $this->attributes, $info[
'attributes'] );
335 foreach ( $info[
'callbacks'] as $name => $cb ) {
336 if ( !is_callable( $cb ) ) {
337 if ( is_array( $cb ) ) {
338 $cb =
'[ ' . implode(
', ', $cb ) .
' ]';
340 throw new UnexpectedValueException(
"callback '$cb' is not callable" );
342 call_user_func( $cb, $info[
'credits'][$name] );
354 public function load( $path ) {
356 $this->
queue( $path );
366 return isset( $this->loaded[$name] );
374 if ( isset( $this->attributes[$name] ) ) {
375 return $this->attributes[
$name];
397 $this->loaded[
$name] = $credits;
408 if ( isset( $info[
'AutoloadClasses'] ) ) {
410 return array_map(
function ( $file ) use (
$dir ) {
412 }, $info[
'AutoloadClasses'] );
$GLOBALS['wgAutoloadClasses']['LocalisationUpdate']
int bool $wgExtensionInfoMTime
When loading extensions through the extension registration system, this can be used to invalidate the...
$wgVersion
MediaWiki version number.
$wgDevelopmentWarnings
If set to true MediaWiki will throw notices for some possible error conditions and for deprecated fun...
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
A BagOStuff object with no objects in it.
isLoaded( $name)
Whether a thing has been loaded.
array $queued
List of paths that should be loaded.
const MERGE_STRATEGY
Special key that defines the merge strategy.
getQueue()
Get the current load queue.
const MANIFEST_VERSION
Version of the highest supported manifest version.
processAutoLoader( $dir, array $info)
Register classes with the autoloader.
const OLDEST_MANIFEST_VERSION
Version of the oldest supported manifest version.
array $loaded
Array of loaded things, keyed by name, values are credits information.
const CACHE_VERSION
Bump whenever the registration cache needs resetting.
clearQueue()
Clear the current load queue.
static ExtensionRegistry $instance
load( $path)
Loads and processes the given JSON file without delay.
const MEDIAWIKI_CORE
"requires" key that applies to MediaWiki core/$wgVersion
readFromQueue(array $queue)
Process a queue of extensions and return their extracted data.
exportExtractedData(array $info)
bool $finished
Whether we are done loading things.
getAllThings()
Get information about all things.
finish()
After this is called, no more extensions can be loaded.
array $attributes
Items in the JSON file that aren't being set as globals.
markLoaded( $name, array $credits)
Mark a thing as loaded.
Provides functions to check a set of extensions with dependencies against a set of loaded extensions ...
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e