mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
[refactor] New interface in MWReferenceContextItem
Switch to MWGroupReferences interface. Change-Id: If6b0ee307ea8d44de8859953135be6e06f3e19e3
This commit is contained in:
parent
35e8af7d40
commit
8c08491752
|
@ -72,15 +72,14 @@ ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
|
||||||
* @return {jQuery|undefined}
|
* @return {jQuery|undefined}
|
||||||
*/
|
*/
|
||||||
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
||||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
const usageCount = ve.dm.MWDocumentReferences.static.refsForDoc( this.getFragment().getDocument() )
|
||||||
const group = this.getFragment().getDocument().getInternalList()
|
.getGroupRefs( this.model.getAttribute( 'listGroup' ) )
|
||||||
.getNodeGroup( refModel.getListGroup() );
|
.getRefUsages( this.model.getAttribute( 'listKey' ) )
|
||||||
const nodes = ve.getProp( group, 'keyedNodes', refModel.getListKey() );
|
.length;
|
||||||
const usages = nodes && nodes.filter( ( node ) => !node.findParent( ve.dm.MWReferencesListNode ) ).length;
|
if ( usageCount > 1 ) {
|
||||||
if ( usages > 1 ) {
|
|
||||||
return $( '<div>' )
|
return $( '<div>' )
|
||||||
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
||||||
.text( mw.msg( 'cite-ve-dialog-reference-editing-reused', usages ) );
|
.text( mw.msg( 'cite-ve-dialog-reference-editing-reused', usageCount ) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,9 +107,9 @@ ve.ui.MWReferenceContextItem.prototype.getReferenceNode = function () {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( !this.referenceNode ) {
|
if ( !this.referenceNode ) {
|
||||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
this.referenceNode = ve.dm.MWDocumentReferences.static.refsForDoc( this.getFragment().getDocument() )
|
||||||
this.referenceNode = this.getFragment().getDocument().getInternalList()
|
.getGroupRefs( this.model.getAttribute( 'listGroup' ) )
|
||||||
.getItemNode( refModel.getListIndex() );
|
.getInternalModelNode( this.model.getAttribute( 'listKey' ) );
|
||||||
}
|
}
|
||||||
return this.referenceNode;
|
return this.referenceNode;
|
||||||
};
|
};
|
||||||
|
@ -133,9 +132,10 @@ ve.ui.MWReferenceContextItem.prototype.getParentRef = function () {
|
||||||
if ( !extendsRef ) {
|
if ( !extendsRef ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const list = this.getFragment().getDocument().getInternalList();
|
const parentNode = ve.dm.MWDocumentReferences.static.refsForDoc( this.getFragment().getDocument() )
|
||||||
const itemNode = list.getItemNode( list.keys.indexOf( extendsRef ) );
|
.getGroupRefs( this.model.getAttribute( 'listGroup' ) )
|
||||||
return itemNode ? new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element :
|
.getInternalModelNode( extendsRef );
|
||||||
|
return parentNode ? new ve.ui.MWPreviewElement( parentNode, { useView: true } ).$element :
|
||||||
$( '<div>' )
|
$( '<div>' )
|
||||||
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
||||||
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) );
|
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) );
|
||||||
|
|
Loading…
Reference in a new issue