API:Revisions

From MediaWiki.org
Jump to navigation Jump to search

Returns revisions for a given page, or the latest revision for each of several pages. Pages are specified either by pageids or titles parameter; individual revisions are specified by revids parameter (see API:Query#Specifying pages). Slots can be specified with the rvslots parameter; when the parameter is not present, the API will only return information about the main slot. When using parameters marked as (enum), titles= must have only one title listed. Prior to version 1.25, this module could not be used as a generator. Version 1.30 deprecated the diffing functionality of this module, and moved it to API:Compare. The code for this query is located on the git repository at ApiQueryRevisions.php.

Parameters[edit]

  • rvprop: Which properties to get for each revision (Default: ids|flags|timestamp|comment|user)
    • ids: Get the revid and, from 1.16 onward, the parentid. 1.11+
    • roles: List content slot roles that exist in the revision. 1.32+
    • flags: Whether the revision was a minor edit. 1.11+
    • timestamp: The date and time the revision was made, in ISO 8601 combined date and time format.
    • user: The user who made the revision, and if applicable, the flags: userhidden if revision deleted and/or anon if unregistered.
    • userid: User id of revision creator, as well as userhidden and anon flags. 1.17+
    • size: The size of the revision text in bytes. 1.11+
    • sha1: SHA-1 (base 16) of the revision. 1.19+
    • contentmodel: Content model id of the revision. 1.21+
    • comment: The edit comment.
    • parsedcomment: The edit/log comment in HTML format with wikilinks and section references expanded into hyperlinks 1.16+
    • content: The revision content. If set, the maximum limit will be 10 times as low. (Note: If you want HTML rather than wikitext, use action=parse instead.)
    • tags: Any tags for this revision, such as those added by AbuseFilter. 1.16+
    • parsetree: The XML parse tree of the revision content. 1.26+ (Deprecated in 1.30)
  • rvslots: Which revision slots to return data for, when slot-related properties are included in rvprops. If omitted, data from the main slot will be returned in a backwards-compatible format. 1.32+
  • rvlimit: The maximum number of revisions to return. Use the string "max" to return all revisions (subject to being broken up as usual, using continue). (enum) No more than 500 (5000 for bots) allowed.
  • rvexpandtemplates: Expand templates in rvprop=content output. 1.12+ (Deprecated in 1.30)
  • rvgeneratexml: Generate XML parse tree for revision content. 1.14+ (Deprecated in 1.26)
  • rvparse: Parse revision content. For performance reasons if this option is used, rvlimit is enforced to 1. 1.17+ (Deprecated in 1.30)
  • rvsection: If rvprop=content is set, only retrieve the contents of this section. This is an integer, not a string title. 1.13+
  • rvdiffto: Revision ID to diff each revision to. Use "prev", "next" and "cur" for the previous, next and current revision respectively. 1.15+ (Deprecated in 1.30)
  • rvdifftotext: Text to diff each revision to. Only diffs a limited number of revisions. Overrides rvdiffto. If rvsection is set, only that section will be diffed against this text. 1.16+ (Deprecated in 1.30)
  • rvdifftotextpst: Perform a pre-save transform on the text before diffing it. Only valid when used with rvdifftotext. 1.27+ (Deprecated in 1.30)
  • rvcontentformat: Serialization format used for rvdifftotext and expected for output of content. 1.21+ (Deprecated in 1.32)
  • rvstartid: Revision ID to start listing from. (enum)
  • rvendid: Revision ID to stop listing at. (enum)
  • rvstart: Timestamp to start listing from. (enum)
  • rvend: Timestamp to end listing at. (enum)
  • rvdir: Direction to list in. (enum) (Default: older)
    • older: List newest revisions first. NOTE: rvstart/rvstartid has to be higher than rvend/rvendid.
    • newer: List oldest revisions first. NOTE: rvstart/rvstartid has to be lower than rvend/rvendid.
  • rvuser: Only list revisions made by this user. 1.11+
  • rvexcludeuser: Do not list revisions made by this user. 1.11+
  • rvtag: Only list revisions tagged with this tag. 1.16+
  • rvtoken: Gets the rollback token for each revision. Possible values: rollback. 1.12+ (Deprecated in 1.24)
  • rvcontinue: When more results are available, use this to continue. This can be used, for example, for fetching the text of all revisions of a page (although an XML export might be more efficient). 1.15+

Example[edit]

Get data including content for the last revision of titles en:API and en:Main Page

prop=revisions (rv)

(main | query | revisions)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Get revision information.

May be used in several ways:

  1. Get data about a set of pages (last revision), by setting titles or pageids.
  2. Get revisions for one given page, by using titles or pageids with start, end, or limit.
  3. Get data about a set of revisions by setting their IDs with revids.
Parameters:
rvprop

Which properties to get for each revision:

ids
The ID of the revision.
flags
Revision flags (minor).
timestamp
The timestamp of the revision.
user
User that made the revision.
userid
User ID of the revision creator.
size
Length (bytes) of the revision.
slotsize
Length (bytes) of each revision slot.
sha1
SHA-1 (base 16) of the revision.
slotsha1
SHA-1 (base 16) of each revision slot.
contentmodel
Content model ID of each revision slot.
comment
Comment by the user for the revision.
parsedcomment
Parsed comment by the user for the revision.
content
Content of each revision slot.
tags
Tags for the revision.
roles
List content slot roles that exist in the revision.
parsetree
Deprecated. Use action=expandtemplates or action=parse instead. The XML parse tree of revision content (requires content model wikitext).
Values (separate with | or alternative): ids, flags, timestamp, user, userid, size, slotsize, sha1, slotsha1, contentmodel, comment, parsedcomment, content, tags, roles, parsetree
Default: ids|timestamp|flags|comment|user
rvslots

Which revision slots to return data for, when slot-related properties are included in rvprops. If omitted, data from the main slot will be returned in a backwards-compatible format.

Values (separate with | or alternative): main
To specify all values, use *.
rvlimit

Limit how many revisions will be returned.

May only be used with a single page (mode #2).
No more than 500 (5,000 for bots) allowed.
Type: integer or max
rvexpandtemplates
Deprecated.

Use action=expandtemplates instead. Expand templates in revision content (requires rvprop=content).

Type: boolean (details)
rvgeneratexml
Deprecated.

Use action=expandtemplates or action=parse instead. Generate XML parse tree for revision content (requires rvprop=content).

Type: boolean (details)
rvparse
Deprecated.

Use action=parse instead. Parse revision content (requires rvprop=content). For performance reasons, if this option is used, rvlimit is enforced to 1.

Type: boolean (details)
rvsection

Only retrieve the content of this section number.

rvdiffto
Deprecated.

Use action=compare instead. Revision ID to diff each revision to. Use prev, next and cur for the previous, next and current revision respectively.

rvdifftotext
Deprecated.

Use action=compare instead. Text to diff each revision to. Only diffs a limited number of revisions. Overrides rvdiffto. If rvsection is set, only that section will be diffed against this text.

rvdifftotextpst
Deprecated.

Use action=compare instead. Perform a pre-save transform on the text before diffing it. Only valid when used with rvdifftotext.

Type: boolean (details)
rvcontentformat
Deprecated.

Serialization format used for rvdifftotext and expected for output of content.

One of the following values: application/json, text/css, text/plain, text/x-wiki, text/javascript
rvstartid

Start enumeration from this revision's timestamp. The revision must exist, but need not belong to this page.

May only be used with a single page (mode #2).
Type: integer
rvendid

Stop enumeration at this revision's timestamp. The revision must exist, but need not belong to this page.

May only be used with a single page (mode #2).
Type: integer
rvstart

From which revision timestamp to start enumeration.

May only be used with a single page (mode #2).
Type: timestamp (allowed formats)
rvend

Enumerate up to this timestamp.

May only be used with a single page (mode #2).
Type: timestamp (allowed formats)
rvdir

In which direction to enumerate:

newer
List oldest first. Note: rvstart has to be before rvend.
older
List newest first (default). Note: rvstart has to be later than rvend.
May only be used with a single page (mode #2).
One of the following values: newer, older
Default: older
rvuser

Only include revisions made by user.

May only be used with a single page (mode #2).
Type: user name
rvexcludeuser

Exclude revisions made by user.

May only be used with a single page (mode #2).
Type: user name
rvtag

Only list revisions tagged with this tag.

rvtoken
Deprecated.

Which tokens to obtain for each revision.

Values (separate with | or alternative): rollback
rvcontinue

When more results are available, use this to continue.

Possible warnings[edit]

  • Couldn't diff to r######: content is hidden
    • Thrown when the revision has been hidden (e.g., using RevisionDelete or Oversight).
  • Conversion to XML is supported for wikitext only, title uses content model content model
    • Thrown when the parsetree property or generatexml parameter is used and the content model (as returned by the content property) is not set to wikitext
  • Template expansion is supported for wikitext only, title uses content model content model
    • Thrown when the expandtemplates parameter is used and the content model (as returned by the content property) is not set to wikitext
  • The requested format contentFormat is not supported for content model model used by name
    • Thrown when the content of either the current revision or one being diffed to is not supported (typically, not text).
  • Action 'action' is not allowed for the current user
    • Thrown when a token is requested that the current user isn't allowed to use


Possible errors[edit]

Code Info
rvdiffto rvdiffto must be set to "prev", "next", "cur" or a non-negative number.
rvnosuchrevid There is no revision with ID ID
rvnosuchsection There is no section section in rID
rvrevids The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).
rvmultpages titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.
rvaccessdenied The current user is not allowed to read title
rvbadparams start and startid cannot be used together
rvbadparams end and endid cannot be used together
rvbadparams user and excludeuser cannot be used together
rvbadformat The requested format contentFormat is not supported for content model model used by name
Note: this is changed to a warning as of MW 1.25