API:Rollback
This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Create and edit pages
- Move pages
- Merge pages
- Rollback
- Delete pages
- Restore deleted revisions
- (Un)protect pages
- (Un)block users
- (Un)watch pages
- Mark revisions of watched pages as visited
- Send email
- Patrol changes
- Import pages
- Change user group membership
- Upload files
- User options
- Tokens
- Page language
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
Rollback | ||
---|---|---|
This module cannot be used as a Generator . |
||
Prefix | ||
Required rights | rollback | |
Post only? | Yes | |
Generated help | Current | |
Version added |
|
Contents
Rollback[edit]
Rolling back a page means undoing the last series of edits by one user. In other words, rollback keeps undoing revision after revision until it encounters one made by someone different. This functionality is identical to the one provided by the [rollback] links in the graphical interface. The rollback revision will be marked as minor. Optionally, both the rollback and the edits being rolled back can be marked as bot, which hides them from Special:RecentChanges by default.
Token[edit]
To rollback a page, a rollback token is required. If your wiki is using MediaWiki 1.24+, you can use action=query&meta=tokens&type=rollback to get a rollback token.
For MediaWiki 1.23 or earlier, follow these instructions:
Unlike most other tokens, rollback tokens aren't universal: they're not only different for every login, but also depend on the title of the page and the name of the user whose edits are to be rolled back. A rollback token can be obtained as follows:
Obtaining a rollback token
Result |
---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<query>
<pages>
<page pageid="5" ns="0" title="Main Page" rollbacktoken="094a45ddbbd5e90d55d79d2a23a8c921+\">
<revisions>
<rev revid="20" user="Catrope" timestamp="2007-09-03T20:32:20Z" />
</revisions>
</page>
</pages>
</query>
</api>
|
Rolling back pages[edit]
Pages can be rolled back with action=rollback.
Parameters[edit]
Note that only one of title
or pageid
are required, and they cannot be used together.
title
: The page you want to roll back. Cannot be used together with pageid.pageid
: Page ID of the page you want to roll back. Cannot be used together with title. 1.24+tags
: Tags to apply to the rollback. 1.27+user
: The author of the last revision.summary
: Edit summary (optional). If not set, a default summary will be used.markbot
: If set, both the rollback and the revisions being rolled back will be marked as bot edits.watchlist
: Unconditionally add or remove the page from your watchlist, use preferences or do not change watch. Possible values:watch
,unwatch
,preferences
,nochange
. (Default:preferences
) 1.17+token
: The token obtained in either a Tokens request withtype=rollback
or for wiki versions prior to 1.24, a Revisions request withrvtoken=rollback
. In the latter case, please note that the token is specific to the page and user who made the revision. In either case, make sure to urlencode the token.
Example[edit]
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=rollback requires POST requests; GET requests will cause an error.
Rollback Username's edits to the Main Page with a default summary, and mark them as bot edits
Result |
---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<rollback
title="Main Page"
pageid="5"
summary="Reverted edits by [[Special:Contributions/Username|Username]] ([[User talk:Username|Talk]]); changed back to last version by [[User:PreviousEditor|PreviousEditor]]"
revid="28"
old_revid="27"
last_revid="20" />
</api>
|
Returned fields[edit]
title
: The page title.pageid
: The page id.summary
: A copy of thesummary
parameter, or the auto-generated summary if none was provided.revid
: The revision ID of the rollback.old_revid
: The revision ID of the first (most recent) revision that was rolled back.last_revid
: The revision ID of the last (oldest) revision that was rolled back.
If rolling back wouldn't change the page, no new revision is made. In this case, revid
will be equal to old_revid
.
Possible errors[edit]
In addition to the usual stuff:
Code | Info |
---|---|
notitle | The title parameter must be set |
nouser | The user parameter must be set |
notoken | The token parameter must be set |
alreadyrolled | The page you tried to rollback was already rolled back |
onlyauthor | The page you tried to rollback only has one author |
The following documentation is the output of Special:ApiHelp/rollback, generated from rollback's source code. |
action=rollback
- This module requires read rights.
- This module requires write rights.
- This module only accepts POST requests.
- Source: MediaWiki
- License: GPL-2.0+
Undo the last edit to the page.
If the last user who edited the page made multiple edits in a row, they will all be rolled back.
- title
-
Title of the page to roll back. Cannot be used together with pageid.
- pageid
-
Page ID of the page to roll back. Cannot be used together with title.
- Type: integer
- tags
-
Tags to apply to the rollback.
- Values (separate with | or alternative):
- user
-
Name of the user whose edits are to be rolled back.
- This parameter is required.
- Type: user name
- summary
-
Custom edit summary. If empty, default summary will be used.
- Default: (empty)
- markbot
-
Mark the reverted edits and the revert as bot edits.
- Type: boolean (details)
- watchlist
-
Unconditionally add or remove the page from the current user's watchlist, use preferences or do not change watch.
- One of the following values: watch, unwatch, preferences, nochange
- Default: preferences
- token
-
A "rollback" token retrieved from action=query&meta=tokens
For compatibility, the token used in the web UI is also accepted.
- This parameter is required.
- Roll back the last edits to page Main Page by user Example.
- api.php?action=rollback&title=Main%20Page&user=Example&token=123ABC [open in sandbox]
- Roll back the last edits to page Main Page by IP user 192.0.2.5 with summary Reverting vandalism, and mark those edits and the revert as bot edits.
- api.php?action=rollback&title=Main%20Page&user=192.0.2.5&token=123ABC&summary=Reverting%20vandalism&markbot=1 [open in sandbox]