Avoid creating a MWReferenceModel if not needed

It's fine to copy attributes directly from the reference node rather
than go through the specialized model object.

Bug: T336417
Change-Id: Idaca192137dc762ddced2ee8446a7d838f97e317
This commit is contained in:
Adam Wight 2024-02-06 17:26:46 +01:00
parent df2a713934
commit 74f66bc478
3 changed files with 13 additions and 17 deletions

View file

@ -74,10 +74,9 @@ 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( refModel.getListGroup() );
const nodes = ve.getProp( group, 'keyedNodes', refModel.getListKey() );
.getNodeGroup( this.model.getAttribute( 'listGroup' ) );
const nodes = ve.getProp( group, 'keyedNodes', this.model.getAttribute( 'listKey' ) );
const usages = nodes && nodes.filter( function ( node ) {
return !node.findParent( ve.dm.MWReferencesListNode );
} ).length;
@ -95,9 +94,7 @@ ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
* @return {jQuery|null}
*/
ve.ui.MWReferenceContextItem.prototype.getExtendsWarning = function () {
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
if ( refModel.extendsRef ) {
if ( this.model.getAttribute( 'extendsRef' ) ) {
return $( '<div>' )
.addClass( 've-ui-mwReferenceContextItem-muted' )
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) );
@ -114,9 +111,8 @@ 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( refModel.getListIndex() );
.getItemNode( this.model.getAttribute( 'listIndex' ) );
}
return this.referenceNode;
};
@ -135,12 +131,12 @@ ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
* @return {string|null}
*/
ve.ui.MWReferenceContextItem.prototype.getParentRef = function () {
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
if ( !refModel.extendsRef ) {
const extendsRef = this.model.getAttribute( 'extendsRef' );
if ( !extendsRef ) {
return null;
}
const list = this.getFragment().getDocument().getInternalList();
const index = list.keys.indexOf( 'literal/' + refModel.extendsRef );
const index = list.keys.indexOf( 'literal/' + 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 = item.getData();
const ref = ve.dm.MWReferenceModel.static.newFromReferenceNode( 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 refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode );
const itemNode = this.internalList.getItemNode( refModel.getListIndex() );
const itemNode = this.internalList.getItemNode( refNode.getAttribute( 'listIndex' ) );
const refGroup = refModel.getGroup();
const refGroup = refNode.getAttribute( 'refGroup' );
const citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n;
// Use [\s\S]* instead of .* to catch esoteric whitespace (T263698)
const matches = refModel.getListKey().match( /^literal\/([\s\S]*)$/ );
// TODO: pass through mw-data name instead
const matches = refNode.getAttribute( 'listKey' ).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: refModel,
reference: refNode,
citation: citation,
name: name
} );