Go to the documentation of this file.
3 use Composer\Semver\Semver;
4 use Wikimedia\ScopedCallback;
99 if ( self::$instance ===
null ) {
100 self::$instance =
new self();
113 if ( $mtime ===
false ) {
114 if ( file_exists(
$path ) ) {
115 $mtime = filemtime(
$path );
117 throw new Exception(
"$path does not exist!" );
120 if ( $mtime ===
false ) {
121 $err = error_get_last();
122 throw new Exception(
"Couldn't stat $path: {$err['message']}" );
126 $this->queued[
$path] = $mtime;
135 if ( !$this->queued ) {
139 if ( $this->finished ) {
141 "The following paths tried to load late: "
142 . implode(
', ', array_keys( $this->queued ) )
160 }
catch ( InvalidArgumentException
$e ) {
166 md5( json_encode( $this->queued + $versions ) )
176 $data[
'globals'][
'wgAutoloadClasses'] +=
$data[
'autoload'];
177 unset(
$data[
'autoload'] );
210 $this->finished =
true;
219 'shell' => !Shell::isDisabled(),
238 PHP_MAJOR_VERSION .
'.' . PHP_MINOR_VERSION .
'.' . PHP_RELEASE_VERSION,
239 get_loaded_extensions(),
254 $autoloadClasses = [];
255 $autoloadNamespaces = [];
256 $autoloaderPaths = [];
259 $extDependencies = [];
263 $json = file_get_contents(
$path );
264 if ( $json ===
false ) {
265 throw new Exception(
"Unable to read $path, does it exist?" );
267 $info = json_decode( $json,
true );
268 if ( !is_array( $info ) ) {
269 throw new Exception(
"$path is not a valid JSON file." );
272 if ( !isset( $info[
'manifest_version'] ) ) {
274 "{$info['name']}'s extension.json or skin.json does not have manifest_version",
279 $info[
'manifest_version'] = 1;
281 $version = $info[
'manifest_version'];
282 if ( $version < self::OLDEST_MANIFEST_VERSION || $version > self::MANIFEST_VERSION ) {
283 $incompatible[] =
"$path: unsupported manifest_version: {$version}";
286 $dir = dirname(
$path );
287 if ( isset( $info[
'AutoloadClasses'] ) ) {
289 $GLOBALS[
'wgAutoloadClasses'] += $autoload;
290 $autoloadClasses += $autoload;
292 if ( isset( $info[
'AutoloadNamespaces'] ) ) {
293 $autoloadNamespaces += $this->
processAutoLoader( $dir, $info[
'AutoloadNamespaces'] );
298 $requires = $processor->getRequirements( $info );
301 if ( is_array( $requires ) && $requires && isset( $info[
'name'] ) ) {
302 $extDependencies[$info[
'name']] = $requires;
306 $autoloaderPaths = array_merge( $autoloaderPaths,
307 $processor->getExtraAutoloaderPaths( $dir, $info ) );
309 $processor->extractInfo(
$path, $info, $version );
311 $data = $processor->getExtractedInfo();
312 $data[
'warnings'] = $warnings;
315 $incompatible = array_merge(
318 ->setLoadedExtensionsAndSkins(
$data[
'credits'] )
319 ->checkArray( $extDependencies )
322 if ( $incompatible ) {
327 $data[
'globals'][
'wgAutoloadClasses'] = [];
328 $data[
'autoload'] = $autoloadClasses;
329 $data[
'autoloaderPaths'] = $autoloaderPaths;
330 $data[
'autoloaderNS'] = $autoloadNamespaces;
335 foreach ( $info[
'globals']
as $key => $val ) {
338 if ( is_array( $val ) && isset( $val[self::MERGE_STRATEGY] ) ) {
340 unset( $val[self::MERGE_STRATEGY] );
342 $mergeStrategy =
'array_merge';
352 if ( !is_array(
$GLOBALS[$key] ) || !is_array( $val ) ) {
357 switch ( $mergeStrategy ) {
358 case 'array_merge_recursive':
361 case 'array_replace_recursive':
364 case 'array_plus_2d':
374 throw new UnexpectedValueException(
"Unknown merge strategy '$mergeStrategy'" );
378 if ( isset( $info[
'autoloaderNS'] ) ) {
382 foreach ( $info[
'defines']
as $name => $val ) {
383 define(
$name, $val );
385 foreach ( $info[
'autoloaderPaths']
as $path ) {
386 if ( file_exists(
$path ) ) {
391 $this->loaded += $info[
'credits'];
392 if ( $info[
'attributes'] ) {
393 if ( !$this->attributes ) {
394 $this->attributes = $info[
'attributes'];
396 $this->attributes = array_merge_recursive( $this->attributes, $info[
'attributes'] );
400 foreach ( $info[
'callbacks']
as $name => $cb ) {
401 if ( !is_callable( $cb ) ) {
402 if ( is_array( $cb ) ) {
403 $cb =
'[ ' . implode(
', ', $cb ) .
' ]';
405 throw new UnexpectedValueException(
"callback '$cb' is not callable" );
407 $cb( $info[
'credits'][
$name] );
434 $isLoaded = isset( $this->loaded[
$name] );
435 if ( $constraint ===
'*' || !$isLoaded ) {
439 if ( !isset( $this->loaded[
$name][
'version'] ) ) {
440 $msg =
"{$name} does not expose its version, but an extension or a skin"
441 .
" requires: {$constraint}.";
442 throw new LogicException( $msg );
445 return SemVer::satisfies( $this->loaded[
$name][
'version'], $constraint );
453 return $this->testAttributes[
$name] ??
454 $this->attributes[
$name] ?? [];
467 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
468 throw new RuntimeException( __METHOD__ .
' can only be used in tests' );
471 if ( isset( $this->testAttributes[
$name] ) ) {
472 throw new Exception(
"The attribute '$name' has already been overridden" );
475 return new ScopedCallback(
function ()
use (
$name ) {
476 unset( $this->testAttributes[
$name] );
499 $file =
"$dir/$file";
static newFromId( $id)
Create a new cache object of the specified type.
isLoaded( $name, $constraint=' *')
Whether a thing has been loaded.
getQueue()
Get the current load queue.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
bool $finished
Whether we are done loading things.
const MANIFEST_VERSION
Version of the highest supported manifest version Note: Update MANIFEST_VERSION_MW_VERSION when chang...
A BagOStuff object with no objects in it.
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
Copyright (C) 2018 Kunal Mehta legoktm@member.fsf.org
static detectLocalServerCache()
Detects which local server cache library is present and returns a configuration for it.
exportExtractedData(array $info)
$wgVersion
MediaWiki version number.
getAllThings()
Get information about all things.
array $loaded
Array of loaded things, keyed by name, values are credits information.
getAbilities()
Get the list of abilities and their values.
processAutoLoader( $dir, array $files)
Fully expand autoloader paths.
setAttributeForTest( $name, array $value)
Force override the value of an attribute during tests.
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.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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.
const MANIFEST_VERSION_MW_VERSION
MediaWiki version constraint representing what the current highest MANIFEST_VERSION is supported in.
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
static string[] $psr4Namespaces
finish()
After this is called, no more extensions can be loaded.
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))
const OLDEST_MANIFEST_VERSION
Version of the oldest supported manifest version.
const MEDIAWIKI_CORE
"requires" key that applies to MediaWiki core/$wgVersion
Allows to change the fields on the form that will be generated $name
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.
array $testAttributes
Attributes for testing.
$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 ...
buildVersionChecker()
Queries information about the software environment and constructs an appropiate version checker.
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...
static ExtensionRegistry $instance