Filter JavaScript namespacesWithSubpages to only existing namespaces

$wgNamespacesWithSubpages can include namespaces that
don't exist, no need to add them to the JavaScript configuration.

Bug: T291727
Change-Id: I1f4f3d2c2accb3d84f83262480616d05115f406c
This commit is contained in:
DannyS712 2021-09-29 20:36:53 +00:00
parent 492fcfbd9f
commit 267daeb6c6

View file

@ -1007,6 +1007,16 @@ class VisualEditorHooks {
)
);
$namespacesWithSubpages = $coreConfig->get( 'NamespacesWithSubpages' );
// $namespacesWithSubpages is a map of namespace id to boolean value, we want
// to filter out namespaces that don't exist, not need to include those and it
// would increase the JavaScript config size. See T291727
$nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
$namespacesWithSubpages = array_filter(
$namespacesWithSubpages,
[ $nsInfo, 'exists' ],
ARRAY_FILTER_USE_KEY
);
$vars['wgVisualEditorConfig'] = [
'usePageImages' => $extensionRegistry->isLoaded( 'PageImages' ),
'usePageDescriptions' => $extensionRegistry->isLoaded( 'WikibaseClient' ),
@ -1036,7 +1046,7 @@ class VisualEditorHooks {
$veConfig->get( 'VisualEditorEnableWikitextBetaFeature' )
),
'useChangeTagging' => $veConfig->get( 'VisualEditorUseChangeTagging' ),
'namespacesWithSubpages' => $coreConfig->get( 'NamespacesWithSubpages' ),
'namespacesWithSubpages' => $namespacesWithSubpages,
'specialBooksources' => urldecode( SpecialPage::getTitleFor( 'Booksources' )->getPrefixedURL() ),
'rebaserUrl' => $coreConfig->get( 'VisualEditorRebaserURL' ),
'restbaseUrl' => $coreConfig->get( 'VisualEditorRestbaseURL' ),