mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Merge "Avoid creating a MWReferenceModel if not needed"
This commit is contained in:
commit
47b552f504
|
@ -74,10 +74,9 @@ ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
|
||||||
* @return {jQuery|null}
|
* @return {jQuery|null}
|
||||||
*/
|
*/
|
||||||
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
||||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
|
||||||
const group = this.getFragment().getDocument().getInternalList()
|
const group = this.getFragment().getDocument().getInternalList()
|
||||||
.getNodeGroup( refModel.getListGroup() );
|
.getNodeGroup( this.model.getAttribute( 'listGroup' ) );
|
||||||
const nodes = ve.getProp( group, 'keyedNodes', refModel.getListKey() );
|
const nodes = ve.getProp( group, 'keyedNodes', this.model.getAttribute( 'listKey' ) );
|
||||||
const usages = nodes && nodes.filter( function ( node ) {
|
const usages = nodes && nodes.filter( function ( node ) {
|
||||||
return !node.findParent( ve.dm.MWReferencesListNode );
|
return !node.findParent( ve.dm.MWReferencesListNode );
|
||||||
} ).length;
|
} ).length;
|
||||||
|
@ -95,9 +94,7 @@ ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
||||||
* @return {jQuery|null}
|
* @return {jQuery|null}
|
||||||
*/
|
*/
|
||||||
ve.ui.MWReferenceContextItem.prototype.getExtendsWarning = function () {
|
ve.ui.MWReferenceContextItem.prototype.getExtendsWarning = function () {
|
||||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
if ( this.model.getAttribute( 'extendsRef' ) ) {
|
||||||
|
|
||||||
if ( refModel.extendsRef ) {
|
|
||||||
return $( '<div>' )
|
return $( '<div>' )
|
||||||
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
||||||
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) );
|
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) );
|
||||||
|
@ -114,9 +111,8 @@ 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 = this.getFragment().getDocument().getInternalList()
|
this.referenceNode = this.getFragment().getDocument().getInternalList()
|
||||||
.getItemNode( refModel.getListIndex() );
|
.getItemNode( this.model.getAttribute( 'listIndex' ) );
|
||||||
}
|
}
|
||||||
return this.referenceNode;
|
return this.referenceNode;
|
||||||
};
|
};
|
||||||
|
@ -135,12 +131,12 @@ ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
|
||||||
* @return {string|null}
|
* @return {string|null}
|
||||||
*/
|
*/
|
||||||
ve.ui.MWReferenceContextItem.prototype.getParentRef = function () {
|
ve.ui.MWReferenceContextItem.prototype.getParentRef = function () {
|
||||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
const extendsRef = this.model.getAttribute( 'extendsRef' );
|
||||||
if ( !refModel.extendsRef ) {
|
if ( !extendsRef ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const list = this.getFragment().getDocument().getInternalList();
|
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;
|
return list.getItemNode( index ).element.attributes.originalHtml;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ ve.ui.MWReferenceDialog.prototype.onReferenceGroupInputChange = function () {
|
||||||
* @param {ve.ui.MWReferenceResultWidget} item Chosen item
|
* @param {ve.ui.MWReferenceResultWidget} item Chosen item
|
||||||
*/
|
*/
|
||||||
ve.ui.MWReferenceDialog.prototype.onSearchResultsChoose = function ( 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 ) {
|
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
||||||
this.getFragment().removeContent();
|
this.getFragment().removeContent();
|
||||||
|
|
|
@ -138,13 +138,13 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
|
||||||
}
|
}
|
||||||
// Only increment counter for real references
|
// Only increment counter for real references
|
||||||
n++;
|
n++;
|
||||||
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( refNode );
|
const itemNode = this.internalList.getItemNode( refNode.getAttribute( 'listIndex' ) );
|
||||||
const itemNode = this.internalList.getItemNode( refModel.getListIndex() );
|
|
||||||
|
|
||||||
const refGroup = refModel.getGroup();
|
const refGroup = refNode.getAttribute( 'refGroup' );
|
||||||
const citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n;
|
const citation = ( refGroup && refGroup.length ? refGroup + ' ' : '' ) + n;
|
||||||
// Use [\s\S]* instead of .* to catch esoteric whitespace (T263698)
|
// 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 ] || '';
|
const name = matches && matches[ 1 ] || '';
|
||||||
|
|
||||||
// TODO: At some point we need to make sure this text is updated in
|
// 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( {
|
this.index.push( {
|
||||||
$element: $element,
|
$element: $element,
|
||||||
text: text,
|
text: text,
|
||||||
reference: refModel,
|
reference: refNode,
|
||||||
citation: citation,
|
citation: citation,
|
||||||
name: name
|
name: name
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in a new issue