mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-21 10:33:05 +00:00
Allow checks to be dismissed by fragment or ID
Bug: T379804 Change-Id: I8c275a560971b95e3bbcf4921633e17c0078511f
This commit is contained in:
parent
04264c6b6e
commit
a26c145574
|
@ -274,3 +274,45 @@ mw.editcheck.BaseEditCheck.prototype.isRangeInValidSection = function ( range, d
|
||||||
// If the heading text matches any of ignoreSections, return false.
|
// If the heading text matches any of ignoreSections, return false.
|
||||||
return !ignoreSections.some( ( section ) => compare( headingText, section ) === 0 );
|
return !ignoreSections.some( ( section ) => compare( headingText, section ) === 0 );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dismiss a check action
|
||||||
|
*
|
||||||
|
* @param {mw.editCheck.EditCheckAction} action
|
||||||
|
*/
|
||||||
|
mw.editcheck.BaseEditCheck.prototype.dismiss = function ( action ) {
|
||||||
|
const name = this.constructor.static.name;
|
||||||
|
if ( action.id ) {
|
||||||
|
const dismissedIds = mw.editcheck.dismissedIds;
|
||||||
|
dismissedIds[ name ] = dismissedIds[ name ] || [];
|
||||||
|
dismissedIds[ name ].push( action.id );
|
||||||
|
} else {
|
||||||
|
const dismissedFragments = mw.editcheck.dismissedFragments;
|
||||||
|
dismissedFragments[ name ] = dismissedFragments[ name ] || [];
|
||||||
|
dismissedFragments[ name ].push( ...action.fragments );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this type of check has been dismissed covering a specific range
|
||||||
|
*
|
||||||
|
* @param {ve.Range} range
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
mw.editcheck.BaseEditCheck.prototype.isDismissedRange = function ( range ) {
|
||||||
|
const fragments = mw.editcheck.dismissedFragments[ this.constructor.static.name ];
|
||||||
|
return !!fragments && fragments.some(
|
||||||
|
( fragment ) => fragment.getSelection().getCoveringRange().containsRange( range )
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an action with a given ID has been dismissed
|
||||||
|
*
|
||||||
|
* @param {string} id
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
mw.editcheck.BaseEditCheck.prototype.isDismissedId = function ( id ) {
|
||||||
|
const ids = mw.editcheck.dismissedIds[ this.constructor.static.name ];
|
||||||
|
return ids && ids.indexOf( id ) !== -1;
|
||||||
|
};
|
||||||
|
|
|
@ -11,6 +11,7 @@ mw.editcheck.EditCheckAction = function MWEditCheckAction( config ) {
|
||||||
this.check = config.check;
|
this.check = config.check;
|
||||||
this.fragments = config.fragments;
|
this.fragments = config.fragments;
|
||||||
this.message = config.message;
|
this.message = config.message;
|
||||||
|
this.id = config.id;
|
||||||
this.title = config.title;
|
this.title = config.title;
|
||||||
this.icon = config.icon;
|
this.icon = config.icon;
|
||||||
this.type = config.type || 'warning';
|
this.type = config.type || 'warning';
|
||||||
|
|
|
@ -317,12 +317,7 @@ ve.ui.EditCheckDialog.prototype.onAct = function ( widget, choice, actionChosen,
|
||||||
setTimeout( () => this.surface.getModel().setNullSelection(), 300 );
|
setTimeout( () => this.surface.getModel().setNullSelection(), 300 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !data ) {
|
if ( data && this.listener === 'onBeforeSave' ) {
|
||||||
// Nothing happened, just fall back and leave the check
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( this.listener === 'onBeforeSave' ) {
|
|
||||||
// If an action has been taken, we want to linger for a brief moment
|
// If an action has been taken, we want to linger for a brief moment
|
||||||
// to show the result of the action before moving away
|
// to show the result of the action before moving away
|
||||||
// TODO: This was written for AddReferenceEditCheck but should be
|
// TODO: This was written for AddReferenceEditCheck but should be
|
||||||
|
@ -334,6 +329,8 @@ ve.ui.EditCheckDialog.prototype.onAct = function ( widget, choice, actionChosen,
|
||||||
this.currentOffset = Math.max( 0, this.currentOffset - 1 );
|
this.currentOffset = Math.max( 0, this.currentOffset - 1 );
|
||||||
this.update();
|
this.update();
|
||||||
}, pause );
|
}, pause );
|
||||||
|
} else {
|
||||||
|
this.updateDebounced();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,14 +17,13 @@ mw.editcheck.AddReferenceEditCheck.static.defaultConfig = ve.extendObject( {}, m
|
||||||
} );
|
} );
|
||||||
|
|
||||||
mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceModel ) {
|
mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceModel ) {
|
||||||
return this.findAddedContent( surfaceModel.getDocument() ).map( ( range ) => {
|
return this.findAddedContent( surfaceModel.getDocument() ).filter( ( range ) => !this.isDismissedRange( range ) )
|
||||||
const fragment = surfaceModel.getLinearFragment( range );
|
.map(
|
||||||
return new mw.editcheck.EditCheckAction( {
|
( range ) => new mw.editcheck.EditCheckAction( {
|
||||||
fragments: [ fragment ],
|
fragments: [ surfaceModel.getLinearFragment( range ) ],
|
||||||
check: this
|
check: this
|
||||||
// icon: 'quotes',
|
} )
|
||||||
} );
|
);
|
||||||
} );
|
|
||||||
};
|
};
|
||||||
mw.editcheck.AddReferenceEditCheck.prototype.onDocumentChange = mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave;
|
mw.editcheck.AddReferenceEditCheck.prototype.onDocumentChange = mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave;
|
||||||
|
|
||||||
|
@ -100,6 +99,7 @@ mw.editcheck.AddReferenceEditCheck.prototype.act = function ( choice, action, su
|
||||||
} ).done( ( data ) => {
|
} ).done( ( data ) => {
|
||||||
if ( data && data.action === 'reject' && data.reason ) {
|
if ( data && data.action === 'reject' && data.reason ) {
|
||||||
mw.editcheck.rejections.push( data.reason );
|
mw.editcheck.rejections.push( data.reason );
|
||||||
|
this.dismiss( action );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
mw.editcheck = {
|
mw.editcheck = {
|
||||||
config: require( './config.json' ),
|
config: require( './config.json' ),
|
||||||
ecenable: !!( new URL( location.href ).searchParams.get( 'ecenable' ) || window.MWVE_FORCE_EDIT_CHECK_ENABLED )
|
ecenable: !!( new URL( location.href ).searchParams.get( 'ecenable' ) || window.MWVE_FORCE_EDIT_CHECK_ENABLED ),
|
||||||
|
dismissedFragments: {},
|
||||||
|
dismissedIds: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
require( './EditCheckContextItem.js' );
|
require( './EditCheckContextItem.js' );
|
||||||
|
|
Loading…
Reference in a new issue