Don't include null in the namespaces where VE can be enabled

Bug: T291728
Change-Id: I2cb168a21c559e61bf2c9e881d46f7f23110e826
This commit is contained in:
DannyS712 2021-09-25 07:30:00 +00:00
parent abd115c054
commit 492fcfbd9f
2 changed files with 4 additions and 2 deletions

View file

@ -626,7 +626,7 @@ class ApiVisualEditor extends ApiBase {
// Note: existing numeric keys might exist, and so array_merge cannot be used
(array)$config->get( 'VisualEditorAvailableNamespaces' ) +
(array)ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorAvailableNamespaces' );
return array_values( array_unique( array_map( static function ( $namespace ) {
$namespaceIds = array_values( array_unique( array_map( static function ( $namespace ) {
// Convert canonical namespace names to IDs
$nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
$idFromName = $nsInfo->getCanonicalIndex( strtolower( $namespace ) );
@ -636,6 +636,8 @@ class ApiVisualEditor extends ApiBase {
// Allow namespaces to be specified by ID as well
return $nsInfo->exists( $namespace ) ? $namespace : null;
}, array_keys( array_filter( $availableNamespaces ) ) ) ) );
// Remove `null` if there were any namespaces that didn't exist, T291728
return array_values( array_diff( $namespaceIds, [ null ] ) );
}
/**

View file

@ -48,7 +48,7 @@ class ApiVisualEditorTest extends MediaWikiIntegrationTestCase {
'Foobar' => true,
] ] );
$this->assertSame(
[ 0, -1, null, 10, 11 ],
[ 0, -1, 10, 11 ],
ApiVisualEditor::getAvailableNamespaceIds( $config )
);
}