aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/extension.schema.v1.json3
-rw-r--r--docs/extension.schema.v2.json3
-rw-r--r--includes/registration/ExtensionRegistry.php7
-rw-r--r--tests/phpunit/includes/registration/ExtensionRegistryTest.php29
4 files changed, 40 insertions, 2 deletions
diff --git a/docs/extension.schema.v1.json b/docs/extension.schema.v1.json
index c1369b42ed16..8db1291c9d5b 100644
--- a/docs/extension.schema.v1.json
+++ b/docs/extension.schema.v1.json
@@ -1033,7 +1033,8 @@
"array_replace_recursive",
"array_plus_2d",
"array_plus",
- "array_merge"
+ "array_merge",
+ "provide_default"
],
"default": "array_merge"
}
diff --git a/docs/extension.schema.v2.json b/docs/extension.schema.v2.json
index 842d509eca16..17f7b59ac3d4 100644
--- a/docs/extension.schema.v2.json
+++ b/docs/extension.schema.v2.json
@@ -1067,7 +1067,8 @@
"array_replace_recursive",
"array_plus_2d",
"array_plus",
- "array_merge"
+ "array_merge",
+ "provide_default"
],
"default": "array_merge"
},
diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php
index 000c9845ed02..5fd79242f485 100644
--- a/includes/registration/ExtensionRegistry.php
+++ b/includes/registration/ExtensionRegistry.php
@@ -470,6 +470,13 @@ class ExtensionRegistry {
$mergeStrategy = 'array_merge';
}
+ if ( $mergeStrategy === 'provide_default' ) {
+ if ( !array_key_exists( $key, $GLOBALS ) ) {
+ $GLOBALS[$key] = $val;
+ }
+ continue;
+ }
+
// Optimistic: If the global is not set, or is an empty array, replace it entirely.
// Will be O(1) performance.
if ( !array_key_exists( $key, $GLOBALS ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) {
diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
index efd7eef4770d..58064186f1bf 100644
--- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php
+++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
@@ -401,6 +401,35 @@ class ExtensionRegistryTest extends MediaWikiIntegrationTestCase {
'NullGlobal' => null
],
],
+ [
+ 'provide_default passive case',
+ [
+ 'wgFlatArray' => [],
+ ],
+ [
+ 'wgFlatArray' => [
+ 1,
+ ExtensionRegistry::MERGE_STRATEGY => 'provide_default'
+ ],
+ ],
+ [
+ 'wgFlatArray' => []
+ ],
+ ],
+ [
+ 'provide_default active case',
+ [
+ ],
+ [
+ 'wgFlatArray' => [
+ 1,
+ ExtensionRegistry::MERGE_STRATEGY => 'provide_default'
+ ],
+ ],
+ [
+ 'wgFlatArray' => [ 1 ]
+ ],
+ ]
];
}