Expand all

abstract mw.editcheck.BaseEditCheck

Constructor

new mw.editcheck.BaseEditCheck(controller, [config], [includeSuggestions])abstract #

BaseEditCheck

Abstract base class for edit checks. Provides common configuration, tagging, and utility methods for subclasses implementing specific edit check logic.

Subclasses should implement event handler methods such as onBeforeSave and onDocumentChange.

Parameters:

Name Type Attributes Default Description
controller

Edit check controller

config Object optional

Configuration options

includeSuggestions boolean optional
false
Source:

BaseEditCheck

Abstract base class for edit checks.

Properties

onBeforeSaveabstract #

Get actions to show before save

Source:
Get actions to show before save

onBranchNodeChangeabstract #

Get actions to show when the focused branch node changed

Source:
Get actions to show when the focused branch node changed

onDocumentChangeabstract #

Get actions to show when document changed

Source:
Get actions to show when document changed

description :jQuery|string|function|OO.ui.HtmlSnippetstatic #

Main message of the edit check

Type:

Source:
Main message of the edit check

footer :jQuery|string|function|OO.ui.HtmlSnippetstatic #

Footer message of the edit check

Type:

Source:
Footer message of the edit check

prompt :jQuery|string|function|OO.ui.HtmlSnippetstatic #

Prompt message of the edit check

Type:

Source:
Prompt message of the edit check

success :jQuery|string|function|OO.ui.HtmlSnippetstatic #

Success message of the edit check

TODO: Add a default success message?

Type:

Source:

Success message of the edit check

TODO: Add a default success message?

takesFocus :booleanstatic #

Takes focus from the surface to show the check as soon as it is detected (on mobile)

On desktop the check cards are always visible so this config does nothing.

Type:

  • boolean
Source:

Takes focus from the surface to show the check as soon as it is detected (on mobile)

On desktop the check cards are always visible so this config does nothing.

Methods

act(choice, action, surface) → {jQuery.Promise|undefined}abstract #

User performs an action on an check

Parameters:

Name Type Description
choice string

action key from static.choices

action mw.editcheck.EditCheckAction
surface ve.ui.Surface
Source:

Returns:

Promise which resolves when action is complete, or undefined if there's nothing to wait on

Type
jQuery.Promise | undefined
User performs an action on an check

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 suggestions mode

Source:

Returns:

Whether the check should be shown

Type
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.

canBeStale() → {boolean} #

Check if the edit check can be stale

Source:

Returns:

Type
boolean
Check if the edit check can be stale

dismiss(action) #

Dismiss a check action

Parameters:

Name Type Description
action mw.editCheck.EditCheckAction
Source:
Dismiss a check action

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
Source:

Returns:

Type
Array.<ve.Range>
Get content ranges where at least the minimum about of text has been added

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 optional

Type of nodes to find, or all nodes if false

Source:

Returns:

Type
Array.<ve.dm.Node>
Find nodes that were added during the edit session

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

Source:

Returns:

Type
Array.<ve.Range>
Get content ranges which have been inserted

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

Source:

Returns:

The contained content ranges (content branch node interiors)

Type
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.

getDescription(action) → {jQuery|string|function|OO.ui.HtmlSnippet} #

Parameters:

Name Type Description
action mw.editcheck.EditCheckAction
Source:

Returns:

Type
jQuery | string | function | OO.ui.HtmlSnippet

getFooter(action) → {jQuery|string|function|OO.ui.HtmlSnippet|undefined} #

Get the footer of the check, if any

Parameters:

Name Type Description
action mw.editcheck.EditCheckAction
Source:

Returns:

Type
jQuery | string | function | OO.ui.HtmlSnippet | undefined
Get the footer of the check, if any

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
Source:

Returns:

Heading nodes from nearest to furthest

Type
Array.<ve.dm.MWHeadingNode>
Get the heading hierarchy at a given range

getModifiedAnnotationRanges(documentModel, [names]) → {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

Source:

Returns:

Annotation ranges, containing an annotation and its range

Type
Array.<ve.dm.LinearData.AnnotationRange>
Get annotation ranges where at least some content has been modified

getModifiedContentBranchNodes(documentModel) → {Array.<ve.dm.ContentBranchNode>} #

Get ContentBranchNodes where some text has been changed

Parameters:

Name Type Description
documentModel ve.dm.Document
Source:

Returns:

Type
Array.<ve.dm.ContentBranchNode>
Get ContentBranchNodes where some text has been changed

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
Source:

Returns:

Type
Array.<ve.Range>
Get content ranges where at least the minimum about of text has been changed

getModifiedRanges(documentModel, coveredNodesOnly, onlyContentRanges, onlyPureInsertions) → {Array.<ve.Range>} #

Get content ranges which have been modified

In suggestions 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

Source:

Returns:

Type
Array.<ve.Range>

Get content ranges which have been modified

In suggestions mode, this will return all content ranges.

getName() → {string} #

Get the name of the check type

Source:

Returns:

Check type name

Type
string
Get the name of the check type

getPrompt(action) → {jQuery|string|function|OO.ui.HtmlSnippet|undefined} #

Get the prompt for the check's actions, if any

Parameters:

Name Type Description
action mw.editcheck.EditCheckAction
Source:

Returns:

Type
jQuery | string | function | OO.ui.HtmlSnippet | undefined
Get the prompt for the check's actions, if any

getTitle(action) → {jQuery|string|function|OO.ui.HtmlSnippet} #

Get the title of the check

Parameters:

Name Type Description
action mw.editcheck.EditCheckAction
Source:

Returns:

Type
jQuery | string | function | OO.ui.HtmlSnippet
Get the title of the check

isDismissedId(id) → {boolean} #

Check if an action with a given ID has been dismissed

Parameters:

Name Type Description
id string
Source:

Returns:

Type
boolean
Check if an action with a given ID has been dismissed

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

Source:

Returns:

Type
boolean
Check if this type of check has been dismissed covering a specific range

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
Source:

Returns:

Type
boolean

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

Source:

Returns:

Whether the range is in a section we don't ignore

Type
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.

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

Source:

Returns:

Type
boolean
Test whether the range is valid for the check to apply

isTaggedId(tag, id) → {boolean} #

Check if an action with a given ID has a given tag

Parameters:

Name Type Description
tag string
id string
Source:

Returns:

Type
boolean
Check if an action with a given ID has a given tag

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

Source:

Returns:

Type
boolean
Check if this type of check has a given tag

showSuccess([message]) #

Show a success notification

Parameters:

Name Type Attributes Description
message string optional

Message to show; defaults to static.success

Source:
Show a success notification

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
Source:

Tag a check action

TODO: This is asymmetrical.

takesFocus() → {boolean} #

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
Source:

Returns:

Whether anything was untagged

Type
boolean

Untag a check action

TODO: This is asymmetrical.

doesConfigMatch(config, [documentModel], [suggestion]) → {boolean}static #

Find out if any conditions in the provided config are met

Parameters:

Name Type Attributes Default Description
config Object

Configuration options

documentModel ve.dm.Document optional

if attached to a known document

suggestion boolean optional
false

Whether we are checking for suggestions mode

Source:

Returns:

Whether the config matches

Type
boolean
Find out if any conditions in the provided config are met