Merge "Revert "Avoid creating a MWReferenceModel if not needed""

This commit is contained in:
jenkins-bot 2024-02-16 08:30:13 +00:00 committed by Gerrit Code Review
commit 5bad2b183f
3 changed files with 17 additions and 13 deletions

View file

@ -74,9 +74,10 @@ ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
* @return {jQuery|null}
*/
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
const group = this.getFragment().getDocument().getInternalList()
.getNodeGroup( this.model.getAttribute( 'listGroup' ) );
const nodes = ve.getProp( group, 'keyedNodes', this.model.getAttribute( 'listKey' ) );
.getNodeGroup( refModel.getListGroup() );
const nodes = ve.getProp( group, 'keyedNodes', refModel.getListKey() );
const usages = nodes && nodes.filter( function ( node ) {
return !node.findParent( ve.dm.MWReferencesListNode );
} ).length;
@ -94,7 +95,9 @@ ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
* @return {jQuery|null}
*/
ve.ui.MWReferenceContextItem.prototype.getExtendsWarning = function () {
if ( this.model.getAttribute( 'extendsRef' ) ) {
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
if ( refModel.extendsRef ) {
return $( '<div>' )
.addClass( 've-ui-mwReferenceContextItem-muted' )
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) );
@ -111,8 +114,9 @@ ve.ui.MWReferenceContextItem.prototype.getReferenceNode = function () {
return null;
}
if ( !this.referenceNode ) {
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
this.referenceNode = this.getFragment().getDocument().getInternalList()
.getItemNode( this.model.getAttribute( 'listIndex' ) );
.getItemNode( refModel.getListIndex() );
}
return this.referenceNode;
};
@ -131,12 +135,12 @@ ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
* @return {string|null}
*/
ve.ui.MWReferenceContextItem.prototype.getParentRef = function () {
const extendsRef = this.model.getAttribute( 'extendsRef' );
if ( !extendsRef ) {
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
if ( !refModel.extendsRef ) {
return null;
}
const list = this.getFragment().getDocument().getInternalList();
const index = list.keys.indexOf( 'literal/' + extendsRef );
const index = list.keys.indexOf( 'literal/' + refModel.extendsRef );
return list.getItemNode( index ).element.attributes.originalHtml;
};

View file

@ -197,7 +197,7 @@ ve.ui.MWReferenceDialog.prototype.onReferenceGroupInputChange = function () {
* @param {ve.ui.MWReferenceResultWidget} item Chosen item
*/
ve.ui.MWReferenceDialog.prototype.onSearchResultsChoose = function ( item ) {
const ref = ve.dm.MWReferenceModel.static.newFromReferenceNode( item.getData() );
const ref = item.getData();
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
this.getFragment().removeContent();

View file

@ -138,13 +138,13 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
}
// Only increment counter for real references
n++;
const itemNode = this.internalList.getItemNode( refNode.getAttribute( 'listIndex' ) );
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode );
const itemNode = this.internalList.getItemNode( refModel.getListIndex() );
const refGroup = refNode.getAttribute( 'refGroup' );
const refGroup = refModel.getGroup();
const citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n;
// Use [\s\S]* instead of .* to catch esoteric whitespace (T263698)
// TODO: pass through mw-data name instead
const matches = refNode.getAttribute( 'listKey' ).match( /^literal\/([\s\S]*)$/ );
const matches = refModel.getListKey().match( /^literal\/([\s\S]*)$/ );
const name = matches && matches[ 1 ] || '';
// TODO: At some point we need to make sure this text is updated in
@ -172,7 +172,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
this.index.push( {
$element: $element,
text: text,
reference: refNode,
reference: refModel,
citation: citation,
name: name
} );