2024-03-14 17:17:36 +00:00
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 . replacers = [
// TODO: Load text replacement rules from community config
{
query : 'unfortunately' ,
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>.' )
}
] ;
2024-10-01 11:31:17 +00:00
mw . editcheck . TextMatchEditCheck . prototype . onDocumentChange = function ( surfaceModel ) {
2024-03-14 17:17:36 +00:00
const actions = [ ] ;
this . constructor . static . replacers . forEach ( ( replacer ) => {
2024-10-01 11:31:17 +00:00
surfaceModel . getDocument ( ) . findText ( replacer . query ) . forEach ( ( range ) => {
2024-10-30 20:28:14 +00:00
const fragment = surfaceModel . getLinearFragment ( range ) ;
2024-03-14 17:17:36 +00:00
actions . push (
new mw . editcheck . EditCheckAction ( {
2024-12-05 12:10:28 +00:00
fragments : [ fragment ] ,
2024-03-14 17:17:36 +00:00
message : replacer . message ,
check : this
} )
) ;
} ) ;
} ) ;
return actions ;
} ;
mw . editcheck . editCheckFactory . register ( mw . editcheck . TextMatchEditCheck ) ;