| 1 |
mw.editcheck.TextMatchEditCheck = function MWTextMatchEditCheck( ) { |
| 2 |
|
| 3 |
mw.editcheck.TextMatchEditCheck.super.apply( this, arguments ); |
| 4 |
}; |
| 5 |
|
| 6 |
OO.inheritClass( mw.editcheck.TextMatchEditCheck, mw.editcheck.BaseEditCheck ); |
| 7 |
|
| 8 |
mw.editcheck.TextMatchEditCheck.static.name = 'textMatch'; |
| 9 |
|
| 10 |
mw.editcheck.TextMatchEditCheck.static.replacers = [ |
| 11 |
|
| 12 |
{ |
| 13 |
query: 'unfortunately', |
| 14 |
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>.' ) |
| 15 |
} |
| 16 |
]; |
| 17 |
|
| 18 |
mw.editcheck.TextMatchEditCheck.prototype.onDocumentChange = function ( surfaceModel ) { |
| 19 |
const actions = []; |
| 20 |
this.constructor.static.replacers.forEach( ( replacer ) => { |
| 21 |
surfaceModel.getDocument().findText( replacer.query ).forEach( ( range ) => { |
| 22 |
const fragment = surfaceModel.getFragment( new ve.dm.LinearSelection( range ) ); |
| 23 |
actions.push( |
| 24 |
new mw.editcheck.EditCheckAction( { |
| 25 |
highlight: fragment, |
| 26 |
selection: fragment, |
| 27 |
message: replacer.message, |
| 28 |
check: this |
| 29 |
} ) |
| 30 |
); |
| 31 |
} ); |
| 32 |
} ); |
| 33 |
return actions; |
| 34 |
}; |
| 35 |
|
| 36 |
mw.editcheck.editCheckFactory.register( mw.editcheck.TextMatchEditCheck ); |