mediawiki-extensions-Visual.../editcheck/modules/editchecks/TextMatchEditCheck.js
David Lynch 37627ad9ae EditCheck: move checks to a sidebar
Bug: T341308
Bug: T379443
Change-Id: I66147d95fc23d0f72960ff93a76b3e5ba65ce44e
2024-12-11 20:20:00 +00:00

42 lines
1.4 KiB
JavaScript

mw.editcheck.TextMatchEditCheck = function MWTextMatchEditCheck( /* config */ ) {
// Parent constructor
mw.editcheck.TextMatchEditCheck.super.apply( this, arguments );
};
OO.inheritClass( mw.editcheck.TextMatchEditCheck, mw.editcheck.BaseEditCheck );
mw.editcheck.TextMatchEditCheck.static.name = 'textMatch';
mw.editcheck.TextMatchEditCheck.static.choices = [];
mw.editcheck.TextMatchEditCheck.static.replacers = [
// TODO: Load text replacement rules from community config
{
query: 'unfortunately',
title: 'Adverb usage',
message: new OO.ui.HtmlSnippet( 'Use of adverbs such as "unfortunately" should usually be avoided so as to maintain an impartial tone. <a href="#">Read more</a>.' )
}
];
mw.editcheck.TextMatchEditCheck.prototype.onDocumentChange = function ( surfaceModel ) {
const actions = [];
this.constructor.static.replacers.forEach( ( replacer ) => {
surfaceModel.getDocument().findText( replacer.query ).forEach( ( range ) => {
const fragment = surfaceModel.getLinearFragment( range );
actions.push(
new mw.editcheck.EditCheckAction( {
fragments: [ fragment ],
title: replacer.title,
message: replacer.message,
check: this
} )
);
} );
} );
return actions;
};
// mw.editcheck.TextMatchEditCheck.prototype.onBeforeSave = mw.editcheck.TextMatchEditCheck.prototype.onDocumentChange;
mw.editcheck.editCheckFactory.register( mw.editcheck.TextMatchEditCheck );