19 'AuthManagerAutoConfig',
21 'CentralIdLookupProviders',
22 'ChangeCredentialsBlacklist',
26 'ExtensionEntryPointListFiles',
31 'GrantPermissionGroups',
35 'GroupsRemoveFromSelf',
51 'RemoveCredentialsBlacklist',
53 'ResourceLoaderSources',
65 protected const CORE_ATTRIBS = [
80 protected const MERGE_STRATEGIES = [
81 'wgAuthManagerAutoConfig' =>
'array_plus_2d',
82 'wgCapitalLinkOverrides' =>
'array_plus',
83 'wgExtraGenderNamespaces' =>
'array_plus',
84 'wgGrantPermissions' =>
'array_plus_2d',
85 'wgGroupPermissions' =>
'array_plus_2d',
86 'wgHooks' =>
'array_merge_recursive',
87 'wgNamespaceContentModels' =>
'array_plus',
88 'wgNamespaceProtection' =>
'array_plus',
89 'wgNamespacesWithSubpages' =>
'array_plus',
90 'wgPasswordPolicy' =>
'array_merge_recursive',
91 'wgRateLimits' =>
'array_plus_2d',
92 'wgRevokePermissions' =>
'array_plus_2d',
100 protected const CREDIT_ATTRIBS = [
118 protected const NOT_ATTRIBS = [
122 'load_composer_autoloader',
127 'ExtensionMessagesFiles',
129 'MessagePosterModule',
134 'ResourceFileModulePaths',
135 'ResourceModuleSkinStyles',
137 'ServiceWiringFiles',
148 'wgExtensionMessagesFiles' => [],
149 'wgMessagesDirs' => [],
199 $dir = dirname(
$path );
205 if ( isset( $info[
'ServiceWiringFiles'] ) ) {
207 'wgServiceWiringFiles',
209 $info[
'ServiceWiringFiles']
212 if ( isset( $info[
'ParserTestFiles'] ) ) {
216 $info[
'ParserTestFiles']
220 if ( isset( $info[
'callback'] ) ) {
221 $this->callbacks[$name] = $info[
'callback'];
226 if ( $version === 2 ) {
234 if ( isset( $info[
'ParsoidModules'] ) ) {
235 foreach ( $info[
'ParsoidModules'] as &$module ) {
236 if ( is_string( $module ) ) {
237 $className = $module;
239 'class' => $className,
242 $module[
'name'] = $name;
246 if ( $version === 2 ) {
250 foreach ( $info as $key => $val ) {
252 if ( in_array( $key, self::$globalSettings ) ) {
257 if ( $key[0] ===
'@' ) {
261 if ( $version === 2 ) {
263 if ( in_array( $key, self::CORE_ATTRIBS ) ) {
268 if ( !in_array( $key, self::NOT_ATTRIBS )
269 && !in_array( $key, self::CREDIT_ATTRIBS )
283 if ( isset( $info[
'attributes'] ) ) {
284 foreach ( $info[
'attributes'] as $extName => $value ) {
292 foreach ( $this->globals as $key => $val ) {
293 if ( isset( self::MERGE_STRATEGIES[$key] ) ) {
294 $this->globals[$key][ExtensionRegistry::MERGE_STRATEGY] = self::MERGE_STRATEGIES[$key];
299 foreach ( $this->extAttributes as $extName => $value ) {
301 if ( isset( $this->credits[$extName] ) ) {
302 foreach ( $value as $attrName => $attrValue ) {
305 $extName . $attrName,
310 unset( $this->extAttributes[$extName] );
326 if ( !$includeDev || !isset( $info[
'dev-requires'] ) ) {
327 return $info[
'requires'] ?? [];
330 if ( !isset( $info[
'requires'] ) ) {
331 return $info[
'dev-requires'] ?? [];
341 $pick =
function ( $a, $b ) {
344 } elseif ( $b ===
null ) {
351 $req = $info[
'requires'];
352 $dev = $info[
'dev-requires'];
353 if ( isset( $req[
'MediaWiki'] ) || isset( $dev[
'MediaWiki'] ) ) {
354 $merged[
'MediaWiki'] = $pick(
355 $req[
'MediaWiki'] ??
null,
356 $dev[
'MediaWiki'] ??
null
360 $platform = array_merge(
361 array_keys( $req[
'platform'] ?? [] ),
362 array_keys( $dev[
'platform'] ?? [] )
365 foreach ( $platform as $pkey ) {
366 if ( $pkey ===
'php' ) {
368 $req[
'platform'][
'php'] ??
null,
369 $dev[
'platform'][
'php'] ??
null
374 $value = $dev[
'platform'][$pkey] ?? $req[
'platform'][$pkey];
376 $merged[
'platform'][$pkey] = $value;
380 foreach ( [
'extensions',
'skins' ] as $thing ) {
381 $things = array_merge(
382 array_keys( $req[$thing] ?? [] ),
383 array_keys( $dev[$thing] ?? [] )
385 foreach ( $things as $name ) {
386 $merged[$thing][$name] = $pick(
387 $req[$thing][$name] ??
null,
388 $dev[$thing][$name] ??
null
408 array $hookHandlersAttr,
412 if ( isset( $callback[
'handler'] ) ) {
413 $handlerName = $callback[
'handler'];
414 $handlerDefinition = $hookHandlersAttr[$handlerName] ??
false;
415 if ( !$handlerDefinition ) {
416 throw new UnexpectedValueException(
417 "Missing handler definition for $name in HookHandlers attribute in $path"
420 $callback[
'handler'] = $handlerDefinition;
421 $callback[
'extensionPath'] =
$path;
422 $this->attributes[
'Hooks'][$name][] = $callback;
424 foreach ( $callback as $callable ) {
425 if ( is_array( $callable ) ) {
426 if ( isset( $callable[
'handler'] ) ) {
429 $this->globals[
'wgHooks'][$name][] = $callable;
431 } elseif ( is_string( $callable ) ) {
450 array $hookHandlersAttr,
454 if ( isset( $hookHandlersAttr[$callback] ) ) {
456 'handler' => $hookHandlersAttr[$callback],
457 'extensionPath' =>
$path
459 $this->attributes[
'Hooks'][$name][] = $handler;
461 $this->globals[
'wgHooks'][$name][] = $callback;
474 $extName = $info[
'name'];
475 if ( isset( $info[
'Hooks'] ) ) {
476 $hookHandlersAttr = [];
477 foreach ( $info[
'HookHandlers'] ?? [] as $name => $def ) {
478 $hookHandlersAttr[$name] = [
'name' =>
"$extName-$name" ] + $def;
480 foreach ( $info[
'Hooks'] as $name => $callback ) {
481 if ( is_string( $callback ) ) {
483 } elseif ( is_array( $callback ) ) {
488 if ( isset( $info[
'DeprecatedHooks'] ) ) {
489 $deprecatedHooks = [];
490 foreach ( $info[
'DeprecatedHooks'] as $name => $deprecatedHookInfo ) {
491 $deprecatedHookInfo += [
'component' => $extName ];
492 $deprecatedHooks[$name] = $deprecatedHookInfo;
494 if ( isset( $this->attributes[
'DeprecatedHooks'] ) ) {
495 $this->attributes[
'DeprecatedHooks'] += $deprecatedHooks;
497 $this->attributes[
'DeprecatedHooks'] = $deprecatedHooks;
508 if ( isset( $info[
'namespaces'] ) ) {
509 foreach ( $info[
'namespaces'] as $ns ) {
510 if ( defined( $ns[
'constant'] ) ) {
513 $id = constant( $ns[
'constant'] );
517 $this->defines[ $ns[
'constant'] ] = $id;
519 if ( !( isset( $ns[
'conditional'] ) && $ns[
'conditional'] ) ) {
521 $this->attributes[
'ExtensionNamespaces'][$id] = $ns[
'name'];
523 if ( isset( $ns[
'movable'] ) && !$ns[
'movable'] ) {
524 $this->attributes[
'ImmovableNamespaces'][] = $id;
526 if ( isset( $ns[
'gender'] ) ) {
527 $this->globals[
'wgExtraGenderNamespaces'][$id] = $ns[
'gender'];
529 if ( isset( $ns[
'subpages'] ) && $ns[
'subpages'] ) {
530 $this->globals[
'wgNamespacesWithSubpages'][$id] =
true;
532 if ( isset( $ns[
'content'] ) && $ns[
'content'] ) {
533 $this->globals[
'wgContentNamespaces'][] = $id;
535 if ( isset( $ns[
'defaultcontentmodel'] ) ) {
536 $this->globals[
'wgNamespaceContentModels'][$id] = $ns[
'defaultcontentmodel'];
538 if ( isset( $ns[
'protection'] ) ) {
539 $this->globals[
'wgNamespaceProtection'][$id] = $ns[
'protection'];
541 if ( isset( $ns[
'capitallinkoverride'] ) ) {
542 $this->globals[
'wgCapitalLinkOverrides'][$id] = $ns[
'capitallinkoverride'];
550 $defaultPaths = $info[
'ResourceFileModulePaths'] ??
false;
551 if ( isset( $defaultPaths[
'localBasePath'] ) ) {
552 if ( $defaultPaths[
'localBasePath'] ===
'' ) {
554 $defaultPaths[
'localBasePath'] = $dir;
556 $defaultPaths[
'localBasePath'] =
"$dir/{$defaultPaths['localBasePath']}";
560 foreach ( [
'ResourceModules',
'ResourceModuleSkinStyles',
'OOUIThemePaths' ] as $setting ) {
561 if ( isset( $info[$setting] ) ) {
562 foreach ( $info[$setting] as $name => $data ) {
563 if ( isset( $data[
'localBasePath'] ) ) {
564 if ( $data[
'localBasePath'] ===
'' ) {
566 $data[
'localBasePath'] = $dir;
568 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
571 if ( $defaultPaths ) {
572 $data += $defaultPaths;
574 $this->attributes[$setting][$name] = $data;
579 if ( isset( $info[
'QUnitTestModule'] ) ) {
580 $data = $info[
'QUnitTestModule'];
581 if ( isset( $data[
'localBasePath'] ) ) {
582 if ( $data[
'localBasePath'] ===
'' ) {
584 $data[
'localBasePath'] = $dir;
586 $data[
'localBasePath'] =
"$dir/{$data['localBasePath']}";
589 $this->attributes[
'QUnitTestModules'][
"test.{$info['name']}"] = $data;
592 if ( isset( $info[
'MessagePosterModule'] ) ) {
593 $data = $info[
'MessagePosterModule'];
594 $basePath = $data[
'localBasePath'] ??
'';
595 $baseDir =
$basePath ===
'' ? $dir :
"$dir/$basePath";
596 foreach ( $data[
'scripts'] ?? [] as $scripts ) {
597 $this->attributes[
'MessagePosterModule'][
'scripts'][] =
600 foreach ( $data[
'dependencies'] ?? [] as $dependency ) {
601 $this->attributes[
'MessagePosterModule'][
'dependencies'][] = $dependency;
607 if ( isset( $info[
'ExtensionMessagesFiles'] ) ) {
608 foreach ( $info[
'ExtensionMessagesFiles'] as &
$file ) {
609 $file =
"$dir/$file";
611 $this->globals[
"wgExtensionMessagesFiles"] += $info[
'ExtensionMessagesFiles'];
623 if ( isset( $info[
'MessagesDirs'] ) ) {
624 foreach ( $info[
'MessagesDirs'] as $name => $files ) {
625 foreach ( (array)$files as
$file ) {
626 $this->globals[
"wgMessagesDirs"][$name][] =
"$dir/$file";
643 foreach ( self::CREDIT_ATTRIBS as $attr ) {
644 if ( isset( $info[$attr] ) ) {
653 if ( isset( $this->credits[$name] ) ) {
654 $firstPath = $this->credits[$name][
'path'];
656 throw new Exception(
"It was attempted to load $name twice, from $firstPath and $secondPath." );
671 if ( isset( $info[
'config'] ) ) {
672 if ( isset( $info[
'config'][
'_prefix'] ) ) {
673 $prefix = $info[
'config'][
'_prefix'];
674 unset( $info[
'config'][
'_prefix'] );
678 foreach ( $info[
'config'] as $key => $val ) {
679 if ( $key[0] !==
'@' ) {
694 $prefix = $info[
'config_prefix'] ??
'wg';
695 if ( isset( $info[
'config'] ) ) {
696 foreach ( $info[
'config'] as $key => $data ) {
697 $value = $data[
'value'];
698 if ( isset( $data[
'path'] ) && $data[
'path'] ) {
699 $callback =
function ( $value ) use ( $dir ) {
700 return "$dir/$value";
702 if ( is_array( $value ) ) {
703 $value = array_map( $callback, $value );
705 $value = $callback( $value );
708 if ( isset( $data[
'merge_strategy'] ) ) {
709 $value[ExtensionRegistry::MERGE_STRATEGY] = $data[
'merge_strategy'];
712 $data[
'providedby'] = $info[
'name'];
713 if ( isset( $info[
'ConfigRegistry'][0] ) ) {
714 $data[
'configregistry'] = array_keys( $info[
'ConfigRegistry'] )[0];
716 $this->config[$key] = $data;
729 if ( array_key_exists( $key, $this->globals ) ) {
730 throw new RuntimeException(
731 "The configuration setting '$key' was already set by MediaWiki core or"
732 .
" another extension, and cannot be set again by $extName." );
734 $this->globals[$key] = $value;
738 foreach ( $paths as
$path ) {
739 $this->globals[$global][] =
"$dir/$path";
753 if ( !is_array( $value ) ) {
754 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
756 if ( isset( $array[$name] ) ) {
757 $array[$name] = array_merge_recursive( $array[$name], $value );
759 $array[$name] = $value;
773 if ( !is_array( $value ) ) {
774 throw new InvalidArgumentException(
"The value for '$name' should be an array (from $path)" );
776 if ( isset( $array[$name] ) ) {
777 $array[$name] = array_merge( $array[$name], $value );
779 $array[$name] = $value;
785 if ( isset( $info[
'load_composer_autoloader'] ) && $info[
'load_composer_autoloader'] ===
true ) {
786 $paths[] =
"$dir/vendor/autoload.php";
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.
addConfigGlobal( $key, $value, $extName)
Helper function to set a value to a specific global, if it isn't set already.
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.
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.
extractResourceLoaderModules( $dir, array $info)
array $extAttributes
Extension attributes, keyed by name => settings.
getExtraAutoloaderPaths( $dir, array $info)
Get the path for additional autoloaders, e.g.
extractAttributes( $path, array $info)
getRequirements(array $info, $includeDev)
Get the requirements for the provided info.
extractInfo( $path, array $info, $version)
storeToArray( $path, $name, $value, &$array)
Stores $value to $array; using array_merge() if $array already contains $name.
setStringHookHandler(string $callback, array $hookHandlersAttr, string $name, string $path)
When handler value is a string, set $wgHooks or Hooks attribute.
extractPathBasedGlobal( $global, $dir, $paths)
setArrayHookHandler(array $callback, array $hookHandlersAttr, string $name, string $path)
When handler value is an array, set $wgHooks or Hooks attribute Could be legacy hook e....
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.
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path,...
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.