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
74 protected const CORE_ATTRIBS = [
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',
146 'ResourceFileModulePaths',
147 'ResourceModuleSkinStyles',
149 'ServiceWiringFiles',
160 'wgExtensionMessagesFiles' => [],
161 'wgMessagesDirs' => [],
233 $json = file_get_contents(
$path );
234 $info = json_decode( $json,
true );
237 throw new RuntimeException(
"Failed to load JSON data from $path" );
240 if ( !isset( $info[
'manifest_version'] ) ) {
242 "{$info['name']}'s extension.json or skin.json does not have manifest_version, " .
243 'this is deprecated since MediaWiki 1.29',
246 $info[
'manifest_version'] = 1;
249 $this->
extractInfo( $path, $info, $info[
'manifest_version'] );
258 $dir = dirname(
$path );
266 if ( isset( $info[
'ServiceWiringFiles'] ) ) {
268 'wgServiceWiringFiles',
270 $info[
'ServiceWiringFiles']
273 if ( isset( $info[
'ParserTestFiles'] ) ) {
277 $info[
'ParserTestFiles']
281 if ( isset( $info[
'callback'] ) ) {
282 $this->callbacks[$name] = $info[
'callback'];
285 $this->extractAutoload( $info, $dir );
289 if ( $version >= 2 ) {
297 if ( isset( $info[
'ParsoidModules'] ) ) {
298 foreach ( $info[
'ParsoidModules'] as &$module ) {
299 if ( is_string( $module ) ) {
300 $className = $module;
302 'class' => $className,
305 $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] ) ) {
357 $this->globals[$key][ExtensionRegistry::MERGE_STRATEGY] = 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] );
385 'autoloaderClasses' =>
$autoload[
'classes'],
386 '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
473 private function setArrayHookHandler(
475 array $hookHandlersAttr,
479 if ( isset( $callback[
'handler'] ) ) {
480 $handlerName = $callback[
'handler'];
481 $handlerDefinition = $hookHandlersAttr[$handlerName] ??
false;
482 if ( !$handlerDefinition ) {
483 throw new UnexpectedValueException(
484 "Missing handler definition for $name in HookHandlers attribute in $path"
487 $callback[
'handler'] = $handlerDefinition;
488 $callback[
'extensionPath'] =
$path;
489 $this->attributes[
'Hooks'][$name][] = $callback;
491 foreach ( $callback as $callable ) {
492 if ( is_array( $callable ) ) {
493 if ( isset( $callable[
'handler'] ) ) {
494 $this->setArrayHookHandler( $callable, $hookHandlersAttr, $name,
$path );
496 $this->globals[
'wgHooks'][$name][] = $callable;
498 } elseif ( is_string( $callable ) ) {
499 $this->setStringHookHandler( $callable, $hookHandlersAttr, $name,
$path );
515 private function setStringHookHandler(
517 array $hookHandlersAttr,
521 if ( isset( $hookHandlersAttr[$callback] ) ) {
523 'handler' => $hookHandlersAttr[$callback],
524 'extensionPath' =>
$path
526 $this->attributes[
'Hooks'][$name][] = $handler;
528 $this->globals[
'wgHooks'][$name][] = $callback;
541 $extName = $info[
'name'];
542 if ( isset( $info[
'Hooks'] ) ) {
543 $hookHandlersAttr = [];
544 foreach ( $info[
'HookHandlers'] ?? [] as $name => $def ) {
545 $hookHandlersAttr[$name] = [
'name' =>
"$extName-$name" ] + $def;
547 foreach ( $info[
'Hooks'] as $name => $callback ) {
548 if ( is_string( $callback ) ) {
549 $this->setStringHookHandler( $callback, $hookHandlersAttr, $name,
$path );
550 } elseif ( is_array( $callback ) ) {
551 $this->setArrayHookHandler( $callback, $hookHandlersAttr, $name,
$path );
555 if ( isset( $info[
'DeprecatedHooks'] ) ) {
556 $deprecatedHooks = [];
557 foreach ( $info[
'DeprecatedHooks'] as $name => $deprecatedHookInfo ) {
558 $deprecatedHookInfo += [
'component' => $extName ];
559 $deprecatedHooks[$name] = $deprecatedHookInfo;
561 if ( isset( $this->attributes[
'DeprecatedHooks'] ) ) {
562 $this->attributes[
'DeprecatedHooks'] += $deprecatedHooks;
564 $this->attributes[
'DeprecatedHooks'] = $deprecatedHooks;
575 if ( isset( $info[
'namespaces'] ) ) {
576 foreach ( $info[
'namespaces'] as $ns ) {
577 if ( defined( $ns[
'constant'] ) ) {
580 $id = constant( $ns[
'constant'] );
584 $this->defines[ $ns[
'constant'] ] = $id;
586 if ( !( isset( $ns[
'conditional'] ) && $ns[
'conditional'] ) ) {
588 $this->attributes[
'ExtensionNamespaces'][$id] = $ns[
'name'];
590 if ( isset( $ns[
'movable'] ) && !$ns[
'movable'] ) {
591 $this->attributes[
'ImmovableNamespaces'][] = $id;
593 if ( isset( $ns[
'gender'] ) ) {
594 $this->globals[
'wgExtraGenderNamespaces'][$id] = $ns[
'gender'];
596 if ( isset( $ns[
'subpages'] ) && $ns[
'subpages'] ) {
597 $this->globals[
'wgNamespacesWithSubpages'][$id] =
true;
599 if ( isset( $ns[
'content'] ) && $ns[
'content'] ) {
600 $this->globals[
'wgContentNamespaces'][] = $id;
602 if ( isset( $ns[
'defaultcontentmodel'] ) ) {
603 $this->globals[
'wgNamespaceContentModels'][$id] = $ns[
'defaultcontentmodel'];
605 if ( isset( $ns[
'protection'] ) ) {
606 $this->globals[
'wgNamespaceProtection'][$id] = $ns[
'protection'];
608 if ( isset( $ns[
'capitallinkoverride'] ) ) {
609 $this->globals[
'wgCapitalLinkOverrides'][$id] = $ns[
'capitallinkoverride'];
611 if ( isset( $ns[
'includable'] ) && !$ns[
'includable'] ) {
612 $this->globals[
'wgNonincludableNamespaces'][] = $id;
619 $defaultPaths = $info[
'ResourceFileModulePaths'] ??
false;
620 if ( isset( $defaultPaths[
'localBasePath'] ) ) {
621 if ( $defaultPaths[
'localBasePath'] ===
'' ) {
623 $defaultPaths[
'localBasePath'] = $dir;
625 $defaultPaths[
'localBasePath'] =
"$dir/{$defaultPaths['localBasePath']}";
629 foreach ( [
'ResourceModules',
'ResourceModuleSkinStyles',
'OOUIThemePaths' ] as $setting ) {
630 if ( isset( $info[$setting] ) ) {
631 foreach ( $info[$setting] as $name => $data ) {
632 if ( isset( $data[
'localBasePath'] ) ) {
633 if ( $data[
'localBasePath'] ===
'' ) {
635 $data[
'localBasePath'] = $dir;
637 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
640 if ( $defaultPaths ) {
641 $data += $defaultPaths;
643 $this->attributes[$setting][$name] = $data;
648 if ( isset( $info[
'QUnitTestModule'] ) ) {
649 $data = $info[
'QUnitTestModule'];
650 if ( isset( $data[
'localBasePath'] ) ) {
651 if ( $data[
'localBasePath'] ===
'' ) {
653 $data[
'localBasePath'] = $dir;
655 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
658 $this->attributes[
'QUnitTestModules'][
"test.{$info['name']}"] = $data;
661 if ( isset( $info[
'MessagePosterModule'] ) ) {
662 $data = $info[
'MessagePosterModule'];
663 $basePath = $data[
'localBasePath'] ??
'';
664 $baseDir = $basePath ===
'' ? $dir :
"$dir/$basePath";
665 foreach ( $data[
'scripts'] ?? [] as $scripts ) {
666 $this->attributes[
'MessagePosterModule'][
'scripts'][] =
669 foreach ( $data[
'dependencies'] ?? [] as $dependency ) {
670 $this->attributes[
'MessagePosterModule'][
'dependencies'][] = $dependency;
676 if ( isset( $info[
'ExtensionMessagesFiles'] ) ) {
677 foreach ( $info[
'ExtensionMessagesFiles'] as &
$file ) {
678 $file =
"$dir/$file";
680 $this->globals[
"wgExtensionMessagesFiles"] += $info[
'ExtensionMessagesFiles'];
692 if ( isset( $info[
'MessagesDirs'] ) ) {
693 foreach ( $info[
'MessagesDirs'] as $name => $files ) {
694 foreach ( (array)$files as
$file ) {
695 $this->globals[
"wgMessagesDirs"][$name][] =
"$dir/$file";
708 if ( isset( $info[
'ValidSkinNames'] ) ) {
709 foreach ( $info[
'ValidSkinNames'] as $skinKey => $data ) {
710 if ( isset( $data[
'args'][0][
'templateDirectory'] ) ) {
711 $templateDirectory = $data[
'args'][0][
'templateDirectory'];
712 $correctedPath = $dir .
'/' . $templateDirectory;
718 if ( is_dir( $correctedPath ) ) {
719 $data[
'args'][0][
'templateDirectory'] = $correctedPath;
721 $data[
'args'][0][
'templateDirectory'] = $templateDirectory;
723 'Template directory should be relative to skin or omitted for skin ' . $skinKey,
727 } elseif ( isset( $data[
'args'][0] ) ) {
729 $data[
'args'][0][
'templateDirectory'] = $dir .
'/templates';
731 $this->globals[
'wgValidSkinNames'][$skinKey] = $data;
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." );
787 if ( isset( $info[
'config'] ) ) {
788 if ( isset( $info[
'config'][
'_prefix'] ) ) {
789 $prefix = $info[
'config'][
'_prefix'];
790 unset( $info[
'config'][
'_prefix'] );
794 foreach ( $info[
'config'] as $key => $val ) {
795 if ( $key[0] !==
'@' ) {
796 $this->addConfigGlobal(
"$prefix$key", $val, $info[
'name'] );
810 private function applyPath( array $value,
string $dir ): array {
813 foreach ( $value as $k => $v ) {
814 $result[$k] = $dir .
'/' . $v;
827 $prefix = $info[
'config_prefix'] ??
'wg';
828 if ( isset( $info[
'config'] ) ) {
829 foreach ( $info[
'config'] as $key => $data ) {
830 if ( !array_key_exists(
'value', $data ) ) {
831 throw new UnexpectedValueException(
"Missing value for config $key" );
834 $value = $data[
'value'];
835 if ( isset( $data[
'path'] ) && $data[
'path'] ) {
836 if ( is_array( $value ) ) {
837 $value = $this->applyPath( $value, $dir );
839 $value =
"$dir/$value";
842 if ( isset( $data[
'merge_strategy'] ) ) {
843 $value[ExtensionRegistry::MERGE_STRATEGY] = $data[
'merge_strategy'];
845 $this->addConfigGlobal(
"$prefix$key", $value, $info[
'name'] );
846 $data[
'providedby'] = $info[
'name'];
847 if ( isset( $info[
'ConfigRegistry'][0] ) ) {
848 $data[
'configregistry'] = array_keys( $info[
'ConfigRegistry'] )[0];
861 private function addConfigGlobal( $key, $value, $extName ) {
862 if ( array_key_exists( $key, $this->globals ) ) {
863 throw new RuntimeException(
864 "The configuration setting '$key' was already set by MediaWiki core or"
865 .
" another extension, and cannot be set again by $extName." );
867 $this->globals[$key] = $value;
871 foreach ( $paths as
$path ) {
872 $this->globals[$global][] =
"$dir/$path";
886 if ( !is_array( $value ) ) {
887 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
889 if ( isset( $array[$name] ) ) {
890 $array[$name] = array_merge_recursive( $array[$name], $value );
892 $array[$name] = $value;
906 if ( !is_array( $value ) ) {
907 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
909 if ( isset( $array[$name] ) ) {
910 $array[$name] = array_merge( $array[$name], $value );
912 $array[$name] = $value;
927 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
928 $paths[] =
"$dir/vendor/autoload.php";
948 $autoload = $this->autoload;
951 $autoload[
'classes'] += $this->autoloadDev[
'classes'];
952 $autoload[
'namespaces'] += $this->autoloadDev[
'namespaces'];
957 if ( !empty( $this->autoloadDev[
'files'] ) ) {
960 $autoload[
'files'] = array_merge(
962 $this->autoloadDev[
'files']
974 private function extractAutoload( array $info,
string $dir ) {
975 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
976 $file =
"$dir/vendor/autoload.php";
977 if ( file_exists(
$file ) ) {
978 $this->autoload[
'files'][] =
$file;
982 if ( isset( $info[
'AutoloadClasses'] ) ) {
983 $paths = $this->applyPath( $info[
'AutoloadClasses'], $dir );
984 $this->autoload[
'classes'] += $paths;
987 if ( isset( $info[
'AutoloadNamespaces'] ) ) {
988 $paths = $this->applyPath( $info[
'AutoloadNamespaces'], $dir );
989 $this->autoload[
'namespaces'] += $paths;
992 if ( isset( $info[
'TestAutoloadClasses'] ) ) {
993 $paths = $this->applyPath( $info[
'TestAutoloadClasses'], $dir );
994 $this->autoloadDev[
'classes'] += $paths;
997 if ( isset( $info[
'TestAutoloadNamespaces'] ) ) {
998 $paths = $this->applyPath( $info[
'TestAutoloadNamespaces'], $dir );
999 $this->autoloadDev[
'namespaces'] += $paths;