API:Revisions
| Revisions | ||
|---|---|---|
| Get revision information. This module can be used as a Generator. |
||
| Prefix | rv | |
| Required rights | none | |
| Post only? | No | |
| Generated help | Current | |
| Version added |
|
|
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). 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. 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+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:userhiddenif revision deleted and/oranonif unregistered.userid: User id of revision creator, as well asuserhiddenandanonflags. 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)
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 inrvprop=contentoutput. 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,rvlimitis enforced to 1. 1.17+ (Deprecated in 1.30)rvsection: Ifrvprop=contentis 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. Overridesrvdiffto. Ifrvsectionis 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 withrvdifftotext. 1.27+ (Deprecated in 1.30)rvcontentformat: Serialization format used forrvdifftotextand expected for output of content. 1.21+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/rvstartidhas to be higher thanrvend/rvendid.newer: List oldest revisions first. NOTE:rvstart/rvstartidhas to be lower thanrvend/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
api.php? action=query& prop=revisions& titles=API|Main%20Page& rvprop=timestamp|user|comment|content& formatversion=2 [try in ApiSandbox]
| Result |
|---|
{
"query": {
"pages": [
{
"pageid": 15580374,
"ns": 0,
"title": "Main Page",
"revisions": [
{
"user": "SlimVirgin",
"timestamp": "2015-05-31T17:32:11Z",
"comment": "Reverted edits by [[Special:Contribs/SlimVirgin|SlimVirgin]] ([[User talk:SlimVirgin|talk]]) to last version by Tim Starling (WMF)",
"contentformat": "text/x-wiki",
"contentmodel": "wikitext",
"content": // content removed for example
}
]
},
{
"pageid": 27697087,
"ns": 0,
"title": "API",
"revisions": [
{
"user": "Graham87",
"timestamp": "2010-06-13T08:41:17Z",
"comment": "Protected API: restore protection ([edit=sysop] (indefinite) [move=sysop] (indefinite))",
"contentformat": "text/x-wiki",
"contentmodel": "wikitext",
"content": "#REDIRECT [[Application programming interface]]{{R from abbreviation}}"
}
]
}
]
}
}
|
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
parsetreeproperty orgeneratexmlparameter is used and the content model (as returned by thecontentproperty) is not set towikitext
- Thrown when the
- Template expansion is supported for wikitext only, title uses content model content model
- Thrown when the
expandtemplatesparameter is used and the content model (as returned by thecontentproperty) is not set towikitext
- Thrown when the
- 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 |