Robert Vogel has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/364660 )
Change subject: Allow namespaces defined in extension.json to be overwritten
locally.
......................................................................
Allow namespaces defined in extension.json to be overwritten locally.
This allows extension namespaces to be assigned a custom ID, e.g. in case
the namespace pre-defined by the extension is already taken on the local
wiki.
This is done by defining the respective namespace constant in
LocalSettings.php.
Bug: T160462
Change-Id: If648d6e218847e6632d643ea724cd3da3945db70
(cherry picked from commit e4fc1ffec346a3b29622761362f866b1248b94bd)
---
M includes/registration/ExtensionProcessor.php
M tests/phpunit/includes/registration/ExtensionProcessorTest.php
2 files changed, 61 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/60/364660/1
diff --git a/includes/registration/ExtensionProcessor.php
b/includes/registration/ExtensionProcessor.php
index 8b942aa..bf05d86 100644
--- a/includes/registration/ExtensionProcessor.php
+++ b/includes/registration/ExtensionProcessor.php
@@ -239,8 +239,15 @@
protected function extractNamespaces( array $info ) {
if ( isset( $info['namespaces'] ) ) {
foreach ( $info['namespaces'] as $ns ) {
- $id = $ns['id'];
- $this->defines[$ns['constant']] = $id;
+ if ( defined( $ns['constant'] ) ) {
+ // If the namespace constant is already
defined, use it.
+ // This allows namespace IDs to be
overwritten locally.
+ $id = constant( $ns['constant'] );
+ } else {
+ $id = $ns['id'];
+ $this->defines[ $ns['constant'] ] = $id;
+ }
+
if ( !( isset( $ns['conditional'] ) &&
$ns['conditional'] ) ) {
// If it is not conditional, register it
$this->attributes['ExtensionNamespaces'][$id] = $ns['name'];
diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php
b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
index be7fe91..b209c9b 100644
--- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php
+++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
@@ -37,6 +37,58 @@
$this->assertArrayNotHasKey( 'AutoloadClasses', $attributes );
}
+ /**
+ * @covers ExtensionProcessor::extractInfo
+ */
+ public function testExtractInfo_namespaces() {
+ // Test that namespace IDs can be overwritten
+ if ( !defined( 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X' ) )
{
+ define( 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
123456 );
+ }
+
+ $processor = new ExtensionProcessor();
+ $processor->extractInfo( $this->dir, self::$default + [
+ 'namespaces' => [
+ [
+ 'id' => 332200,
+ 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
+ 'name' => 'Test_A',
+ 'content' => 'TestModel'
+ ],
+ [ // Test_X will use ID 123456 not 334400
+ 'id' => 334400,
+ 'constant' =>
'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
+ 'name' => 'Test_X',
+ 'content' => 'TestModel'
+ ],
+ ]
+ ], 1 );
+
+ $extracted = $processor->getExtractedInfo();
+
+ $this->assertArrayHasKey(
+ 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A',
+ $extracted['defines']
+ );
+ $this->assertArrayNotHasKey(
+ 'MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_X',
+ $extracted['defines']
+ );
+
+ $this->assertSame(
+
$extracted['defines']['MW_EXTENSION_PROCESSOR_TEST_EXTRACT_INFO_A'],
+ 332200
+ );
+
+ $this->assertArrayHasKey( 'ExtensionNamespaces',
$extracted['attributes'] );
+ $this->assertArrayHasKey( 123456,
$extracted['attributes']['ExtensionNamespaces'] );
+ $this->assertArrayHasKey( 332200,
$extracted['attributes']['ExtensionNamespaces'] );
+ $this->assertArrayNotHasKey( 334400,
$extracted['attributes']['ExtensionNamespaces'] );
+
+ $this->assertSame( 'Test_X',
$extracted['attributes']['ExtensionNamespaces'][123456] );
+ $this->assertSame( 'Test_A',
$extracted['attributes']['ExtensionNamespaces'][332200] );
+ }
+
public static function provideRegisterHooks() {
$merge = [ ExtensionRegistry::MERGE_STRATEGY =>
'array_merge_recursive' ];
// Format:
--
To view, visit https://gerrit.wikimedia.org/r/364660
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If648d6e218847e6632d643ea724cd3da3945db70
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_28
Gerrit-Owner: Robert Vogel <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits