jenkins-bot has submitted this change and it was merged. Change subject: registration: Use a static whitelist of keys that are not attributes ......................................................................
registration: Use a static whitelist of keys that are not attributes Rather than continuously creating an array of keys that were used, just hardcode a list of keys that aren't attributes. This also handles keys like "AutoloadClasses" that is handled by the registry. Bug: T98977 Change-Id: I35088a76ff4c58db71e8c9bc139fa0ccca738e3b --- M includes/registration/ExtensionProcessor.php M tests/phpunit/includes/registration/ExtensionProcessorTest.php 2 files changed, 26 insertions(+), 18 deletions(-) Approvals: Chad: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index 23a2993..bac020d 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -64,6 +64,27 @@ ); /** + * Things that are not 'attributes', but are not in + * $globalSettings or $creditsAttributes. + * + * @var array + */ + protected static $notAttributes = array( + 'callback', + 'Hooks', + 'namespaces', + 'ResourceFileModulePaths', + 'ResourceModules', + 'ResourceModuleSkinStyles', + 'ExtensionMessagesFiles', + 'MessagesDirs', + 'type', + 'config', + 'ParserTestFiles', + 'AutoloadClasses', + ); + + /** * Stuff that is going to be set to $GLOBALS * * Some keys are pre-set to arrays so we can += to them @@ -103,13 +124,6 @@ protected $attributes = array(); /** - * List of keys that have already been processed - * - * @var array - */ - protected $processed = array(); - - /** * @param string $path * @param array $info * @return array @@ -125,7 +139,6 @@ $this->extractParserTestFiles( $dir, $info ); if ( isset( $info['callback'] ) ) { $this->callbacks[] = $info['callback']; - $this->processed[] = 'callback'; } $this->extractCredits( $path, $info ); @@ -133,11 +146,12 @@ if ( in_array( $key, self::$globalSettings ) ) { $this->storeToArray( "wg$key", $val, $this->globals ); // Ignore anything that starts with a @ - } elseif ( $key[0] !== '@' && !in_array( $key, $this->processed ) ) { + } elseif ( $key[0] !== '@' && !in_array( $key, self::$notAttributes ) + && !in_array( $key, self::$creditsAttributes ) + ) { $this->storeToArray( $key, $val, $this->attributes ); } } - } public function getExtractedInfo() { @@ -157,7 +171,6 @@ $this->globals['wgHooks'][$name][] = $callback; } } - $this->processed[] = 'Hooks'; } } @@ -185,7 +198,6 @@ $this->globals['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel']; } } - $this->processed[] = 'namespaces'; } } @@ -217,7 +229,6 @@ $this->globals["wgExtensionMessagesFiles"] += array_map( function( $file ) use ( $dir ) { return "$dir/$file"; }, $info['ExtensionMessagesFiles'] ); - $this->processed[] = 'ExtensionMessagesFiles'; } } @@ -235,7 +246,6 @@ $this->globals["wgMessagesDirs"][$name][] = "$dir/$file"; } } - $this->processed[] = 'MessagesDirs'; } } @@ -244,11 +254,9 @@ 'path' => $path, 'type' => isset( $info['type'] ) ? $info['type'] : 'other', ); - $this->processed[] = 'type'; foreach ( self::$creditsAttributes as $attr ) { if ( isset( $info[$attr] ) ) { $credits[$attr] = $info[$attr]; - $this->processed[] = $attr; } } @@ -268,7 +276,6 @@ $this->globals["wg$key"] = $val; } } - $this->processed[] = 'config'; } } @@ -277,7 +284,6 @@ foreach ( $info['ParserTestFiles'] as $path ) { $this->globals['wgParserTestFiles'][] = "$dir/$path"; } - $this->processed[] = 'ParserTestFiles'; } } diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php b/tests/phpunit/includes/registration/ExtensionProcessorTest.php index d47ffa9..9474496 100644 --- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php +++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php @@ -27,12 +27,14 @@ $processor->extractInfo( $this->dir, self::$default + array( '@metadata' => array( 'foobarbaz' ), 'AnAttribute' => array( 'omg' ), + 'AutoloadClasses' => array( 'FooBar' => 'includes/FooBar.php' ), ) ); $extracted = $processor->getExtractedInfo(); $attributes = $extracted['attributes']; $this->assertArrayHasKey( 'AnAttribute', $attributes ); $this->assertArrayNotHasKey( '@metadata', $attributes ); + $this->assertArrayNotHasKey( 'AutoloadClasses', $attributes ); } public static function provideRegisterHooks() { -- To view, visit https://gerrit.wikimedia.org/r/211664 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I35088a76ff4c58db71e8c9bc139fa0ccca738e3b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits