6use InvalidArgumentException;
10use UnexpectedValueException;
89 'LateJSConfigVarNames',
90 'TempUserSerialProviders',
91 'TempUserSerialMappings',
92 'DatabaseVirtualDomains',
93 'UserOptionsStoreProviders',
103 'wgAuthManagerAutoConfig' =>
'array_plus_2d',
104 'wgCapitalLinkOverrides' =>
'array_plus',
105 'wgExtraGenderNamespaces' =>
'array_plus',
106 'wgGrantPermissions' =>
'array_plus_2d',
107 'wgGroupPermissions' =>
'array_plus_2d',
108 'wgHooks' =>
'array_merge_recursive',
109 'wgNamespaceContentModels' =>
'array_plus',
110 'wgNamespaceProtection' =>
'array_plus',
111 'wgNamespacesWithSubpages' =>
'array_plus',
112 'wgPasswordPolicy' =>
'array_merge_recursive',
113 'wgRateLimits' =>
'array_plus_2d',
114 'wgRevokePermissions' =>
'array_plus_2d',
140 'load_composer_autoloader',
145 'AutoloadNamespaces',
146 'ExtensionMessagesFiles',
147 'TranslationAliasesDirs',
148 'ForeignResourcesDir',
150 'DomainEventSubscribers',
151 'MessagePosterModule',
155 'ResourceFileModulePaths',
156 'ResourceModuleSkinStyles',
158 'ServiceWiringFiles',
169 'wgExtensionMessagesFiles' => [],
170 'wgRestAPIAdditionalRouteFiles' => [],
171 'wgMessagesDirs' => [],
172 'TranslationAliasesDirs' => [],
245 $json = file_get_contents(
$path );
246 $info = json_decode( $json,
true );
249 throw new RuntimeException(
"Failed to load JSON data from $path" );
252 $this->
extractInfo( $path, $info, $info[
'manifest_version'] );
261 $dir = dirname(
$path );
274 if ( isset( $info[
'ServiceWiringFiles'] ) ) {
276 'wgServiceWiringFiles',
278 $info[
'ServiceWiringFiles']
282 if ( isset( $info[
'callback'] ) ) {
283 $this->callbacks[$name] = $info[
'callback'];
286 $this->extractAutoload( $info, $dir );
290 if ( $version >= 2 ) {
298 if ( isset( $info[
'ParsoidModules'] ) ) {
299 foreach ( $info[
'ParsoidModules'] as &$module ) {
300 if ( is_string( $module ) ) {
301 $className = $module;
303 'class' => $className,
306 $module[
'name'] = $name;
312 if ( $version >= 2 ) {
316 foreach ( $info as $key => $val ) {
318 if ( in_array( $key, self::$globalSettings ) ) {
323 if ( $key[0] ===
'@' ) {
327 if ( $version >= 2 ) {
329 if ( in_array( $key, self::CORE_ATTRIBS ) ) {
330 $this->
storeToArray( $path, $key, $val, $this->attributes );
334 if ( !in_array( $key, self::NOT_ATTRIBS )
335 && !in_array( $key, self::CREDIT_ATTRIBS )
349 if ( isset( $info[
'attributes'] ) ) {
350 foreach ( $info[
'attributes'] as $extName => $value ) {
358 foreach ( $this->globals as $key => $val ) {
359 if ( isset( self::MERGE_STRATEGIES[$key] ) ) {
365 foreach ( $this->extAttributes as $extName => $value ) {
367 if ( isset( $this->credits[$extName] ) ) {
368 foreach ( $value as $attrName => $attrValue ) {
371 $extName . $attrName,
376 unset( $this->extAttributes[$extName] );
389 'autoloaderClasses' =>
$autoload[
'classes'],
390 'autoloaderNS' =>
$autoload[
'namespaces'],
396 if ( !$includeDev || !isset( $info[
'dev-requires'] ) ) {
397 return $info[
'requires'] ?? [];
400 if ( !isset( $info[
'requires'] ) ) {
401 return $info[
'dev-requires'] ?? [];
411 $pick =
static function ( $a, $b ) {
414 } elseif ( $b ===
null ) {
421 $req = $info[
'requires'];
422 $dev = $info[
'dev-requires'];
423 if ( isset( $req[
'MediaWiki'] ) || isset( $dev[
'MediaWiki'] ) ) {
424 $merged[
'MediaWiki'] = $pick(
425 $req[
'MediaWiki'] ??
null,
426 $dev[
'MediaWiki'] ??
null
430 $platform = array_merge(
431 array_keys( $req[
'platform'] ?? [] ),
432 array_keys( $dev[
'platform'] ?? [] )
435 foreach ( $platform as $pkey ) {
436 if ( $pkey ===
'php' ) {
438 $req[
'platform'][
'php'] ??
null,
439 $dev[
'platform'][
'php'] ??
null
444 $value = $dev[
'platform'][$pkey] ?? $req[
'platform'][$pkey];
446 $merged[
'platform'][$pkey] = $value;
450 foreach ( [
'extensions',
'skins' ] as $thing ) {
451 $things = array_merge(
452 array_keys( $req[$thing] ?? [] ),
453 array_keys( $dev[$thing] ?? [] )
455 foreach ( $things as $name ) {
456 $merged[$thing][$name] = $pick(
457 $req[$thing][$name] ??
null,
458 $dev[$thing][$name] ??
null
478 private function setArrayHookHandler(
480 array $hookHandlersAttr,
484 if ( isset( $callback[
'handler'] ) ) {
485 $handlerName = $callback[
'handler'];
486 $handlerDefinition = $hookHandlersAttr[$handlerName] ??
false;
487 if ( !$handlerDefinition ) {
488 throw new UnexpectedValueException(
489 "Missing handler definition for $name in HookHandlers attribute in $path"
492 $callback[
'handler'] = $handlerDefinition;
493 $callback[
'extensionPath'] =
$path;
494 $this->attributes[
'Hooks'][$name][] = $callback;
496 foreach ( $callback as $callable ) {
497 if ( is_array( $callable ) ) {
498 if ( isset( $callable[
'handler'] ) ) {
499 $this->setArrayHookHandler( $callable, $hookHandlersAttr, $name,
$path );
501 $this->globals[
'wgHooks'][$name][] = $callable;
503 } elseif ( is_string( $callable ) ) {
504 $this->setStringHookHandler( $callable, $hookHandlersAttr, $name,
$path );
520 private function setStringHookHandler(
522 array $hookHandlersAttr,
526 if ( isset( $hookHandlersAttr[$callback] ) ) {
528 'handler' => $hookHandlersAttr[$callback],
529 'extensionPath' =>
$path
531 $this->attributes[
'Hooks'][$name][] = $handler;
533 $this->globals[
'wgHooks'][$name][] = $callback;
546 $extName = $info[
'name'];
547 if ( isset( $info[
'Hooks'] ) ) {
548 $hookHandlersAttr = [];
549 foreach ( $info[
'HookHandlers'] ?? [] as $name => $def ) {
550 $hookHandlersAttr[$name] = [
'name' =>
"$extName-$name" ] + $def;
552 foreach ( $info[
'Hooks'] as $name => $callback ) {
553 if ( is_string( $callback ) ) {
554 $this->setStringHookHandler( $callback, $hookHandlersAttr, $name,
$path );
555 } elseif ( is_array( $callback ) ) {
556 $this->setArrayHookHandler( $callback, $hookHandlersAttr, $name,
$path );
560 if ( isset( $info[
'DeprecatedHooks'] ) ) {
561 $deprecatedHooks = [];
562 foreach ( $info[
'DeprecatedHooks'] as $name => $deprecatedHookInfo ) {
563 $deprecatedHookInfo += [
'component' => $extName ];
564 $deprecatedHooks[$name] = $deprecatedHookInfo;
566 if ( isset( $this->attributes[
'DeprecatedHooks'] ) ) {
567 $this->attributes[
'DeprecatedHooks'] += $deprecatedHooks;
569 $this->attributes[
'DeprecatedHooks'] = $deprecatedHooks;
581 $this->attributes[
'DomainEventSubscribers'] ??= [];
582 foreach ( $info[
'DomainEventSubscribers'] ?? [] as $subscriber ) {
583 $subscriber[
'extensionPath'] =
$path;
584 $this->attributes[
'DomainEventSubscribers'][] = $subscriber;
594 if ( isset( $info[
'namespaces'] ) ) {
595 foreach ( $info[
'namespaces'] as $ns ) {
596 if ( defined( $ns[
'constant'] ) ) {
599 $id = constant( $ns[
'constant'] );
603 $this->defines[ $ns[
'constant'] ] = $id;
605 if ( !( isset( $ns[
'conditional'] ) && $ns[
'conditional'] ) ) {
607 $this->attributes[
'ExtensionNamespaces'][$id] = $ns[
'name'];
609 if ( isset( $ns[
'movable'] ) && !$ns[
'movable'] ) {
610 $this->attributes[
'ImmovableNamespaces'][] = $id;
612 if ( isset( $ns[
'gender'] ) ) {
613 $this->globals[
'wgExtraGenderNamespaces'][$id] = $ns[
'gender'];
615 if ( isset( $ns[
'subpages'] ) && $ns[
'subpages'] ) {
616 $this->globals[
'wgNamespacesWithSubpages'][$id] =
true;
618 if ( isset( $ns[
'content'] ) && $ns[
'content'] ) {
619 $this->globals[
'wgContentNamespaces'][] = $id;
621 if ( isset( $ns[
'defaultcontentmodel'] ) ) {
622 $this->globals[
'wgNamespaceContentModels'][$id] = $ns[
'defaultcontentmodel'];
624 if ( isset( $ns[
'protection'] ) ) {
625 $this->globals[
'wgNamespaceProtection'][$id] = $ns[
'protection'];
627 if ( isset( $ns[
'capitallinkoverride'] ) ) {
628 $this->globals[
'wgCapitalLinkOverrides'][$id] = $ns[
'capitallinkoverride'];
630 if ( isset( $ns[
'includable'] ) && !$ns[
'includable'] ) {
631 $this->globals[
'wgNonincludableNamespaces'][] = $id;
638 $defaultPaths = $info[
'ResourceFileModulePaths'] ??
false;
639 if ( isset( $defaultPaths[
'localBasePath'] ) ) {
640 if ( $defaultPaths[
'localBasePath'] ===
'' ) {
642 $defaultPaths[
'localBasePath'] = $dir;
644 $defaultPaths[
'localBasePath'] =
"$dir/{$defaultPaths['localBasePath']}";
648 foreach ( [
'ResourceModules',
'ResourceModuleSkinStyles',
'OOUIThemePaths' ] as $setting ) {
649 if ( isset( $info[$setting] ) ) {
650 foreach ( $info[$setting] as $name => $data ) {
651 if ( isset( $data[
'localBasePath'] ) ) {
652 if ( $data[
'localBasePath'] ===
'' ) {
654 $data[
'localBasePath'] = $dir;
656 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
659 if ( $defaultPaths ) {
660 $data += $defaultPaths;
662 $this->attributes[$setting][$name] = $data;
667 if ( isset( $info[
'QUnitTestModule'] ) ) {
668 $data = $info[
'QUnitTestModule'];
669 if ( isset( $data[
'localBasePath'] ) ) {
670 if ( $data[
'localBasePath'] ===
'' ) {
672 $data[
'localBasePath'] = $dir;
674 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
677 $this->attributes[
'QUnitTestModules'][
"test.{$info['name']}"] = $data;
680 if ( isset( $info[
'MessagePosterModule'] ) ) {
681 $data = $info[
'MessagePosterModule'];
682 $basePath = $data[
'localBasePath'] ??
'';
683 $baseDir = $basePath ===
'' ? $dir :
"$dir/$basePath";
684 foreach ( $data[
'scripts'] ?? [] as $scripts ) {
685 $this->attributes[
'MessagePosterModule'][
'scripts'][] =
688 foreach ( $data[
'dependencies'] ?? [] as $dependency ) {
689 $this->attributes[
'MessagePosterModule'][
'dependencies'][] = $dependency;
695 if ( isset( $info[
'ExtensionMessagesFiles'] ) ) {
696 foreach ( $info[
'ExtensionMessagesFiles'] as &$file ) {
697 $file =
"$dir/$file";
699 $this->globals[
"wgExtensionMessagesFiles"] += $info[
'ExtensionMessagesFiles'];
705 if ( isset( $info[
'RestModuleFiles'] ) ) {
706 foreach ( $info[
'RestModuleFiles'] as &$file ) {
707 $this->globals[
"wg$var"][] =
"$dir/$file";
720 if ( isset( $info[
'MessagesDirs'] ) ) {
721 foreach ( $info[
'MessagesDirs'] as $name => $files ) {
722 foreach ( (array)$files as $file ) {
723 $this->globals[
"wgMessagesDirs"][$name][] =
"$dir/$file";
737 foreach ( $info[
'TranslationAliasesDirs'] ?? [] as $name => $files ) {
738 foreach ( (array)$files as $file ) {
739 $this->globals[
'wgTranslationAliasesDirs'][$name][] =
"$dir/$file";
751 if ( isset( $info[
'ValidSkinNames'] ) ) {
752 foreach ( $info[
'ValidSkinNames'] as $skinKey => $data ) {
753 if ( isset( $data[
'args'][0] ) ) {
754 $templateDirectory = $data[
'args'][0][
'templateDirectory'] ??
'templates';
755 $data[
'args'][0][
'templateDirectory'] = $dir .
'/' . $templateDirectory;
757 $this->globals[
'wgValidSkinNames'][$skinKey] = $data;
772 if ( isset( $info[
'RateLimits'] ) ) {
773 $rights = array_keys( $info[
'RateLimits'] );
775 if ( isset( $info[
'AvailableRights'] ) ) {
776 $rights = array_diff( $rights, $info[
'AvailableRights'] );
779 $this->globals[
'wgImplicitRights'] = array_merge(
780 $this->globals[
'wgImplicitRights'] ?? [],
791 if ( isset( $info[
'SkinLessImportPaths'] ) ) {
792 foreach ( $info[
'SkinLessImportPaths'] as $skin => $subpath ) {
793 $this->attributes[
'SkinLessImportPaths'][$skin] =
"$dir/$subpath";
810 foreach ( self::CREDIT_ATTRIBS as $attr ) {
811 if ( isset( $info[$attr] ) ) {
820 if ( isset( $this->credits[$name] ) ) {
821 $firstPath = $this->credits[$name][
'path'];
823 throw new InvalidArgumentException(
824 "It was attempted to load $name twice, from $firstPath and $secondPath."
834 if ( array_key_exists(
'ForeignResourcesDir', $info ) ) {
835 if ( !is_string( $info[
'ForeignResourcesDir'] ) ) {
836 throw new InvalidArgumentException(
"Incorrect ForeignResourcesDir type, must be a string (in $name)" );
838 $this->attributes[
'ForeignResourcesDir'][$name] =
"{$dir}/{$info['ForeignResourcesDir']}";
843 if ( isset( $info[
'InstallerTasks'] ) ) {
846 $schemaBasePath =
$path .
'/sql';
847 foreach ( $info[
'InstallerTasks'] as $taskSpec ) {
848 $this->attributes[
'InstallerTasks'][]
849 = $taskSpec + [
'schemaBasePath' => $schemaBasePath ];
862 if ( isset( $info[
'config'] ) ) {
863 if ( isset( $info[
'config'][
'_prefix'] ) ) {
864 $prefix = $info[
'config'][
'_prefix'];
865 unset( $info[
'config'][
'_prefix'] );
869 foreach ( $info[
'config'] as $key => $val ) {
870 if ( $key[0] !==
'@' ) {
871 $this->addConfigGlobal(
"$prefix$key", $val, $info[
'name'] );
885 private function applyPath( array $value,
string $dir ): array {
888 foreach ( $value as $k => $v ) {
889 $result[$k] = $dir .
'/' . $v;
904 $prefix = $info[
'config_prefix'] ??
'wg';
905 if ( isset( $info[
'config'] ) ) {
906 foreach ( $info[
'config'] as $key => $data ) {
907 if ( !array_key_exists(
'value', $data ) ) {
908 throw new UnexpectedValueException(
"Missing value for config $key" );
911 $value = $data[
'value'];
912 if ( isset( $data[
'path'] ) && $data[
'path'] ) {
913 if ( is_array( $value ) ) {
914 $value = $this->applyPath( $value, $dir );
916 $value =
"$dir/$value";
919 if ( isset( $data[
'merge_strategy'] ) ) {
920 $value[ExtensionRegistry::MERGE_STRATEGY] = $data[
'merge_strategy'];
922 $this->addConfigGlobal(
"$prefix$key", $value, $info[
'name'] );
923 $data[
'providedby'] = $info[
'name'];
924 if ( isset( $info[
'ConfigRegistry'][0] ) ) {
925 $data[
'configregistry'] = array_keys( $info[
'ConfigRegistry'] )[0];
938 private function addConfigGlobal( $key, $value, $extName ) {
939 if ( array_key_exists( $key, $this->globals ) ) {
940 throw new RuntimeException(
941 "The configuration setting '$key' was already set by MediaWiki core or"
942 .
" another extension, and cannot be set again by $extName." );
944 if ( isset( $value[ExtensionRegistry::MERGE_STRATEGY] ) &&
945 $value[ExtensionRegistry::MERGE_STRATEGY] ===
'array_merge_recursive' ) {
947 "Using the array_merge_recursive merge strategy in extension.json and skin.json" .
948 " was deprecated in MediaWiki 1.42",
952 $this->globals[$key] = $value;
956 foreach ( $paths as
$path ) {
957 $this->globals[$global][] =
"$dir/$path";
971 if ( !is_array( $value ) ) {
972 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
974 if ( isset( $array[$name] ) ) {
975 $array[$name] = array_merge_recursive( $array[$name], $value );
977 $array[$name] = $value;
992 if ( !is_array( $value ) ) {
993 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
995 if ( isset( $array[$name] ) ) {
996 $array[$name] = array_merge( $array[$name], $value );
998 $array[$name] = $value;
1017 $autoload = $this->autoload;
1019 if ( $includeDev ) {
1020 $autoload[
'classes'] += $this->autoloadDev[
'classes'];
1021 $autoload[
'namespaces'] += $this->autoloadDev[
'namespaces'];
1026 if ( !empty( $this->autoloadDev[
'files'] ) ) {
1029 $autoload[
'files'] = array_merge(
1031 $this->autoloadDev[
'files']
1043 private function extractAutoload( array $info,
string $dir ) {
1044 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
1045 $file =
"$dir/vendor/autoload.php";
1046 if ( file_exists( $file ) ) {
1047 $this->autoload[
'files'][] = $file;
1051 if ( isset( $info[
'AutoloadClasses'] ) ) {
1052 $paths = $this->applyPath( $info[
'AutoloadClasses'], $dir );
1053 $this->autoload[
'classes'] += $paths;
1056 if ( isset( $info[
'AutoloadNamespaces'] ) ) {
1057 $paths = $this->applyPath( $info[
'AutoloadNamespaces'], $dir );
1058 $this->autoload[
'namespaces'] += $paths;
1061 if ( isset( $info[
'TestAutoloadClasses'] ) ) {
1062 $paths = $this->applyPath( $info[
'TestAutoloadClasses'], $dir );
1063 $this->autoloadDev[
'classes'] += $paths;
1066 if ( isset( $info[
'TestAutoloadNamespaces'] ) ) {
1067 $paths = $this->applyPath( $info[
'TestAutoloadNamespaces'], $dir );
1068 $this->autoloadDev[
'namespaces'] += $paths;
1074class_alias( ExtensionProcessor::class,
'ExtensionProcessor' );
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
if(!defined('MW_SETUP_CALLBACK'))
A class containing constants representing the names of configuration variables.
const HiddenPrefs
Name constant for the HiddenPrefs setting, for use with Config::get()
const DefaultUserOptions
Name constant for the DefaultUserOptions setting, for use with Config::get()
const FeedClasses
Name constant for the FeedClasses setting, for use with Config::get()
const AvailableRights
Name constant for the AvailableRights setting, for use with Config::get()
const APIListModules
Name constant for the APIListModules setting, for use with Config::get()
const APIFormatModules
Name constant for the APIFormatModules setting, for use with Config::get()
const ImplicitGroups
Name constant for the ImplicitGroups setting, for use with Config::get()
const RemoveCredentialsBlacklist
Name constant for the RemoveCredentialsBlacklist setting, for use with Config::get()
const LogRestrictions
Name constant for the LogRestrictions setting, for use with Config::get()
const ExtensionFunctions
Name constant for the ExtensionFunctions setting, for use with Config::get()
const ActionFilteredLogs
Name constant for the ActionFilteredLogs setting, for use with Config::get()
const RevokePermissions
Name constant for the RevokePermissions setting, for use with Config::get()
const RecentChangesFlags
Name constant for the RecentChangesFlags setting, for use with Config::get()
const GroupsRemoveFromSelf
Name constant for the GroupsRemoveFromSelf setting, for use with Config::get()
const Actions
Name constant for the Actions setting, for use with Config::get()
const CentralIdLookupProviders
Name constant for the CentralIdLookupProviders setting, for use with Config::get()
const ExtensionEntryPointListFiles
Name constant for the ExtensionEntryPointListFiles setting, for use with Config::get()
const APIModules
Name constant for the APIModules setting, for use with Config::get()
const LogNames
Name constant for the LogNames setting, for use with Config::get()
const SpecialPages
Name constant for the SpecialPages setting, for use with Config::get()
const UserRegistrationProviders
Name constant for the UserRegistrationProviders setting, for use with Config::get()
const AuthManagerAutoConfig
Name constant for the AuthManagerAutoConfig setting, for use with Config::get()
const FilterLogTypes
Name constant for the FilterLogTypes setting, for use with Config::get()
const LogTypes
Name constant for the LogTypes setting, for use with Config::get()
const ResourceLoaderSources
Name constant for the ResourceLoaderSources setting, for use with Config::get()
const LogHeaders
Name constant for the LogHeaders setting, for use with Config::get()
const JobClasses
Name constant for the JobClasses setting, for use with Config::get()
const RateLimits
Name constant for the RateLimits setting, for use with Config::get()
const MediaHandlers
Name constant for the MediaHandlers setting, for use with Config::get()
const OutputPipelineStages
Name constant for the OutputPipelineStages setting, for use with Config::get()
const GrantRiskGroups
Name constant for the GrantRiskGroups setting, for use with Config::get()
const GrantPermissionGroups
Name constant for the GrantPermissionGroups setting, for use with Config::get()
const GroupPermissions
Name constant for the GroupPermissions setting, for use with Config::get()
const AddGroups
Name constant for the AddGroups setting, for use with Config::get()
const ConfigRegistry
Name constant for the ConfigRegistry setting, for use with Config::get()
const FileExtensions
Name constant for the FileExtensions setting, for use with Config::get()
const SessionProviders
Name constant for the SessionProviders setting, for use with Config::get()
const RawHtmlMessages
Name constant for the RawHtmlMessages setting, for use with Config::get()
const LogActionsHandlers
Name constant for the LogActionsHandlers setting, for use with Config::get()
const LogActions
Name constant for the LogActions setting, for use with Config::get()
const APIPropModules
Name constant for the APIPropModules setting, for use with Config::get()
const PrivilegedGroups
Name constant for the PrivilegedGroups setting, for use with Config::get()
const APIMetaModules
Name constant for the APIMetaModules setting, for use with Config::get()
const GroupsAddToSelf
Name constant for the GroupsAddToSelf setting, for use with Config::get()
const ContentHandlers
Name constant for the ContentHandlers setting, for use with Config::get()
const GrantPermissions
Name constant for the GrantPermissions setting, for use with Config::get()
const ChangeCredentialsBlacklist
Name constant for the ChangeCredentialsBlacklist setting, for use with Config::get()
const ReauthenticateTime
Name constant for the ReauthenticateTime setting, for use with Config::get()
const RemoveGroups
Name constant for the RemoveGroups setting, for use with Config::get()
const PasswordPolicy
Name constant for the PasswordPolicy setting, for use with Config::get()
const ConditionalUserOptions
Name constant for the ConditionalUserOptions setting, for use with Config::get()
const RestAPIAdditionalRouteFiles
Name constant for the RestAPIAdditionalRouteFiles setting, for use with Config::get()