User:Ostrzyciel/GSoC 2020/manual

A revert is (broadly speaking) an edit that reverses the actions of other editors. In that process a new version of the page is created.

This page serves as an overview of various types of reverts supported and recognized by MediaWiki, mainly for developers. It also discusses how to integrate extensions with revert-related mechanisms present in MediaWiki core.

Revert types
There are several methods of performing reverts that are recognized by MediaWiki.

UI
Undos are performed using the undo link that appears in page history, diff view, recent changes list and other places.

Undo links point to  with   and   parameters that specify which edits should be undone.
 * – the ID of the last revision being undone.
 * – the ID of the last "good" revision. The next revision will be the first revision being undone.

See also: Manual:Parameters to index.php

API
Undos can be performed through API using  with   and   parameters. Their behavior is the same as in.

Mechanism
All revisions from  (exclusive) to   (inclusive) are reverted. EditPage attempts to merge the inverse of these edits with the sequence of all subsequent edits. If that is not possible, a regular edit form is displayed and the edit is not counted as an undo.

After that, the edit form is displayed to the user, where the resulting content can be further modified.

Since version 1.36, if the user performs any modifications to the content before saving, the edit is not marked as an undo. This is to prevent users from marking arbitrary edits as undos.

Other content types
If your extension implements a new ContentHandler, it can override the  method in order to customize how undos are handled by your content type.

UI
Rollback can be performed using the rollback link that appears in page history, diff view, recent changes list and other places.

Rollback links point to  with additional parameters for ensuring the correct set of changes is being rolled back.

See also: Manual:Parameters to index.php

API
Rollbacks can be performed through API using. Their behavior is the same as in.

Mechanism
Rollback reverts the last edits made by the last editor of the page. This is a commonly useful scenario when dealing with vandalism, as usually all changes made recently by one user should be reverted.

Manual revert
The manual revert does not use any special UI or API, as it is inferred by the software automatically. Every time an edit is made, MediaWiki looks at a number of most recent revisions of the page (specified by, 15 by default) and looks for the most recent revision with matching content. If such a revision is found, the edit is marked as a "manual revert", that is an edit restoring the page to an exact previous state.

The feature can be disabled entirely by setting  to zero.

Revert tags
By default every revision considered a revert by MediaWiki is marked with an appropriate change tag. Each of these tags can be individually disabled using the  configuration variable.
 * Undo:
 * Rollback:
 * Manual revert:

Since version 1.36 additional data about the revert is saved with each tag in the  field of the. The data is the EditResult object associated with the edit (see the next section), encoded as JSON.

Accessing revert information in extensions
Version 1.35 introduced the EditResult class that is constructed when saving an edit. This object encapsulates information about the effect of the edit in context of its page's history, most importantly:
 * whether the edit was a revert,
 * which revert method was used,
 * what is the "base" revision for this revert,
 * which revisions were reverted.

This object is passed to extensions using the PageSaveComplete hook.