20 MainConfigNames::ActionFilteredLogs,
21 MainConfigNames::Actions,
22 MainConfigNames::AddGroups,
23 MainConfigNames::APIFormatModules,
24 MainConfigNames::APIListModules,
25 MainConfigNames::APIMetaModules,
26 MainConfigNames::APIModules,
27 MainConfigNames::APIPropModules,
28 MainConfigNames::AuthManagerAutoConfig,
29 MainConfigNames::AvailableRights,
30 MainConfigNames::CentralIdLookupProviders,
31 MainConfigNames::ChangeCredentialsBlacklist,
32 MainConfigNames::ConfigRegistry,
33 MainConfigNames::ContentHandlers,
34 MainConfigNames::DefaultUserOptions,
35 MainConfigNames::ExtensionEntryPointListFiles,
36 MainConfigNames::ExtensionFunctions,
37 MainConfigNames::FeedClasses,
38 MainConfigNames::FileExtensions,
39 MainConfigNames::FilterLogTypes,
40 MainConfigNames::GrantPermissionGroups,
41 MainConfigNames::GrantPermissions,
42 MainConfigNames::GroupPermissions,
43 MainConfigNames::GroupsAddToSelf,
44 MainConfigNames::GroupsRemoveFromSelf,
45 MainConfigNames::HiddenPrefs,
46 MainConfigNames::ImplicitGroups,
47 MainConfigNames::JobClasses,
48 MainConfigNames::LogActions,
49 MainConfigNames::LogActionsHandlers,
50 MainConfigNames::LogHeaders,
51 MainConfigNames::LogNames,
52 MainConfigNames::LogRestrictions,
53 MainConfigNames::LogTypes,
54 MainConfigNames::MediaHandlers,
55 MainConfigNames::PasswordPolicy,
56 MainConfigNames::RateLimits,
57 MainConfigNames::RawHtmlMessages,
58 MainConfigNames::ReauthenticateTime,
59 MainConfigNames::RecentChangesFlags,
60 MainConfigNames::RemoveCredentialsBlacklist,
61 MainConfigNames::RemoveGroups,
62 MainConfigNames::ResourceLoaderSources,
63 MainConfigNames::RevokePermissions,
64 MainConfigNames::SessionProviders,
65 MainConfigNames::SpecialPages
73 protected const CORE_ATTRIBS = [
79 'LateJSConfigVarNames',
80 'TempUserSerialProviders',
81 'TempUserSerialMappings',
91 protected const MERGE_STRATEGIES = [
92 'wgAuthManagerAutoConfig' =>
'array_plus_2d',
93 'wgCapitalLinkOverrides' =>
'array_plus',
94 'wgExtraGenderNamespaces' =>
'array_plus',
95 'wgGrantPermissions' =>
'array_plus_2d',
96 'wgGroupPermissions' =>
'array_plus_2d',
97 'wgHooks' =>
'array_merge_recursive',
98 'wgNamespaceContentModels' =>
'array_plus',
99 'wgNamespaceProtection' =>
'array_plus',
100 'wgNamespacesWithSubpages' =>
'array_plus',
101 'wgPasswordPolicy' =>
'array_merge_recursive',
102 'wgRateLimits' =>
'array_plus_2d',
103 'wgRevokePermissions' =>
'array_plus_2d',
111 protected const CREDIT_ATTRIBS = [
129 protected const NOT_ATTRIBS = [
133 'load_composer_autoloader',
138 'AutoloadNamespaces',
139 'ExtensionMessagesFiles',
141 'MessagePosterModule',
145 'ResourceFileModulePaths',
146 'ResourceModuleSkinStyles',
148 'ServiceWiringFiles',
159 'wgExtensionMessagesFiles' => [],
160 'wgMessagesDirs' => [],
232 $json = file_get_contents(
$path );
233 $info = json_decode( $json,
true );
236 throw new RuntimeException(
"Failed to load JSON data from $path" );
239 if ( !isset( $info[
'manifest_version'] ) ) {
241 "{$info['name']}'s extension.json or skin.json does not have manifest_version, " .
242 'this is deprecated since MediaWiki 1.29',
245 $info[
'manifest_version'] = 1;
248 $this->
extractInfo( $path, $info, $info[
'manifest_version'] );
257 $dir = dirname(
$path );
265 if ( isset( $info[
'ServiceWiringFiles'] ) ) {
267 'wgServiceWiringFiles',
269 $info[
'ServiceWiringFiles']
273 if ( isset( $info[
'callback'] ) ) {
274 $this->callbacks[$name] = $info[
'callback'];
277 $this->extractAutoload( $info, $dir );
281 if ( $version >= 2 ) {
289 if ( isset( $info[
'ParsoidModules'] ) ) {
290 foreach ( $info[
'ParsoidModules'] as &$module ) {
291 if ( is_string( $module ) ) {
292 $className = $module;
294 'class' => $className,
297 $module[
'name'] = $name;
301 if ( $version >= 2 ) {
305 foreach ( $info as $key => $val ) {
307 if ( in_array( $key, self::$globalSettings ) ) {
312 if ( $key[0] ===
'@' ) {
316 if ( $version >= 2 ) {
318 if ( in_array( $key, self::CORE_ATTRIBS ) ) {
319 $this->
storeToArray( $path, $key, $val, $this->attributes );
323 if ( !in_array( $key, self::NOT_ATTRIBS )
324 && !in_array( $key, self::CREDIT_ATTRIBS )
338 if ( isset( $info[
'attributes'] ) ) {
339 foreach ( $info[
'attributes'] as $extName => $value ) {
347 foreach ( $this->globals as $key => $val ) {
348 if ( isset( self::MERGE_STRATEGIES[$key] ) ) {
354 foreach ( $this->extAttributes as $extName => $value ) {
356 if ( isset( $this->credits[$extName] ) ) {
357 foreach ( $value as $attrName => $attrValue ) {
360 $extName . $attrName,
365 unset( $this->extAttributes[$extName] );
377 'autoloaderClasses' =>
$autoload[
'classes'],
378 'autoloaderNS' =>
$autoload[
'namespaces'],
385 if ( !$includeDev || !isset( $info[
'dev-requires'] ) ) {
386 return $info[
'requires'] ?? [];
389 if ( !isset( $info[
'requires'] ) ) {
390 return $info[
'dev-requires'] ?? [];
400 $pick =
static function ( $a, $b ) {
403 } elseif ( $b ===
null ) {
410 $req = $info[
'requires'];
411 $dev = $info[
'dev-requires'];
412 if ( isset( $req[
'MediaWiki'] ) || isset( $dev[
'MediaWiki'] ) ) {
413 $merged[
'MediaWiki'] = $pick(
414 $req[
'MediaWiki'] ??
null,
415 $dev[
'MediaWiki'] ??
null
419 $platform = array_merge(
420 array_keys( $req[
'platform'] ?? [] ),
421 array_keys( $dev[
'platform'] ?? [] )
424 foreach ( $platform as $pkey ) {
425 if ( $pkey ===
'php' ) {
427 $req[
'platform'][
'php'] ??
null,
428 $dev[
'platform'][
'php'] ??
null
433 $value = $dev[
'platform'][$pkey] ?? $req[
'platform'][$pkey];
435 $merged[
'platform'][$pkey] = $value;
439 foreach ( [
'extensions',
'skins' ] as $thing ) {
440 $things = array_merge(
441 array_keys( $req[$thing] ?? [] ),
442 array_keys( $dev[$thing] ?? [] )
444 foreach ( $things as $name ) {
445 $merged[$thing][$name] = $pick(
446 $req[$thing][$name] ??
null,
447 $dev[$thing][$name] ??
null
465 private function setArrayHookHandler(
467 array $hookHandlersAttr,
471 if ( isset( $callback[
'handler'] ) ) {
472 $handlerName = $callback[
'handler'];
473 $handlerDefinition = $hookHandlersAttr[$handlerName] ??
false;
474 if ( !$handlerDefinition ) {
475 throw new UnexpectedValueException(
476 "Missing handler definition for $name in HookHandlers attribute in $path"
479 $callback[
'handler'] = $handlerDefinition;
480 $callback[
'extensionPath'] =
$path;
481 $this->attributes[
'Hooks'][$name][] = $callback;
483 foreach ( $callback as $callable ) {
484 if ( is_array( $callable ) ) {
485 if ( isset( $callable[
'handler'] ) ) {
486 $this->setArrayHookHandler( $callable, $hookHandlersAttr, $name,
$path );
488 $this->globals[
'wgHooks'][$name][] = $callable;
490 } elseif ( is_string( $callable ) ) {
491 $this->setStringHookHandler( $callable, $hookHandlersAttr, $name,
$path );
507 private function setStringHookHandler(
509 array $hookHandlersAttr,
513 if ( isset( $hookHandlersAttr[$callback] ) ) {
515 'handler' => $hookHandlersAttr[$callback],
516 'extensionPath' =>
$path
518 $this->attributes[
'Hooks'][$name][] = $handler;
520 $this->globals[
'wgHooks'][$name][] = $callback;
533 $extName = $info[
'name'];
534 if ( isset( $info[
'Hooks'] ) ) {
535 $hookHandlersAttr = [];
536 foreach ( $info[
'HookHandlers'] ?? [] as $name => $def ) {
537 $hookHandlersAttr[$name] = [
'name' =>
"$extName-$name" ] + $def;
539 foreach ( $info[
'Hooks'] as $name => $callback ) {
540 if ( is_string( $callback ) ) {
541 $this->setStringHookHandler( $callback, $hookHandlersAttr, $name,
$path );
542 } elseif ( is_array( $callback ) ) {
543 $this->setArrayHookHandler( $callback, $hookHandlersAttr, $name,
$path );
547 if ( isset( $info[
'DeprecatedHooks'] ) ) {
548 $deprecatedHooks = [];
549 foreach ( $info[
'DeprecatedHooks'] as $name => $deprecatedHookInfo ) {
550 $deprecatedHookInfo += [
'component' => $extName ];
551 $deprecatedHooks[$name] = $deprecatedHookInfo;
553 if ( isset( $this->attributes[
'DeprecatedHooks'] ) ) {
554 $this->attributes[
'DeprecatedHooks'] += $deprecatedHooks;
556 $this->attributes[
'DeprecatedHooks'] = $deprecatedHooks;
567 if ( isset( $info[
'namespaces'] ) ) {
568 foreach ( $info[
'namespaces'] as $ns ) {
569 if ( defined( $ns[
'constant'] ) ) {
572 $id = constant( $ns[
'constant'] );
576 $this->defines[ $ns[
'constant'] ] = $id;
578 if ( !( isset( $ns[
'conditional'] ) && $ns[
'conditional'] ) ) {
580 $this->attributes[
'ExtensionNamespaces'][$id] = $ns[
'name'];
582 if ( isset( $ns[
'movable'] ) && !$ns[
'movable'] ) {
583 $this->attributes[
'ImmovableNamespaces'][] = $id;
585 if ( isset( $ns[
'gender'] ) ) {
586 $this->globals[
'wgExtraGenderNamespaces'][$id] = $ns[
'gender'];
588 if ( isset( $ns[
'subpages'] ) && $ns[
'subpages'] ) {
589 $this->globals[
'wgNamespacesWithSubpages'][$id] =
true;
591 if ( isset( $ns[
'content'] ) && $ns[
'content'] ) {
592 $this->globals[
'wgContentNamespaces'][] = $id;
594 if ( isset( $ns[
'defaultcontentmodel'] ) ) {
595 $this->globals[
'wgNamespaceContentModels'][$id] = $ns[
'defaultcontentmodel'];
597 if ( isset( $ns[
'protection'] ) ) {
598 $this->globals[
'wgNamespaceProtection'][$id] = $ns[
'protection'];
600 if ( isset( $ns[
'capitallinkoverride'] ) ) {
601 $this->globals[
'wgCapitalLinkOverrides'][$id] = $ns[
'capitallinkoverride'];
603 if ( isset( $ns[
'includable'] ) && !$ns[
'includable'] ) {
604 $this->globals[
'wgNonincludableNamespaces'][] = $id;
611 $defaultPaths = $info[
'ResourceFileModulePaths'] ??
false;
612 if ( isset( $defaultPaths[
'localBasePath'] ) ) {
613 if ( $defaultPaths[
'localBasePath'] ===
'' ) {
615 $defaultPaths[
'localBasePath'] = $dir;
617 $defaultPaths[
'localBasePath'] =
"$dir/{$defaultPaths['localBasePath']}";
621 foreach ( [
'ResourceModules',
'ResourceModuleSkinStyles',
'OOUIThemePaths' ] as $setting ) {
622 if ( isset( $info[$setting] ) ) {
623 foreach ( $info[$setting] as $name => $data ) {
624 if ( isset( $data[
'localBasePath'] ) ) {
625 if ( $data[
'localBasePath'] ===
'' ) {
627 $data[
'localBasePath'] = $dir;
629 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
632 if ( $defaultPaths ) {
633 $data += $defaultPaths;
635 $this->attributes[$setting][$name] = $data;
640 if ( isset( $info[
'QUnitTestModule'] ) ) {
641 $data = $info[
'QUnitTestModule'];
642 if ( isset( $data[
'localBasePath'] ) ) {
643 if ( $data[
'localBasePath'] ===
'' ) {
645 $data[
'localBasePath'] = $dir;
647 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
651 $data[
'targets'] = [
'test' ];
652 $this->attributes[
'QUnitTestModules'][
"test.{$info['name']}"] = $data;
655 if ( isset( $info[
'MessagePosterModule'] ) ) {
656 $data = $info[
'MessagePosterModule'];
657 $basePath = $data[
'localBasePath'] ??
'';
658 $baseDir = $basePath ===
'' ? $dir :
"$dir/$basePath";
659 foreach ( $data[
'scripts'] ?? [] as $scripts ) {
660 $this->attributes[
'MessagePosterModule'][
'scripts'][] =
663 foreach ( $data[
'dependencies'] ?? [] as $dependency ) {
664 $this->attributes[
'MessagePosterModule'][
'dependencies'][] = $dependency;
670 if ( isset( $info[
'ExtensionMessagesFiles'] ) ) {
671 foreach ( $info[
'ExtensionMessagesFiles'] as &
$file ) {
672 $file =
"$dir/$file";
674 $this->globals[
"wgExtensionMessagesFiles"] += $info[
'ExtensionMessagesFiles'];
686 if ( isset( $info[
'MessagesDirs'] ) ) {
687 foreach ( $info[
'MessagesDirs'] as $name => $files ) {
688 foreach ( (array)$files as
$file ) {
689 $this->globals[
"wgMessagesDirs"][$name][] =
"$dir/$file";
702 if ( isset( $info[
'ValidSkinNames'] ) ) {
703 foreach ( $info[
'ValidSkinNames'] as $skinKey => $data ) {
704 if ( isset( $data[
'args'][0][
'templateDirectory'] ) ) {
705 $templateDirectory = $data[
'args'][0][
'templateDirectory'];
706 $correctedPath = $dir .
'/' . $templateDirectory;
712 if ( is_dir( $correctedPath ) ) {
713 $data[
'args'][0][
'templateDirectory'] = $correctedPath;
715 $data[
'args'][0][
'templateDirectory'] = $templateDirectory;
717 'Template directory should be relative to skin or omitted for skin ' . $skinKey,
721 } elseif ( isset( $data[
'args'][0] ) ) {
723 $data[
'args'][0][
'templateDirectory'] = $dir .
'/templates';
725 $this->globals[
'wgValidSkinNames'][$skinKey] = $data;
735 if ( isset( $info[
'SkinLessImportPaths'] ) ) {
736 foreach ( $info[
'SkinLessImportPaths'] as $skin => $subpath ) {
737 $this->attributes[
'SkinLessImportPaths'][$skin] =
"$dir/$subpath";
753 foreach ( self::CREDIT_ATTRIBS as $attr ) {
754 if ( isset( $info[$attr] ) ) {
763 if ( isset( $this->credits[$name] ) ) {
764 $firstPath = $this->credits[$name][
'path'];
766 throw new Exception(
"It was attempted to load $name twice, from $firstPath and $secondPath." );
781 if ( isset( $info[
'config'] ) ) {
782 if ( isset( $info[
'config'][
'_prefix'] ) ) {
783 $prefix = $info[
'config'][
'_prefix'];
784 unset( $info[
'config'][
'_prefix'] );
788 foreach ( $info[
'config'] as $key => $val ) {
789 if ( $key[0] !==
'@' ) {
790 $this->addConfigGlobal(
"$prefix$key", $val, $info[
'name'] );
804 private function applyPath( array $value,
string $dir ): array {
807 foreach ( $value as $k => $v ) {
808 $result[$k] = $dir .
'/' . $v;
821 $prefix = $info[
'config_prefix'] ??
'wg';
822 if ( isset( $info[
'config'] ) ) {
823 foreach ( $info[
'config'] as $key => $data ) {
824 if ( !array_key_exists(
'value', $data ) ) {
825 throw new UnexpectedValueException(
"Missing value for config $key" );
828 $value = $data[
'value'];
829 if ( isset( $data[
'path'] ) && $data[
'path'] ) {
830 if ( is_array( $value ) ) {
831 $value = $this->applyPath( $value, $dir );
833 $value =
"$dir/$value";
836 if ( isset( $data[
'merge_strategy'] ) ) {
839 $this->addConfigGlobal(
"$prefix$key", $value, $info[
'name'] );
840 $data[
'providedby'] = $info[
'name'];
841 if ( isset( $info[
'ConfigRegistry'][0] ) ) {
842 $data[
'configregistry'] = array_keys( $info[
'ConfigRegistry'] )[0];
855 private function addConfigGlobal( $key, $value, $extName ) {
856 if ( array_key_exists( $key, $this->globals ) ) {
857 throw new RuntimeException(
858 "The configuration setting '$key' was already set by MediaWiki core or"
859 .
" another extension, and cannot be set again by $extName." );
861 $this->globals[$key] = $value;
865 foreach ( $paths as
$path ) {
866 $this->globals[$global][] =
"$dir/$path";
880 if ( !is_array( $value ) ) {
881 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
883 if ( isset( $array[$name] ) ) {
884 $array[$name] = array_merge_recursive( $array[$name], $value );
886 $array[$name] = $value;
900 if ( !is_array( $value ) ) {
901 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
903 if ( isset( $array[$name] ) ) {
904 $array[$name] = array_merge( $array[$name], $value );
906 $array[$name] = $value;
921 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
922 $paths[] =
"$dir/vendor/autoload.php";
942 $autoload = $this->autoload;
945 $autoload[
'classes'] += $this->autoloadDev[
'classes'];
946 $autoload[
'namespaces'] += $this->autoloadDev[
'namespaces'];
951 if ( !empty( $this->autoloadDev[
'files'] ) ) {
954 $autoload[
'files'] = array_merge(
956 $this->autoloadDev[
'files']
968 private function extractAutoload( array $info,
string $dir ) {
969 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
970 $file =
"$dir/vendor/autoload.php";
971 if ( file_exists(
$file ) ) {
972 $this->autoload[
'files'][] =
$file;
976 if ( isset( $info[
'AutoloadClasses'] ) ) {
977 $paths = $this->applyPath( $info[
'AutoloadClasses'], $dir );
978 $this->autoload[
'classes'] += $paths;
981 if ( isset( $info[
'AutoloadNamespaces'] ) ) {
982 $paths = $this->applyPath( $info[
'AutoloadNamespaces'], $dir );
983 $this->autoload[
'namespaces'] += $paths;
986 if ( isset( $info[
'TestAutoloadClasses'] ) ) {
987 $paths = $this->applyPath( $info[
'TestAutoloadClasses'], $dir );
988 $this->autoloadDev[
'classes'] += $paths;
991 if ( isset( $info[
'TestAutoloadNamespaces'] ) ) {
992 $paths = $this->applyPath( $info[
'TestAutoloadNamespaces'], $dir );
993 $this->autoloadDev[
'namespaces'] += $paths;
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Utility class for loading extension manifests and aggregating their contents.
extractHooks(array $info, string $path)
Extract hook information from Hooks and HookHandler attributes.
extractNamespaces(array $info)
Register namespaces with the appropriate global settings.
extractCredits( $path, array $info)
array $attributes
Any thing else in the $info that hasn't already been processed.
extractInfoFromFile(string $path)
Extracts extension info from the given JSON file.
callable[] $callbacks
Things to be called once registration of these extensions are done keyed by the name of the extension...
array $defines
Things that should be define()'d.
string[][] $autoloadDev
Autoloader information for development.
extractExtensionMessagesFiles( $dir, array $info)
extractConfig1(array $info)
Set configuration settings for manifest_version == 1.
array $globals
Stuff that is going to be set to $GLOBALS.
extractMessagesDirs( $dir, array $info)
Set message-related settings, which need to be expanded to use absolute paths.
extractConfig2(array $info, $dir)
Set configuration settings for manifest_version == 2.
getExtractedInfo(bool $includeDev=false)
extractResourceLoaderModules( $dir, array $info)
array $extAttributes
Extension attributes, keyed by name => settings.
extractSkins( $dir, array $info)
Extract skins and handle path correction for templateDirectory.
getExtraAutoloaderPaths( $dir, array $info)
extractAttributes( $path, array $info)
getRequirements(array $info, $includeDev)
Get the requirements for the provided info.
extractSkinImportPaths( $dir, array $info)
extractInfo( $path, array $info, $version)
getExtractedAutoloadInfo(bool $includeDev=false)
Returns the extracted autoload info.
storeToArray( $path, $name, $value, &$array)
Stores $value to $array; using array_merge() if $array already contains $name.
string[][] $autoload
Autoloader information.
extractPathBasedGlobal( $global, $dir, $paths)
storeToArrayRecursive( $path, $name, $value, &$array)
Stores $value to $array; using array_merge_recursive() if $array already contains $name.
static array $globalSettings
Keys that should be set to $GLOBALS.
const MERGE_STRATEGY
Special key that defines the merge strategy.
A class containing constants representing the names of configuration variables.
Processors read associated arrays and register whatever is required.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.