Mailing List Archive

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ExtensionRegistry: Properly detect if a global is already set
Hoo man has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/405925 )

Change subject: ExtensionRegistry: Properly detect if a global is already set
......................................................................

ExtensionRegistry: Properly detect if a global is already set

$foo = null; isset( $foo ); will yield false.

Sometimes we want to explicitly set a config to null, but ExtensionRegistry
is then overriding this variable with the default value.

This is no consistent with the old workflow:
require_once the extension and then override the setting with null.

Bug: T128661
Change-Id: I0654c9369a596e84591fcaa9643703e6b4ccf57e
---
M includes/registration/ExtensionRegistry.php
M tests/phpunit/includes/registration/ExtensionRegistryTest.php
2 files changed, 13 insertions(+), 1 deletion(-)


git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/25/405925/1

diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php
index 6308461..ae1ab58 100644
--- a/includes/registration/ExtensionRegistry.php
+++ b/includes/registration/ExtensionRegistry.php
@@ -291,7 +291,7 @@

// Optimistic: If the global is not set, or is an empty array, replace it entirely.
// Will be O(1) performance.
- if ( !isset( $GLOBALS[$key] ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) {
+ if ( !array_key_exists( $key, $GLOBALS ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) {
$GLOBALS[$key] = $val;
continue;
}
diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
index 9b57e1c..5916b45 100644
--- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php
+++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
@@ -287,6 +287,18 @@
],
],
],
+ [.
+ 'global is null before',
+ [
+ 'NullGlobal' => null,
+ ],
+ [
+ 'NullGlobal' => 'not-null'
+ ],
+ [
+ 'NullGlobal' => null
+ ],
+ ],
];
}
}

--
To view, visit https://gerrit.wikimedia.org/r/405925
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0654c9369a596e84591fcaa9643703e6b4ccf57e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hoo man <hoo@online.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ExtensionRegistry: Properly detect if a global is already set [ In reply to ]
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/405925 )

Change subject: ExtensionRegistry: Properly detect if a global is already set
......................................................................


ExtensionRegistry: Properly detect if a global is already set

$foo = null; isset( $foo ); will yield false.

Sometimes we want to explicitly set a config to null, but ExtensionRegistry
is then overriding this variable with the default value.

This is no consistent with the old workflow:
require_once the extension and then override the setting with null.

Bug: T128661
Change-Id: I0654c9369a596e84591fcaa9643703e6b4ccf57e
---
M includes/registration/ExtensionRegistry.php
M tests/phpunit/includes/registration/ExtensionRegistryTest.php
2 files changed, 13 insertions(+), 1 deletion(-)

Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified



diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php
index 6308461..ae1ab58 100644
--- a/includes/registration/ExtensionRegistry.php
+++ b/includes/registration/ExtensionRegistry.php
@@ -291,7 +291,7 @@

// Optimistic: If the global is not set, or is an empty array, replace it entirely.
// Will be O(1) performance.
- if ( !isset( $GLOBALS[$key] ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) {
+ if ( !array_key_exists( $key, $GLOBALS ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) {
$GLOBALS[$key] = $val;
continue;
}
diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
index 9b57e1c..5916b45 100644
--- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php
+++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
@@ -287,6 +287,18 @@
],
],
],
+ [.
+ 'global is null before',
+ [
+ 'NullGlobal' => null,
+ ],
+ [
+ 'NullGlobal' => 'not-null'
+ ],
+ [
+ 'NullGlobal' => null
+ ],
+ ],
];
}
}

--
To view, visit https://gerrit.wikimedia.org/r/405925
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0654c9369a596e84591fcaa9643703e6b4ccf57e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hoo man <hoo@online.de>
Gerrit-Reviewer: Addshore <addshorewiki@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm@member.fsf.org>
Gerrit-Reviewer: Reedy <reedy@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits