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::PrivilegedGroups,
57 MainConfigNames::RateLimits,
58 MainConfigNames::RawHtmlMessages,
59 MainConfigNames::ReauthenticateTime,
60 MainConfigNames::RecentChangesFlags,
61 MainConfigNames::RemoveCredentialsBlacklist,
62 MainConfigNames::RemoveGroups,
63 MainConfigNames::ResourceLoaderSources,
64 MainConfigNames::RevokePermissions,
65 MainConfigNames::SessionProviders,
66 MainConfigNames::SpecialPages,
67 MainConfigNames::UserRegistrationProviders,
75 protected const CORE_ATTRIBS = [
82 'LateJSConfigVarNames',
83 'TempUserSerialProviders',
84 'TempUserSerialMappings',
85 'DatabaseVirtualDomains',
95 protected const MERGE_STRATEGIES = [
96 'wgAuthManagerAutoConfig' =>
'array_plus_2d',
97 'wgCapitalLinkOverrides' =>
'array_plus',
98 'wgExtraGenderNamespaces' =>
'array_plus',
99 'wgGrantPermissions' =>
'array_plus_2d',
100 'wgGroupPermissions' =>
'array_plus_2d',
101 'wgHooks' =>
'array_merge_recursive',
102 'wgNamespaceContentModels' =>
'array_plus',
103 'wgNamespaceProtection' =>
'array_plus',
104 'wgNamespacesWithSubpages' =>
'array_plus',
105 'wgPasswordPolicy' =>
'array_merge_recursive',
106 'wgRateLimits' =>
'array_plus_2d',
107 'wgRevokePermissions' =>
'array_plus_2d',
115 protected const CREDIT_ATTRIBS = [
133 protected const NOT_ATTRIBS = [
137 'load_composer_autoloader',
142 'AutoloadNamespaces',
143 'ExtensionMessagesFiles',
144 'ForeignResourcesDir',
146 'MessagePosterModule',
150 'ResourceFileModulePaths',
151 'ResourceModuleSkinStyles',
153 'ServiceWiringFiles',
164 'wgExtensionMessagesFiles' => [],
165 'wgMessagesDirs' => [],
238 $json = file_get_contents(
$path );
239 $info = json_decode( $json,
true );
242 throw new RuntimeException(
"Failed to load JSON data from $path" );
245 $this->
extractInfo( $path, $info, $info[
'manifest_version'] );
254 $dir = dirname(
$path );
263 if ( isset( $info[
'ServiceWiringFiles'] ) ) {
265 'wgServiceWiringFiles',
267 $info[
'ServiceWiringFiles']
271 if ( isset( $info[
'callback'] ) ) {
272 $this->callbacks[$name] = $info[
'callback'];
275 $this->extractAutoload( $info, $dir );
279 if ( $version >= 2 ) {
287 if ( isset( $info[
'ParsoidModules'] ) ) {
288 foreach ( $info[
'ParsoidModules'] as &$module ) {
289 if ( is_string( $module ) ) {
290 $className = $module;
292 'class' => $className,
295 $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] ) ) {
349 $this->globals[$key][ExtensionRegistry::MERGE_STRATEGY] = 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'],
384 if ( !$includeDev || !isset( $info[
'dev-requires'] ) ) {
385 return $info[
'requires'] ?? [];
388 if ( !isset( $info[
'requires'] ) ) {
389 return $info[
'dev-requires'] ?? [];
399 $pick =
static function ( $a, $b ) {
402 } elseif ( $b ===
null ) {
409 $req = $info[
'requires'];
410 $dev = $info[
'dev-requires'];
411 if ( isset( $req[
'MediaWiki'] ) || isset( $dev[
'MediaWiki'] ) ) {
412 $merged[
'MediaWiki'] = $pick(
413 $req[
'MediaWiki'] ??
null,
414 $dev[
'MediaWiki'] ??
null
418 $platform = array_merge(
419 array_keys( $req[
'platform'] ?? [] ),
420 array_keys( $dev[
'platform'] ?? [] )
423 foreach ( $platform as $pkey ) {
424 if ( $pkey ===
'php' ) {
426 $req[
'platform'][
'php'] ??
null,
427 $dev[
'platform'][
'php'] ??
null
432 $value = $dev[
'platform'][$pkey] ?? $req[
'platform'][$pkey];
434 $merged[
'platform'][$pkey] = $value;
438 foreach ( [
'extensions',
'skins' ] as $thing ) {
439 $things = array_merge(
440 array_keys( $req[$thing] ?? [] ),
441 array_keys( $dev[$thing] ?? [] )
443 foreach ( $things as $name ) {
444 $merged[$thing][$name] = $pick(
445 $req[$thing][$name] ??
null,
446 $dev[$thing][$name] ??
null
464 private function setArrayHookHandler(
466 array $hookHandlersAttr,
470 if ( isset( $callback[
'handler'] ) ) {
471 $handlerName = $callback[
'handler'];
472 $handlerDefinition = $hookHandlersAttr[$handlerName] ??
false;
473 if ( !$handlerDefinition ) {
474 throw new UnexpectedValueException(
475 "Missing handler definition for $name in HookHandlers attribute in $path"
478 $callback[
'handler'] = $handlerDefinition;
479 $callback[
'extensionPath'] =
$path;
480 $this->attributes[
'Hooks'][$name][] = $callback;
482 foreach ( $callback as $callable ) {
483 if ( is_array( $callable ) ) {
484 if ( isset( $callable[
'handler'] ) ) {
485 $this->setArrayHookHandler( $callable, $hookHandlersAttr, $name,
$path );
487 $this->globals[
'wgHooks'][$name][] = $callable;
489 } elseif ( is_string( $callable ) ) {
490 $this->setStringHookHandler( $callable, $hookHandlersAttr, $name,
$path );
506 private function setStringHookHandler(
508 array $hookHandlersAttr,
512 if ( isset( $hookHandlersAttr[$callback] ) ) {
514 'handler' => $hookHandlersAttr[$callback],
515 'extensionPath' =>
$path
517 $this->attributes[
'Hooks'][$name][] = $handler;
519 $this->globals[
'wgHooks'][$name][] = $callback;
532 $extName = $info[
'name'];
533 if ( isset( $info[
'Hooks'] ) ) {
534 $hookHandlersAttr = [];
535 foreach ( $info[
'HookHandlers'] ?? [] as $name => $def ) {
536 $hookHandlersAttr[$name] = [
'name' =>
"$extName-$name" ] + $def;
538 foreach ( $info[
'Hooks'] as $name => $callback ) {
539 if ( is_string( $callback ) ) {
540 $this->setStringHookHandler( $callback, $hookHandlersAttr, $name,
$path );
541 } elseif ( is_array( $callback ) ) {
542 $this->setArrayHookHandler( $callback, $hookHandlersAttr, $name,
$path );
546 if ( isset( $info[
'DeprecatedHooks'] ) ) {
547 $deprecatedHooks = [];
548 foreach ( $info[
'DeprecatedHooks'] as $name => $deprecatedHookInfo ) {
549 $deprecatedHookInfo += [
'component' => $extName ];
550 $deprecatedHooks[$name] = $deprecatedHookInfo;
552 if ( isset( $this->attributes[
'DeprecatedHooks'] ) ) {
553 $this->attributes[
'DeprecatedHooks'] += $deprecatedHooks;
555 $this->attributes[
'DeprecatedHooks'] = $deprecatedHooks;
566 if ( isset( $info[
'namespaces'] ) ) {
567 foreach ( $info[
'namespaces'] as $ns ) {
568 if ( defined( $ns[
'constant'] ) ) {
571 $id = constant( $ns[
'constant'] );
575 $this->defines[ $ns[
'constant'] ] = $id;
577 if ( !( isset( $ns[
'conditional'] ) && $ns[
'conditional'] ) ) {
579 $this->attributes[
'ExtensionNamespaces'][$id] = $ns[
'name'];
581 if ( isset( $ns[
'movable'] ) && !$ns[
'movable'] ) {
582 $this->attributes[
'ImmovableNamespaces'][] = $id;
584 if ( isset( $ns[
'gender'] ) ) {
585 $this->globals[
'wgExtraGenderNamespaces'][$id] = $ns[
'gender'];
587 if ( isset( $ns[
'subpages'] ) && $ns[
'subpages'] ) {
588 $this->globals[
'wgNamespacesWithSubpages'][$id] =
true;
590 if ( isset( $ns[
'content'] ) && $ns[
'content'] ) {
591 $this->globals[
'wgContentNamespaces'][] = $id;
593 if ( isset( $ns[
'defaultcontentmodel'] ) ) {
594 $this->globals[
'wgNamespaceContentModels'][$id] = $ns[
'defaultcontentmodel'];
596 if ( isset( $ns[
'protection'] ) ) {
597 $this->globals[
'wgNamespaceProtection'][$id] = $ns[
'protection'];
599 if ( isset( $ns[
'capitallinkoverride'] ) ) {
600 $this->globals[
'wgCapitalLinkOverrides'][$id] = $ns[
'capitallinkoverride'];
602 if ( isset( $ns[
'includable'] ) && !$ns[
'includable'] ) {
603 $this->globals[
'wgNonincludableNamespaces'][] = $id;
610 $defaultPaths = $info[
'ResourceFileModulePaths'] ??
false;
611 if ( isset( $defaultPaths[
'localBasePath'] ) ) {
612 if ( $defaultPaths[
'localBasePath'] ===
'' ) {
614 $defaultPaths[
'localBasePath'] = $dir;
616 $defaultPaths[
'localBasePath'] =
"$dir/{$defaultPaths['localBasePath']}";
620 foreach ( [
'ResourceModules',
'ResourceModuleSkinStyles',
'OOUIThemePaths' ] as $setting ) {
621 if ( isset( $info[$setting] ) ) {
622 foreach ( $info[$setting] as $name => $data ) {
623 if ( isset( $data[
'localBasePath'] ) ) {
624 if ( $data[
'localBasePath'] ===
'' ) {
626 $data[
'localBasePath'] = $dir;
628 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
631 if ( $defaultPaths ) {
632 $data += $defaultPaths;
634 $this->attributes[$setting][$name] = $data;
639 if ( isset( $info[
'QUnitTestModule'] ) ) {
640 $data = $info[
'QUnitTestModule'];
641 if ( isset( $data[
'localBasePath'] ) ) {
642 if ( $data[
'localBasePath'] ===
'' ) {
644 $data[
'localBasePath'] = $dir;
646 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
650 $data[
'targets'] = [
'test' ];
651 $this->attributes[
'QUnitTestModules'][
"test.{$info['name']}"] = $data;
654 if ( isset( $info[
'MessagePosterModule'] ) ) {
655 $data = $info[
'MessagePosterModule'];
656 $basePath = $data[
'localBasePath'] ??
'';
657 $baseDir = $basePath ===
'' ? $dir :
"$dir/$basePath";
658 foreach ( $data[
'scripts'] ?? [] as $scripts ) {
659 $this->attributes[
'MessagePosterModule'][
'scripts'][] =
662 foreach ( $data[
'dependencies'] ?? [] as $dependency ) {
663 $this->attributes[
'MessagePosterModule'][
'dependencies'][] = $dependency;
669 if ( isset( $info[
'ExtensionMessagesFiles'] ) ) {
670 foreach ( $info[
'ExtensionMessagesFiles'] as &
$file ) {
671 $file =
"$dir/$file";
673 $this->globals[
"wgExtensionMessagesFiles"] += $info[
'ExtensionMessagesFiles'];
685 if ( isset( $info[
'MessagesDirs'] ) ) {
686 foreach ( $info[
'MessagesDirs'] as $name => $files ) {
687 foreach ( (array)$files as
$file ) {
688 $this->globals[
"wgMessagesDirs"][$name][] =
"$dir/$file";
701 if ( isset( $info[
'ValidSkinNames'] ) ) {
702 foreach ( $info[
'ValidSkinNames'] as $skinKey => $data ) {
703 if ( isset( $data[
'args'][0] ) ) {
704 $templateDirectory = $data[
'args'][0][
'templateDirectory'] ??
'templates';
705 $data[
'args'][0][
'templateDirectory'] = $dir .
'/' . $templateDirectory;
707 $this->globals[
'wgValidSkinNames'][$skinKey] = $data;
722 if ( isset( $info[
'RateLimits'] ) ) {
723 $rights = array_keys( $info[
'RateLimits'] );
725 if ( isset( $info[
'AvailableRights'] ) ) {
726 $rights = array_diff( $rights, $info[
'AvailableRights'] );
729 $this->globals[
'wgImplicitRights'] = array_merge(
730 $this->globals[
'wgImplicitRights'] ?? [],
741 if ( isset( $info[
'SkinLessImportPaths'] ) ) {
742 foreach ( $info[
'SkinLessImportPaths'] as $skin => $subpath ) {
743 $this->attributes[
'SkinLessImportPaths'][$skin] =
"$dir/$subpath";
759 foreach ( self::CREDIT_ATTRIBS as $attr ) {
760 if ( isset( $info[$attr] ) ) {
769 if ( isset( $this->credits[$name] ) ) {
770 $firstPath = $this->credits[$name][
'path'];
772 throw new Exception(
"It was attempted to load $name twice, from $firstPath and $secondPath." );
781 if ( array_key_exists(
'ForeignResourcesDir', $info ) ) {
782 if ( !is_string( $info[
'ForeignResourcesDir'] ) ) {
783 throw new Exception(
"Incorrect ForeignResourcesDir type, must be a string (in $name)" );
785 $this->attributes[
'ForeignResourcesDir'][$name] =
"{$dir}/{$info['ForeignResourcesDir']}";
796 if ( isset( $info[
'config'] ) ) {
797 if ( isset( $info[
'config'][
'_prefix'] ) ) {
798 $prefix = $info[
'config'][
'_prefix'];
799 unset( $info[
'config'][
'_prefix'] );
803 foreach ( $info[
'config'] as $key => $val ) {
804 if ( $key[0] !==
'@' ) {
805 $this->addConfigGlobal(
"$prefix$key", $val, $info[
'name'] );
819 private function applyPath( array $value,
string $dir ): array {
822 foreach ( $value as $k => $v ) {
823 $result[$k] = $dir .
'/' . $v;
836 $prefix = $info[
'config_prefix'] ??
'wg';
837 if ( isset( $info[
'config'] ) ) {
838 foreach ( $info[
'config'] as $key => $data ) {
839 if ( !array_key_exists(
'value', $data ) ) {
840 throw new UnexpectedValueException(
"Missing value for config $key" );
843 $value = $data[
'value'];
844 if ( isset( $data[
'path'] ) && $data[
'path'] ) {
845 if ( is_array( $value ) ) {
846 $value = $this->applyPath( $value, $dir );
848 $value =
"$dir/$value";
851 if ( isset( $data[
'merge_strategy'] ) ) {
852 $value[ExtensionRegistry::MERGE_STRATEGY] = $data[
'merge_strategy'];
854 $this->addConfigGlobal(
"$prefix$key", $value, $info[
'name'] );
855 $data[
'providedby'] = $info[
'name'];
856 if ( isset( $info[
'ConfigRegistry'][0] ) ) {
857 $data[
'configregistry'] = array_keys( $info[
'ConfigRegistry'] )[0];
870 private function addConfigGlobal( $key, $value, $extName ) {
871 if ( array_key_exists( $key, $this->globals ) ) {
872 throw new RuntimeException(
873 "The configuration setting '$key' was already set by MediaWiki core or"
874 .
" another extension, and cannot be set again by $extName." );
876 $this->globals[$key] = $value;
880 foreach ( $paths as
$path ) {
881 $this->globals[$global][] =
"$dir/$path";
895 if ( !is_array( $value ) ) {
896 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
898 if ( isset( $array[$name] ) ) {
899 $array[$name] = array_merge_recursive( $array[$name], $value );
901 $array[$name] = $value;
915 if ( !is_array( $value ) ) {
916 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
918 if ( isset( $array[$name] ) ) {
919 $array[$name] = array_merge( $array[$name], $value );
921 $array[$name] = $value;
936 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
937 $paths[] =
"$dir/vendor/autoload.php";
957 $autoload = $this->autoload;
960 $autoload[
'classes'] += $this->autoloadDev[
'classes'];
961 $autoload[
'namespaces'] += $this->autoloadDev[
'namespaces'];
966 if ( !empty( $this->autoloadDev[
'files'] ) ) {
969 $autoload[
'files'] = array_merge(
971 $this->autoloadDev[
'files']
983 private function extractAutoload( array $info,
string $dir ) {
984 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
985 $file =
"$dir/vendor/autoload.php";
986 if ( file_exists(
$file ) ) {
987 $this->autoload[
'files'][] =
$file;
991 if ( isset( $info[
'AutoloadClasses'] ) ) {
992 $paths = $this->applyPath( $info[
'AutoloadClasses'], $dir );
993 $this->autoload[
'classes'] += $paths;
996 if ( isset( $info[
'AutoloadNamespaces'] ) ) {
997 $paths = $this->applyPath( $info[
'AutoloadNamespaces'], $dir );
998 $this->autoload[
'namespaces'] += $paths;
1001 if ( isset( $info[
'TestAutoloadClasses'] ) ) {
1002 $paths = $this->applyPath( $info[
'TestAutoloadClasses'], $dir );
1003 $this->autoloadDev[
'classes'] += $paths;
1006 if ( isset( $info[
'TestAutoloadNamespaces'] ) ) {
1007 $paths = $this->applyPath( $info[
'TestAutoloadNamespaces'], $dir );
1008 $this->autoloadDev[
'namespaces'] += $paths;