Extends
Constructor
new mw.editcheck.TextMatchEditCheck(controller, [config], [includeSuggestions])
#
Edit check to detect generic text matches/replacements
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
controller |
||||
config |
Object |
optional |
||
includeSuggestions |
boolean |
optional |
false |
Properties
onBeforeSaveabstract
#
Get actions to show before save
onBranchNodeChangeabstract
#
Get actions to show when the focused branch node changed
- Inherited from:
- Source:
onDocumentChangeabstract
#
Get actions to show when document changed
defaultConfigstatic
#
The configs of TextMatchEditCheck take priority over individual matchRule configs. So we make TextMatch’s defaults nonrestrictive, and let the finer limitations be handled by individual matchRules.
languageFallbacks :Objectstatic
#
Map of known languages that might be in wgContentLanguage but aren't valid for Intl.Collator
Type:
matchCache :Objectstatic
#
Cache containing fully processed matchRules will all imports, as well as any TextFinders created for them
Type:
Cache containing fully processed matchRules will all imports, as well as any TextFinders created for them
matchRules :Objectstatic
#
Object into which default matchRule configs can be placed
This is largely a place for scripts to interact with the check
Type:
Object into which default matchRule configs can be placed
This is largely a place for scripts to interact with the check
matchRulesPromise :Promise.<Object>static
#
Promise which holds the loading and processing of matchRules
Type:
Methods
act(choice, action, surface) → {jQuery.Promise|undefined}abstract
#
undefined}abstract
#
User performs an action on an check
Parameters:
| Name | Type | Description |
|---|---|---|
choice |
string |
|
action |
mw.editcheck.EditCheckAction | |
surface |
ve.ui.Surface |
Returns:
Promise which resolves when action is complete, or undefined if there's nothing to wait on
- Type
-
jQuery.Promise
|
undefined
- Overrides:
- Source:
buildAction(matchRule, fragment, term, tagName, [replacementConfig]) → {mw.editcheck.TextMatchEditCheckAction}
#
Build a TextMatchEditCheckAction
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
matchRule |
mw.editcheck.TextMatchEditCheck | ||||||||||||||||||
fragment |
ve.dm.LinearFragment | Fragment that the match covers, after optional expansion |
|||||||||||||||||
term |
string | Individual term that triggered the match, before optional expansion |
|||||||||||||||||
tagName |
string | Unique tag name for this matchRule+term pair |
|||||||||||||||||
replacementConfig |
Object |
optional |
Configuration for the replacement Properties:
|
Returns:
canBeShown([documentModel], [suggestion]) → {boolean}
#
Find out whether the check should be applied
This is a general check for its applicability to the viewer / page, rather than a specific check based on the current edit. It's used to filter out checks before any maybe-expensive content analysis happens.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
documentModel |
ve.dm.Document |
optional |
if attached to a known document |
|
suggestion |
boolean |
optional |
false | Whether we are checking for suggestion mode |
Returns:
Whether the check should be shown
- Type
- boolean
- Inherited from:
- Source:
Find out whether the check should be applied
This is a general check for its applicability to the viewer / page, rather than a specific check based on the current edit.
canBeStale() → {boolean}
#
Check if the edit check can be stale
Returns:
- Type
- boolean
- Inherited from:
- Source:
dismiss(action)
#
Dismiss a check action
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editCheck.EditCheckAction |
- Inherited from:
- Source:
getAddedContentRanges(documentModel) → {Array.<ve.Range>}
#
Get content ranges where at least the minimum about of text has been added
Parameters:
| Name | Type | Description |
|---|---|---|
documentModel |
ve.dm.Document |
Returns:
- Inherited from:
- Source:
getAddedNodes(documentModel, [type]) → {Array.<ve.dm.Node>}
#
Find nodes that were added during the edit session
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
documentModel |
ve.dm.Document | ||
type |
string | function |
optional |
Node type name or node constructor to find, or all nodes if false |
Returns:
- Type
- Array.<ve.dm.Node>
- Inherited from:
- Source:
getAddedRanges(documentModel, coveredNodesOnly, onlyContentRanges) → {Array.<ve.Range>}
#
Get content ranges which have been inserted
Parameters:
| Name | Type | Description |
|---|---|---|
documentModel |
ve.dm.Document | |
coveredNodesOnly |
boolean | Only include ranges which cover the whole of their node |
onlyContentRanges |
boolean | Only return ranges which are content branch node interiors |
Returns:
- Inherited from:
- Source:
getContentRangesFromRange(documentModel, range, covers) → {Array.<ve.Range>}
#
Return the content ranges (content branch node interiors) contained within a range
For a content branch node entirely contained within the range, its entire interior range will be included. For a content branch node overlapping with the range boundary, only the covered part of its interior range will be included.
Parameters:
| Name | Type | Description |
|---|---|---|
documentModel |
ve.dm.Document | The documentModel to search |
range |
ve.Range | The range to include |
covers |
boolean | Only include ranges which cover the whole of their node |
Returns:
The contained content ranges (content branch node interiors)
- Inherited from:
- Source:
Return the content ranges (content branch node interiors) contained within a range
For a content branch node entirely contained within the range, its entire interior range will be included.
getDescription(action) → {jQuery|string|function|OO.ui.HtmlSnippet}
#
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction |
Returns:
- Type
- jQuery | string | function | OO.ui.HtmlSnippet
- Inherited from:
- Source:
getHeadingHierarchyFromOffset(offset, documentModel) → {Array.<ve.dm.MWHeadingNode>}
#
Get the heading hierarchy at a given range
Parameters:
| Name | Type | Description |
|---|---|---|
offset |
number | |
documentModel |
ve.dm.Document |
Returns:
Heading nodes from nearest to furthest
- Type
- Array.<ve.dm.MWHeadingNode>
getModifiedAnnotationRanges(documentModel, [names], [scopeNode]) → {Array.<ve.dm.LinearData.AnnotationRange>}
#
Get annotation ranges where at least some content has been modified
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
documentModel |
ve.dm.Document | ||
names |
Array.<string> |
optional |
Names of annotations to filter for |
scopeNode |
ve.dm.ContentBranchNode |
optional |
Node to check within |
Returns:
Annotation ranges, containing an annotation and its range
- Inherited from:
- Source:
getModifiedContentBranchNodes(documentModel) → {Array.<ve.dm.ContentBranchNode>}
#
Get ContentBranchNodes where some text has been changed
Parameters:
| Name | Type | Description |
|---|---|---|
documentModel |
ve.dm.Document |
Returns:
- Type
- Array.<ve.dm.ContentBranchNode>
getModifiedContentRanges(documentModel) → {Array.<ve.Range>}
#
Get content ranges where at least the minimum about of text has been changed
Parameters:
| Name | Type | Description |
|---|---|---|
documentModel |
ve.dm.Document |
Returns:
- Inherited from:
- Source:
getModifiedRanges(documentModel, coveredNodesOnly, onlyContentRanges, onlyPureInsertions) → {Array.<ve.Range>}
#
Get content ranges which have been modified
In suggestion mode, this will return all content ranges.
Parameters:
| Name | Type | Description |
|---|---|---|
documentModel |
ve.dm.Document | |
coveredNodesOnly |
boolean | Only include ranges which cover the whole of their node |
onlyContentRanges |
boolean | Only return ranges which are content branch node interiors |
onlyPureInsertions |
boolean | Only return ranges which didn't replace any other content |
Returns:
- Inherited from:
- Source:
Get content ranges which have been modified
In suggestion mode, this will return all content ranges.
getName() → {string}
#
Get the name of the check type
Returns:
Check type name
- Type
- string
- Inherited from:
- Source:
getPrompt(action) → {jQuery|string|function|OO.ui.HtmlSnippet|undefined}
#
undefined}
#
Get the prompt for the check's actions, if any
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction |
Returns:
- Type
-
jQuery
|
string
|
function
|
OO.ui.HtmlSnippet
|
undefined
- Inherited from:
- Source:
getRegexReplacementData(range, regex, replacer, preserveCase, surfaceModel) → {Object|Object}
#
Compute the replacement string, target fragment, and prompt for a regex match that contains objects
We need special handling when the matched range contains inline objects like templates that getText() omits but that occupy positions in the linear data. To handle this, we narrow the replacement to only the portion that actually changed by chopping the parts that the term and the replacement have in common.
For ex, "foo bar baz" -> "foo qux baz" would become "bar" -> "qux" only.
Parameters:
| Name | Type | Description |
|---|---|---|
range |
ve.Range | Range of the match |
regex |
RegExp | Compiled regex used to find the match |
replacer |
string | function | Replacement string from the matchRule |
preserveCase |
boolean | If the replacement should match the case of the found term |
surfaceModel |
ve.dm.SurfaceModel |
Returns:
(the narrowed string to insert, the narrowed fragment to insert it into, and the string to display in the prompt)
Compute the replacement string, target fragment, and prompt for a regex match that contains objects
We need special handling when the matched range contains inline objects like templates that getText() omits but that occupy positions in the linear data.
getTitle(action) → {jQuery|string|function|OO.ui.HtmlSnippet}
#
Get the title of the check
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction |
Returns:
- Type
- jQuery | string | function | OO.ui.HtmlSnippet
- Inherited from:
- Source:
handleListener(surfaceModel, listener) → {Promise.<Array.<mw.editcheck.TextMatchEditCheckAction>>}
#
instantiateMatchRules(rawMatchRules)
#
Create a matchRule instance for each matchRule NOTE: rawMatchRules should never be anything but this.constructor.static.matchCache.rawMatchRules
Parameters:
| Name | Type | Description |
|---|---|---|
rawMatchRules |
Object | all matchRule objects from config |
Create a matchRule instance for each matchRule NOTE: rawMatchRules should never be anything but this.constructor.static.matchCache.rawMatchRules
isDismissedId(id) → {boolean}
#
Check if an action with a given ID has been dismissed
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string |
Returns:
- Type
- boolean
- Inherited from:
- Source:
isDismissedRange(range, name) → {boolean}
#
Check if this type of check has been dismissed covering a specific range
Parameters:
| Name | Type | Description |
|---|---|---|
range |
ve.Range | |
name |
string | of the tag |
Returns:
- Type
- boolean
- Inherited from:
- Source:
isOffsetQuoted(offset, documentModel) → {boolean}
#
Check if a specific offset in the document counts as being quoted
This is approximate because "quoted" is complicated. Various types of quotes are grouped together, and we count whether there's an odd number of any group preceding the offset within the current content-containing node.
Special attention is paid to distinguishing apostrophes from single-quotes, and blockquote nodes are explicitly always quoted.
Parameters:
| Name | Type | Description |
|---|---|---|
offset |
number | |
documentModel |
ve.dm.Document |
Returns:
- Type
- boolean
- Inherited from:
- Source:
Check if a specific offset in the document counts as being quoted
This is approximate because "quoted" is complicated.
isRangeInValidSection(range, documentModel, [config]) → {boolean}
#
Check if a modified range is a section we allow
This checks config.ignoreSections and config.includeSections, which are arrays containing strings that will be compared to the heading names. As a special-case, an empty string will be treated as referring to the lead section. Articles that don't contain any headings at all are "stubs" and won't be treated as having a lead section.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
range |
ve.Range | ||
documentModel |
ve.dm.Document | ||
config |
Object |
optional |
Override config to use instead of the check's default |
Returns:
Whether the range is in a section we don't ignore
- Type
- boolean
- Inherited from:
- Source:
Check if a modified range is a section we allow
This checks config.ignoreSections and config.includeSections, which are arrays containing strings that will be compared to the heading names.
isRangeValid(range, documentModel, [config]) → {boolean}
#
Test whether the range is valid for the check to apply
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
range |
ve.Range | ||
documentModel |
ve.dm.Document | ||
config |
Object |
optional |
Override config to use instead of the check's default |
Returns:
- Type
- boolean
- Inherited from:
- Source:
isTaggedId(tag, id) → {boolean}
#
Check if an action with a given ID has a given tag
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
string | |
id |
string |
Returns:
- Type
- boolean
- Inherited from:
- Source:
isTaggedRange(tag, range, name) → {boolean}
#
Check if this type of check has a given tag
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
string | |
range |
ve.Range | |
name |
string | of the tag |
Returns:
- Type
- boolean
- Inherited from:
- Source:
showSuccess([message])
#
Show a success notification
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
message |
string |
optional |
Message to show; defaults to static.success |
- Inherited from:
- Source:
tag(tag, action)
#
Tag a check action
TODO: This is asymmetrical. Do we want to split this into two functions, or unify isTaggedRange/isTaggedId into one function?
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
string | |
action |
mw.editCheck.EditCheckAction |
- Inherited from:
- Source:
Tag a check action
TODO: This is asymmetrical.
tagFragments(tag, fragments, [ephemeral], [name])
#
Tag a set of fragments
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tag |
string | ||
fragments |
Array.<ve.dm.SurfaceFragment> | ||
ephemeral |
boolean |
optional |
Clear the tag once the selection leaves the tagged range |
name |
string |
optional |
Tag namespace; defaults to this check's name |
- Inherited from:
- Source:
takesFocus() → {boolean}
#
Returns:
- Type
- boolean
- Inherited from:
- Source:
untag(tag, action) → {boolean}
#
Untag a check action
TODO: This is asymmetrical. Do we want to split this into two functions, or unify isTaggedRange/isTaggedId into one function?
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
string | |
action |
mw.editCheck.EditCheckAction |
Returns:
Whether anything was untagged
- Type
- boolean
- Inherited from:
- Source:
Untag a check action
TODO: This is asymmetrical.
createReplacementPrompt(foundText, replacement) → {string}static
#
Create a prompt for a replacement dialog, if within length limits
Parameters:
| Name | Type | Description |
|---|---|---|
foundText |
string | |
replacement |
string |
Returns:
prompt text
- Type
- string
ensureMatchRulesLoaded() → {Promise.<Object>}static
#
Ensure matchRules and any imported configs are loaded exactly once per edit session
Returns:
Promise which resolves to processed matchRules
processMatchRules(rawMatchRules) → {Promise.<Object>}static
#
Fetch corresponding MW file for any matchRules with the "import" property and leave all other matchRules unchanged
Parameters:
| Name | Type | Description |
|---|---|---|
rawMatchRules |
Object | Array | Map of matchRule IDs to raw config objects, or array (deprecated) |
Returns:
Promise which resolves to map of processed matchRules
Fetch corresponding MW file for any matchRules with the "import" property and leave all other matchRules unchanged