From a62e8556972dc7f7bfd428bd1150d1259ed3cf33 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Thu, 18 Jul 2024 09:07:55 +0200 Subject: [PATCH] Disallow recursively extending already extended references Note that the duplicated search panel is most probably a temporary solution anyway. We probably want a single search panel that can do both kinds of "reuse with/without different details". This is also inconsequential for production. Nothing related to extended references is currently visible on production. Added to the otherwise unrelated T369005 for code review purposes. Bug: T369005 Change-Id: Iedee38dacc01ae59fb1a681e49e655ca91b25b64 --- modules/ve-cite/ve.ui.MWReferenceSearchWidget.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js b/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js index 2300fcb64..b015aa74c 100644 --- a/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js +++ b/modules/ve-cite/ve.ui.MWReferenceSearchWidget.js @@ -48,6 +48,7 @@ ve.ui.MWReferenceSearchWidget.static.isIndexEmpty = function ( internalList ) { // Doing this live every time is cheap because it stops on the first non-empty group for ( const groupName in groups ) { if ( groupName.indexOf( 'mwReference/' ) === 0 && groups[ groupName ].indexOrder.length ) { + // No need to filter subrefs here, as it's impossible to have subrefs without parents return false; } } @@ -143,6 +144,10 @@ ve.ui.MWReferenceSearchWidget.prototype.buildSearchIndex = function () { const index = []; const groupNames = Object.keys( groups ).sort(); + // FIXME: Temporary hack, to be removed soon + // eslint-disable-next-line no-jquery/no-class-state + const filterExtends = this.$element.hasClass( 've-ui-citoidInspector-extends' ); + for ( let i = 0; i < groupNames.length; i++ ) { const groupName = groupNames[ i ]; if ( groupName.indexOf( 'mwReference/' ) !== 0 ) { @@ -159,6 +164,10 @@ ve.ui.MWReferenceSearchWidget.prototype.buildSearchIndex = function () { if ( !refNode || refNode.getAttribute( 'placeholder' ) ) { continue; } + // FIXME: This might miss subrefs that are reused without repeating the extends attribute + if ( filterExtends && refNode.getAttribute( 'extendsRef' ) ) { + continue; + } // Only increment counter for real references n++; const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode );