Rationale
We want to write a general TextReplacementEditCheck base class, upon which it will be easy to write many checks that are domain-specific and wiki-specific.
We wrote the BritishEditCheck quick hack as a learning example. We hypothesize we could build a library of similarly useful replacement checks in specific domains, based on knowledge from domain experts in the community.
Goals:
- Make replacement checks quick and simple to code
- Yet don't compromise maintainability
- Don't require deep VE internals knowledge (like the BritishEditCheck quick hack did)
- Allow highly specific replacement checks that only apply to certain pages
- (Later, not in this task) Support surfacing these checks as edit suggestions (e.g. as curated tasks for new users to improve already-published text).
Functional specification
BritishEditCheck shall inherit from TextReplacementEditCheck (a brand new class).
BritishEditCheck shall have three methods (each overriding one set to null in the base class):
- .shouldCheckPage — so the check can specify whether it wants to check the page. It shall take a string list of categories that apply to the page, and it shall return True iff the page should be checked. (We want the page to be checked if it has a category whose title starts "Use British English").
- .pattern — so the check can specify what text to find. It shall take no arguments, and return a (constant) RegExp object suitable for passing into ve.dm.Document#findText (i.e. it must have the /g flag), that matches any text that should be highlighted as problematic. (We want to match US-only spellings like "humor", but not match GB-only or GB+US spellings like "humoresque").
- .getReplacement — so the check can suggest a replacement for any text found. It shall take matched text and return a replacement. (So calling .getReplacement( 'humor' ) should return 'humour').
No other logic shall be required in BritishEditCheck – it shall be just these three methods and a little boilerplate code. The remainder of the logic shall live in the TextReplacementEditCheck base class.