From 2984539f42128e5a445aaf6857b01584c2af2041 Mon Sep 17 00:00:00 2001 From: DannyS712 Date: Wed, 6 Oct 2021 16:24:36 +0000 Subject: [PATCH] Refactor how namespaces with subpages are exposed to JavaScript Instead of using an object mapping namespace ids to if they have subpages enabled or not, pass an array of the namespaces where subpages are enabled, reducing the size of the configuration that gets loaded on all requests. Only requires a minor update to the JavaScript that uses the value (check for array index instead of object value). Bug: T291729 Change-Id: Ia0ecac71721eceed52cc90f39ecc560bdf1b7f9b --- includes/VisualEditorHooks.php | 21 ++++++++++++------- .../ve.ui.MWInternalLinkAnnotationWidget.js | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/includes/VisualEditorHooks.php b/includes/VisualEditorHooks.php index 67682a3792..1ff6bba4c7 100644 --- a/includes/VisualEditorHooks.php +++ b/includes/VisualEditorHooks.php @@ -1008,14 +1008,19 @@ 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 + // Export as a list of namespaces where subpages are enabled instead of an object + // mapping namespaces to if subpages are enabled or not, so filter out disabled + // namespaces and then just use the keys. See T291729. + $namespacesWithSubpages = array_filter( $namespacesWithSubpages ); + $namespacesWithSubpagesEnabled = array_keys( $namespacesWithSubpages ); + // $wgNamespacesWithSubpages can include namespaces that don't exist, no need + // to include those in the JavaScript data. See T291727. + // Run this filtering after the filter for subpages being enabled, to reduce + // the number of calls needed to namespace info. $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); - $namespacesWithSubpages = array_filter( - $namespacesWithSubpages, - [ $nsInfo, 'exists' ], - ARRAY_FILTER_USE_KEY + $namespacesWithSubpagesEnabled = array_filter( + $namespacesWithSubpagesEnabled, + [ $nsInfo, 'exists' ] ); $vars['wgVisualEditorConfig'] = [ 'usePageImages' => $extensionRegistry->isLoaded( 'PageImages' ), @@ -1046,7 +1051,7 @@ class VisualEditorHooks { $veConfig->get( 'VisualEditorEnableWikitextBetaFeature' ) ), 'useChangeTagging' => $veConfig->get( 'VisualEditorUseChangeTagging' ), - 'namespacesWithSubpages' => $namespacesWithSubpages, + 'namespacesWithSubpages' => $namespacesWithSubpagesEnabled, 'specialBooksources' => urldecode( SpecialPage::getTitleFor( 'Booksources' )->getPrefixedURL() ), 'rebaserUrl' => $coreConfig->get( 'VisualEditorRebaserURL' ), 'restbaseUrl' => $coreConfig->get( 'VisualEditorRestbaseURL' ), diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js index 95888a19fd..e2e3dc0908 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js @@ -112,7 +112,7 @@ ve.ui.MWInternalLinkAnnotationWidget.prototype.onTextChange = function ( value ) value = targetData.title; this.input.query.setValue( targetData.title ); } - } else if ( namespacesWithSubpages[ basePageObj.namespace ] && value[ 0 ] === '/' ) { + } else if ( namespacesWithSubpages.indexOf( basePageObj.namespace ) !== -1 && value[ 0 ] === '/' ) { // This does make it more-difficult to deliberately link to a page in the // default namespace that starts with a / when you're on a subpage-allowing // namespace. However, the exact same trick you need to know to make it work