79 if ( self::$instance === null ) {
80 self::$instance =
new self();
83 return self::$instance;
90 $this->
cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
103 if ( $mtime ===
false ) {
104 if ( file_exists(
$path ) ) {
105 $mtime = filemtime(
$path );
107 throw new Exception(
"$path does not exist!" );
110 $err = error_get_last();
111 throw new Exception(
"Couldn't stat $path: {$err['message']}" );
114 $this->queued[
$path] = $mtime;
119 if ( !$this->queued ) {
125 'registration' => self::CACHE_VERSION,
132 md5( json_encode( $this->queued + $versions ) )
134 $data = $this->
cache->get( $key );
142 $data[
'globals'][
'wgAutoloadClasses'] += $data[
'autoload'];
143 unset( $data[
'autoload'] );
144 $this->
cache->set( $key, $data, 60 * 60 * 24 );
176 $autoloadClasses = [];
177 $autoloaderPaths = [];
181 foreach ( $queue
as $path => $mtime ) {
182 $json = file_get_contents(
$path );
183 if ( $json ===
false ) {
184 throw new Exception(
"Unable to read $path, does it exist?" );
186 $info = json_decode( $json,
true );
187 if ( !is_array( $info ) ) {
188 throw new Exception(
"$path is not a valid JSON file." );
190 if ( !isset( $info[
'manifest_version'] ) ) {
192 $info[
'manifest_version'] = 1;
194 $version = $info[
'manifest_version'];
195 if ( $version < self::OLDEST_MANIFEST_VERSION || $version > self::MANIFEST_VERSION ) {
196 throw new Exception(
"$path: unsupported manifest_version: {$version}" );
200 $GLOBALS[
'wgAutoloadClasses'] += $autoload;
201 $autoloadClasses += $autoload;
203 $requires = $processor->getRequirements( $info );
204 if ( isset( $requires[self::MEDIAWIKI_CORE] )
205 && !$coreVersionParser->check( $requires[self::MEDIAWIKI_CORE] )
208 $incompatible[] =
"{$info['name']} is not compatible with the current "
209 .
"MediaWiki core (version {$wgVersion}), it requires: " . $requires[self::MEDIAWIKI_CORE]
214 $autoloaderPaths = array_merge( $autoloaderPaths,
215 $processor->getExtraAutoloaderPaths( dirname(
$path ), $info ) );
217 $processor->extractInfo(
$path, $info, $version );
219 if ( $incompatible ) {
220 if ( count( $incompatible ) === 1 ) {
223 throw new Exception( implode(
"\n", $incompatible ) );
226 $data = $processor->getExtractedInfo();
228 $data[
'globals'][
'wgAutoloadClasses'] = [];
229 $data[
'autoload'] = $autoloadClasses;
230 $data[
'autoloaderPaths'] = $autoloaderPaths;
235 foreach ( $info[
'globals']
as $key => $val ) {
238 if ( is_array( $val ) && isset( $val[self::MERGE_STRATEGY] ) ) {
239 $mergeStrategy = $val[self::MERGE_STRATEGY];
240 unset( $val[self::MERGE_STRATEGY] );
242 $mergeStrategy =
'array_merge';
252 if ( !is_array(
$GLOBALS[$key] ) || !is_array( $val ) ) {
257 switch ( $mergeStrategy ) {
258 case 'array_merge_recursive':
261 case 'array_replace_recursive':
264 case 'array_plus_2d':
278 foreach ( $info[
'defines']
as $name => $val ) {
279 define(
$name, $val );
281 foreach ( $info[
'autoloaderPaths']
as $path ) {
284 foreach ( $info[
'callbacks']
as $cb ) {
285 call_user_func( $cb );
288 $this->loaded += $info[
'credits'];
289 if ( $info[
'attributes'] ) {
290 if ( !$this->attributes ) {
291 $this->attributes = $info[
'attributes'];
293 $this->attributes = array_merge_recursive( $this->attributes, $info[
'attributes'] );
318 return isset( $this->loaded[
$name] );
326 if ( isset( $this->attributes[
$name] ) ) {
327 return $this->attributes[
$name];
349 $this->loaded[
$name] = $credits;
360 if ( isset( $info[
'AutoloadClasses'] ) ) {
362 return array_map(
function( $file )
use (
$dir ) {
364 }, $info[
'AutoloadClasses'] );
static ExtensionRegistry $instance
const MANIFEST_VERSION
Version of the highest supported manifest version.
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgVersion
MediaWiki version number.
processAutoLoader($dir, array $info)
Register classes with the autoloader.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
exportExtractedData(array $info)
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
when a variable name is used in a it is silently declared as a new local masking the global
getAllThings()
Get information about all things.
array $loaded
Array of loaded things, keyed by name, values are credits information.
const MERGE_STRATEGY
Special key that defines the merge strategy.
isLoaded($name)
Whether a thing has been loaded.
you have access to all of the normal MediaWiki so you can get a DB use the cache
clearQueue()
Clear the current load queue.
const CACHE_VERSION
Bump whenever the registration cache needs resetting.
array $attributes
Items in the JSON file that aren't being set as globals.
int bool $wgExtensionInfoMTime
When loading extensions through the extension registration system, this can be used to invalidate the...
const MEDIAWIKI_CORE
"requires" key that applies to MediaWiki core/$wgVersion
A BagOStuff object with no objects in it.
const OLDEST_MANIFEST_VERSION
Version of the oldest supported manifest version.
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
markLoaded($name, array $credits)
Mark a thing as loaded.
readFromQueue(array $queue)
Process a queue of extensions and return their extracted data.
array $queued
List of paths that should be 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 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
load($path)
Loads and processes the given JSON file without delay.
wfMemcKey()
Make a cache key for the local wiki.
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
getQueue()
Get the current load queue.
Allows to change the fields on the form that will be generated $name