2024-03-14 17:17:36 +00:00
|
|
|
mw.editcheck.ConvertReferenceEditCheck = function MWConvertReferenceEditCheck( /* config */ ) {
|
|
|
|
// Parent constructor
|
|
|
|
mw.editcheck.ConvertReferenceEditCheck.super.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
|
|
|
OO.inheritClass( mw.editcheck.ConvertReferenceEditCheck, mw.editcheck.BaseEditCheck );
|
|
|
|
|
|
|
|
mw.editcheck.ConvertReferenceEditCheck.static.name = 'convertReference';
|
|
|
|
|
2024-10-01 11:31:17 +00:00
|
|
|
mw.editcheck.ConvertReferenceEditCheck.prototype.onDocumentChange = function ( surfaceModel ) {
|
2024-03-14 17:17:36 +00:00
|
|
|
const seenIndexes = {};
|
2024-10-01 11:31:17 +00:00
|
|
|
const documentModel = surfaceModel.getDocument();
|
|
|
|
return documentModel.getNodesByType( 'mwReference' ).map( ( node ) => {
|
2024-03-14 17:17:36 +00:00
|
|
|
const refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( node );
|
|
|
|
const index = refModel.getListIndex();
|
|
|
|
if ( seenIndexes[ index ] ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
seenIndexes[ index ] = true;
|
2024-10-01 11:31:17 +00:00
|
|
|
const referenceNode = documentModel.getInternalList().getItemNode( index );
|
2024-03-14 17:17:36 +00:00
|
|
|
const href = ve.ui.CitoidReferenceContextItem.static.getConvertibleHref( referenceNode );
|
|
|
|
if ( href ) {
|
2024-10-30 20:28:14 +00:00
|
|
|
const fragment = surfaceModel().getLinearFragment( node.getOuterRange() );
|
2024-03-14 17:17:36 +00:00
|
|
|
return new mw.editcheck.EditCheckAction( {
|
|
|
|
highlight: fragment,
|
|
|
|
selection: fragment,
|
|
|
|
message: ve.msg( 'citoid-referencecontextitem-convert-message' ),
|
|
|
|
check: this
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} ).filter( ( obj ) => obj );
|
|
|
|
};
|
|
|
|
|
|
|
|
mw.editcheck.editCheckFactory.register( mw.editcheck.ConvertReferenceEditCheck );
|