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 'MessagePosterModule',
154 'ResourceFileModulePaths',
155 'ResourceModuleSkinStyles',
157 'ServiceWiringFiles',
168 'wgExtensionMessagesFiles' => [],
169 'wgRestAPIAdditionalRouteFiles' => [],
170 'wgMessagesDirs' => [],
171 'TranslationAliasesDirs' => [],
244 $json = file_get_contents(
$path );
245 $info = json_decode( $json,
true );
248 throw new RuntimeException(
"Failed to load JSON data from $path" );
251 $this->
extractInfo( $path, $info, $info[
'manifest_version'] );
260 $dir = dirname(
$path );
271 if ( isset( $info[
'ServiceWiringFiles'] ) ) {
273 'wgServiceWiringFiles',
275 $info[
'ServiceWiringFiles']
279 if ( isset( $info[
'callback'] ) ) {
280 $this->callbacks[$name] = $info[
'callback'];
283 $this->extractAutoload( $info, $dir );
287 if ( $version >= 2 ) {
295 if ( isset( $info[
'ParsoidModules'] ) ) {
296 foreach ( $info[
'ParsoidModules'] as &$module ) {
297 if ( is_string( $module ) ) {
298 $className = $module;
300 'class' => $className,
303 $module[
'name'] = $name;
309 if ( $version >= 2 ) {
313 foreach ( $info as $key => $val ) {
315 if ( in_array( $key, self::$globalSettings ) ) {
320 if ( $key[0] ===
'@' ) {
324 if ( $version >= 2 ) {
326 if ( in_array( $key, self::CORE_ATTRIBS ) ) {
327 $this->
storeToArray( $path, $key, $val, $this->attributes );
331 if ( !in_array( $key, self::NOT_ATTRIBS )
332 && !in_array( $key, self::CREDIT_ATTRIBS )
346 if ( isset( $info[
'attributes'] ) ) {
347 foreach ( $info[
'attributes'] as $extName => $value ) {
355 foreach ( $this->globals as $key => $val ) {
356 if ( isset( self::MERGE_STRATEGIES[$key] ) ) {
362 foreach ( $this->extAttributes as $extName => $value ) {
364 if ( isset( $this->credits[$extName] ) ) {
365 foreach ( $value as $attrName => $attrValue ) {
368 $extName . $attrName,
373 unset( $this->extAttributes[$extName] );
386 'autoloaderClasses' =>
$autoload[
'classes'],
387 'autoloaderNS' =>
$autoload[
'namespaces'],
393 if ( !$includeDev || !isset( $info[
'dev-requires'] ) ) {
394 return $info[
'requires'] ?? [];
397 if ( !isset( $info[
'requires'] ) ) {
398 return $info[
'dev-requires'] ?? [];
408 $pick =
static function ( $a, $b ) {
411 } elseif ( $b ===
null ) {
418 $req = $info[
'requires'];
419 $dev = $info[
'dev-requires'];
420 if ( isset( $req[
'MediaWiki'] ) || isset( $dev[
'MediaWiki'] ) ) {
421 $merged[
'MediaWiki'] = $pick(
422 $req[
'MediaWiki'] ??
null,
423 $dev[
'MediaWiki'] ??
null
427 $platform = array_merge(
428 array_keys( $req[
'platform'] ?? [] ),
429 array_keys( $dev[
'platform'] ?? [] )
432 foreach ( $platform as $pkey ) {
433 if ( $pkey ===
'php' ) {
435 $req[
'platform'][
'php'] ??
null,
436 $dev[
'platform'][
'php'] ??
null
441 $value = $dev[
'platform'][$pkey] ?? $req[
'platform'][$pkey];
443 $merged[
'platform'][$pkey] = $value;
447 foreach ( [
'extensions',
'skins' ] as $thing ) {
448 $things = array_merge(
449 array_keys( $req[$thing] ?? [] ),
450 array_keys( $dev[$thing] ?? [] )
452 foreach ( $things as $name ) {
453 $merged[$thing][$name] = $pick(
454 $req[$thing][$name] ??
null,
455 $dev[$thing][$name] ??
null
475 private function setArrayHookHandler(
477 array $hookHandlersAttr,
481 if ( isset( $callback[
'handler'] ) ) {
482 $handlerName = $callback[
'handler'];
483 $handlerDefinition = $hookHandlersAttr[$handlerName] ??
false;
484 if ( !$handlerDefinition ) {
485 throw new UnexpectedValueException(
486 "Missing handler definition for $name in HookHandlers attribute in $path"
489 $callback[
'handler'] = $handlerDefinition;
490 $callback[
'extensionPath'] =
$path;
491 $this->attributes[
'Hooks'][$name][] = $callback;
493 foreach ( $callback as $callable ) {
494 if ( is_array( $callable ) ) {
495 if ( isset( $callable[
'handler'] ) ) {
496 $this->setArrayHookHandler( $callable, $hookHandlersAttr, $name,
$path );
498 $this->globals[
'wgHooks'][$name][] = $callable;
500 } elseif ( is_string( $callable ) ) {
501 $this->setStringHookHandler( $callable, $hookHandlersAttr, $name,
$path );
517 private function setStringHookHandler(
519 array $hookHandlersAttr,
523 if ( isset( $hookHandlersAttr[$callback] ) ) {
525 'handler' => $hookHandlersAttr[$callback],
526 'extensionPath' =>
$path
528 $this->attributes[
'Hooks'][$name][] = $handler;
530 $this->globals[
'wgHooks'][$name][] = $callback;
543 $extName = $info[
'name'];
544 if ( isset( $info[
'Hooks'] ) ) {
545 $hookHandlersAttr = [];
546 foreach ( $info[
'HookHandlers'] ?? [] as $name => $def ) {
547 $hookHandlersAttr[$name] = [
'name' =>
"$extName-$name" ] + $def;
549 foreach ( $info[
'Hooks'] as $name => $callback ) {
550 if ( is_string( $callback ) ) {
551 $this->setStringHookHandler( $callback, $hookHandlersAttr, $name,
$path );
552 } elseif ( is_array( $callback ) ) {
553 $this->setArrayHookHandler( $callback, $hookHandlersAttr, $name,
$path );
557 if ( isset( $info[
'DeprecatedHooks'] ) ) {
558 $deprecatedHooks = [];
559 foreach ( $info[
'DeprecatedHooks'] as $name => $deprecatedHookInfo ) {
560 $deprecatedHookInfo += [
'component' => $extName ];
561 $deprecatedHooks[$name] = $deprecatedHookInfo;
563 if ( isset( $this->attributes[
'DeprecatedHooks'] ) ) {
564 $this->attributes[
'DeprecatedHooks'] += $deprecatedHooks;
566 $this->attributes[
'DeprecatedHooks'] = $deprecatedHooks;
577 if ( isset( $info[
'namespaces'] ) ) {
578 foreach ( $info[
'namespaces'] as $ns ) {
579 if ( defined( $ns[
'constant'] ) ) {
582 $id = constant( $ns[
'constant'] );
586 $this->defines[ $ns[
'constant'] ] = $id;
588 if ( !( isset( $ns[
'conditional'] ) && $ns[
'conditional'] ) ) {
590 $this->attributes[
'ExtensionNamespaces'][$id] = $ns[
'name'];
592 if ( isset( $ns[
'movable'] ) && !$ns[
'movable'] ) {
593 $this->attributes[
'ImmovableNamespaces'][] = $id;
595 if ( isset( $ns[
'gender'] ) ) {
596 $this->globals[
'wgExtraGenderNamespaces'][$id] = $ns[
'gender'];
598 if ( isset( $ns[
'subpages'] ) && $ns[
'subpages'] ) {
599 $this->globals[
'wgNamespacesWithSubpages'][$id] =
true;
601 if ( isset( $ns[
'content'] ) && $ns[
'content'] ) {
602 $this->globals[
'wgContentNamespaces'][] = $id;
604 if ( isset( $ns[
'defaultcontentmodel'] ) ) {
605 $this->globals[
'wgNamespaceContentModels'][$id] = $ns[
'defaultcontentmodel'];
607 if ( isset( $ns[
'protection'] ) ) {
608 $this->globals[
'wgNamespaceProtection'][$id] = $ns[
'protection'];
610 if ( isset( $ns[
'capitallinkoverride'] ) ) {
611 $this->globals[
'wgCapitalLinkOverrides'][$id] = $ns[
'capitallinkoverride'];
613 if ( isset( $ns[
'includable'] ) && !$ns[
'includable'] ) {
614 $this->globals[
'wgNonincludableNamespaces'][] = $id;
621 $defaultPaths = $info[
'ResourceFileModulePaths'] ??
false;
622 if ( isset( $defaultPaths[
'localBasePath'] ) ) {
623 if ( $defaultPaths[
'localBasePath'] ===
'' ) {
625 $defaultPaths[
'localBasePath'] = $dir;
627 $defaultPaths[
'localBasePath'] =
"$dir/{$defaultPaths['localBasePath']}";
631 foreach ( [
'ResourceModules',
'ResourceModuleSkinStyles',
'OOUIThemePaths' ] as $setting ) {
632 if ( isset( $info[$setting] ) ) {
633 foreach ( $info[$setting] as $name => $data ) {
634 if ( isset( $data[
'localBasePath'] ) ) {
635 if ( $data[
'localBasePath'] ===
'' ) {
637 $data[
'localBasePath'] = $dir;
639 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
642 if ( $defaultPaths ) {
643 $data += $defaultPaths;
645 $this->attributes[$setting][$name] = $data;
650 if ( isset( $info[
'QUnitTestModule'] ) ) {
651 $data = $info[
'QUnitTestModule'];
652 if ( isset( $data[
'localBasePath'] ) ) {
653 if ( $data[
'localBasePath'] ===
'' ) {
655 $data[
'localBasePath'] = $dir;
657 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
660 $this->attributes[
'QUnitTestModules'][
"test.{$info['name']}"] = $data;
663 if ( isset( $info[
'MessagePosterModule'] ) ) {
664 $data = $info[
'MessagePosterModule'];
665 $basePath = $data[
'localBasePath'] ??
'';
666 $baseDir = $basePath ===
'' ? $dir :
"$dir/$basePath";
667 foreach ( $data[
'scripts'] ?? [] as $scripts ) {
668 $this->attributes[
'MessagePosterModule'][
'scripts'][] =
671 foreach ( $data[
'dependencies'] ?? [] as $dependency ) {
672 $this->attributes[
'MessagePosterModule'][
'dependencies'][] = $dependency;
678 if ( isset( $info[
'ExtensionMessagesFiles'] ) ) {
679 foreach ( $info[
'ExtensionMessagesFiles'] as &$file ) {
680 $file =
"$dir/$file";
682 $this->globals[
"wgExtensionMessagesFiles"] += $info[
'ExtensionMessagesFiles'];
688 if ( isset( $info[
'RestModuleFiles'] ) ) {
689 foreach ( $info[
'RestModuleFiles'] as &$file ) {
690 $this->globals[
"wg$var"][] =
"$dir/$file";
703 if ( isset( $info[
'MessagesDirs'] ) ) {
704 foreach ( $info[
'MessagesDirs'] as $name => $files ) {
705 foreach ( (array)$files as $file ) {
706 $this->globals[
"wgMessagesDirs"][$name][] =
"$dir/$file";
720 foreach ( $info[
'TranslationAliasesDirs'] ?? [] as $name => $files ) {
721 foreach ( (array)$files as $file ) {
722 $this->globals[
'wgTranslationAliasesDirs'][$name][] =
"$dir/$file";
734 if ( isset( $info[
'ValidSkinNames'] ) ) {
735 foreach ( $info[
'ValidSkinNames'] as $skinKey => $data ) {
736 if ( isset( $data[
'args'][0] ) ) {
737 $templateDirectory = $data[
'args'][0][
'templateDirectory'] ??
'templates';
738 $data[
'args'][0][
'templateDirectory'] = $dir .
'/' . $templateDirectory;
740 $this->globals[
'wgValidSkinNames'][$skinKey] = $data;
755 if ( isset( $info[
'RateLimits'] ) ) {
756 $rights = array_keys( $info[
'RateLimits'] );
758 if ( isset( $info[
'AvailableRights'] ) ) {
759 $rights = array_diff( $rights, $info[
'AvailableRights'] );
762 $this->globals[
'wgImplicitRights'] = array_merge(
763 $this->globals[
'wgImplicitRights'] ?? [],
774 if ( isset( $info[
'SkinLessImportPaths'] ) ) {
775 foreach ( $info[
'SkinLessImportPaths'] as $skin => $subpath ) {
776 $this->attributes[
'SkinLessImportPaths'][$skin] =
"$dir/$subpath";
793 foreach ( self::CREDIT_ATTRIBS as $attr ) {
794 if ( isset( $info[$attr] ) ) {
803 if ( isset( $this->credits[$name] ) ) {
804 $firstPath = $this->credits[$name][
'path'];
806 throw new InvalidArgumentException(
807 "It was attempted to load $name twice, from $firstPath and $secondPath."
817 if ( array_key_exists(
'ForeignResourcesDir', $info ) ) {
818 if ( !is_string( $info[
'ForeignResourcesDir'] ) ) {
819 throw new InvalidArgumentException(
"Incorrect ForeignResourcesDir type, must be a string (in $name)" );
821 $this->attributes[
'ForeignResourcesDir'][$name] =
"{$dir}/{$info['ForeignResourcesDir']}";
833 if ( isset( $info[
'config'] ) ) {
834 if ( isset( $info[
'config'][
'_prefix'] ) ) {
835 $prefix = $info[
'config'][
'_prefix'];
836 unset( $info[
'config'][
'_prefix'] );
840 foreach ( $info[
'config'] as $key => $val ) {
841 if ( $key[0] !==
'@' ) {
842 $this->addConfigGlobal(
"$prefix$key", $val, $info[
'name'] );
856 private function applyPath( array $value,
string $dir ): array {
859 foreach ( $value as $k => $v ) {
860 $result[$k] = $dir .
'/' . $v;
875 $prefix = $info[
'config_prefix'] ??
'wg';
876 if ( isset( $info[
'config'] ) ) {
877 foreach ( $info[
'config'] as $key => $data ) {
878 if ( !array_key_exists(
'value', $data ) ) {
879 throw new UnexpectedValueException(
"Missing value for config $key" );
882 $value = $data[
'value'];
883 if ( isset( $data[
'path'] ) && $data[
'path'] ) {
884 if ( is_array( $value ) ) {
885 $value = $this->applyPath( $value, $dir );
887 $value =
"$dir/$value";
890 if ( isset( $data[
'merge_strategy'] ) ) {
891 $value[ExtensionRegistry::MERGE_STRATEGY] = $data[
'merge_strategy'];
893 $this->addConfigGlobal(
"$prefix$key", $value, $info[
'name'] );
894 $data[
'providedby'] = $info[
'name'];
895 if ( isset( $info[
'ConfigRegistry'][0] ) ) {
896 $data[
'configregistry'] = array_keys( $info[
'ConfigRegistry'] )[0];
909 private function addConfigGlobal( $key, $value, $extName ) {
910 if ( array_key_exists( $key, $this->globals ) ) {
911 throw new RuntimeException(
912 "The configuration setting '$key' was already set by MediaWiki core or"
913 .
" another extension, and cannot be set again by $extName." );
915 if ( isset( $value[ExtensionRegistry::MERGE_STRATEGY] ) &&
916 $value[ExtensionRegistry::MERGE_STRATEGY] ===
'array_merge_recursive' ) {
918 "Using the array_merge_recursive merge strategy in extension.json and skin.json" .
919 " was deprecated in MediaWiki 1.42",
923 $this->globals[$key] = $value;
927 foreach ( $paths as
$path ) {
928 $this->globals[$global][] =
"$dir/$path";
942 if ( !is_array( $value ) ) {
943 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
945 if ( isset( $array[$name] ) ) {
946 $array[$name] = array_merge_recursive( $array[$name], $value );
948 $array[$name] = $value;
963 if ( !is_array( $value ) ) {
964 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
966 if ( isset( $array[$name] ) ) {
967 $array[$name] = array_merge( $array[$name], $value );
969 $array[$name] = $value;
988 $autoload = $this->autoload;
991 $autoload[
'classes'] += $this->autoloadDev[
'classes'];
992 $autoload[
'namespaces'] += $this->autoloadDev[
'namespaces'];
997 if ( !empty( $this->autoloadDev[
'files'] ) ) {
1000 $autoload[
'files'] = array_merge(
1002 $this->autoloadDev[
'files']
1014 private function extractAutoload( array $info,
string $dir ) {
1015 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
1016 $file =
"$dir/vendor/autoload.php";
1017 if ( file_exists( $file ) ) {
1018 $this->autoload[
'files'][] = $file;
1022 if ( isset( $info[
'AutoloadClasses'] ) ) {
1023 $paths = $this->applyPath( $info[
'AutoloadClasses'], $dir );
1024 $this->autoload[
'classes'] += $paths;
1027 if ( isset( $info[
'AutoloadNamespaces'] ) ) {
1028 $paths = $this->applyPath( $info[
'AutoloadNamespaces'], $dir );
1029 $this->autoload[
'namespaces'] += $paths;
1032 if ( isset( $info[
'TestAutoloadClasses'] ) ) {
1033 $paths = $this->applyPath( $info[
'TestAutoloadClasses'], $dir );
1034 $this->autoloadDev[
'classes'] += $paths;
1037 if ( isset( $info[
'TestAutoloadNamespaces'] ) ) {
1038 $paths = $this->applyPath( $info[
'TestAutoloadNamespaces'], $dir );
1039 $this->autoloadDev[
'namespaces'] += $paths;
1045class_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()