API:Allrevisions
Appearance
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.27 |
GET request to list all revisions by a user or in a namespace.
API documentation
[edit]
Example
[edit]GET request
[edit]Get a list of all revisions by user Place holder on the English Wikipedia.
api.php? action=query& list=allrevisions& arvuser=Place holder& arvprop=ids|flags|timestamp [try in ApiSandbox]
Response
[edit]{
"batchcomplete": "",
"query": {
"allrevisions": [
{
"pageid": 36757881,
"revisions": [
{
"revid": 679803046,
"parentid": 656413943,
"timestamp": "2015-09-06T21:35:42Z"
},
{
"revid": 159361827,
"parentid": 0,
"timestamp": "2007-09-21T10:35:22Z"
}
],
"ns": 3,
"title": "User talk:Place holder"
}
...
]
}
}
Sample code
[edit]Python
[edit]#This file is auto-generated. See modules.json and autogenerator.py for details
#!/usr/bin/python3
"""
get_allrevisions.py
MediaWiki API Demos
Demo of `Allrevisions` module: get revision data of multiple pages and users
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"arvprop": "ids|flags|timestamp",
"arvuser": "Place holder",
"list": "allrevisions",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
ALLREVISIONS = DATA["query"]["allrevisions"]
for rev in ALLREVISIONS:
print(rev)
PHP
[edit]<?php
//This file is autogenerated. See modules.json and autogenerator.py for details
/*
get_allrevisions.php
MediaWiki API Demos
Demo of `Allrevisions` module: get revision data of multiple pages and users
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "allrevisions",
"arvprop" => "ids|flags|timestamp",
"arvuser" => "Place holder"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
foreach( $result["query"]["allrevisions"] as $k => $v ) {
foreach( $v["revisions"] as $k => $v ) {
var_dump( $v );
}
}
JavaScript
[edit]//This file is autogenerated. See modules.json and autogenerator.py for details
/*
get_allrevisions.js
MediaWiki API Demos
Demo of `Allrevisions` module: get revision data of multiple pages and users
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "allrevisions",
arvprop: "ids|flags|timestamp",
arvuser: "Place holder"
};
url = url "?origin=*";
Object.keys(params).forEach(function(key){url = "&" key "=" params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var revs = response.query.allrevisions;
for (var r in revs) {
console.log(revs[r]);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
[edit]// This file is autogenerated. See modules.json and autogenerator.py for details
/*
get_allrevisions.js
MediaWiki API Demos
Demo of `Allrevisions` module: get revision data of multiple pages and users
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'allrevisions',
arvprop: 'ids|flags|timestamp',
arvuser: 'Place holder'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var revs = data.query.allrevisions,
r;
for ( r in revs ) {
console.log( revs[ r ] );
}
} );
Possible warnings
[edit]- Couldn't diff to r######: content is hidden.
- Thrown when the revision has been hidden (e.g., using RevisionDelete or Oversight).
- prop=parsetree is only supported for wikitext content. title uses content model content model.
- Thrown when the
parsetree
property orgeneratexml
parameter is used and the content model (as returned by thecontent
property) is not set towikitext
- Thrown when the
- Template expansion is only supported for wikitext content. title uses content model content model.
- Thrown when the
expandtemplates
parameter is used and the content model (as returned by thecontent
property) 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).
Possible errors
[edit]Code | Info |
---|---|
arvdiffto | arvdiffto must be set to a non-negative number, prev, next or cur. |
arvnosuchrevid | There is no revision with ID ID. |
arvnosuchsection | There is no section section in ID. |
Parameter history
[edit]- v1.26: Deprecated
arvgeneratexml
- v1.27: Introduced
arvdifftotextpst
- v1.30: Deprecated
parsetree
,arvparse
,arvexpandtemplates
,arvdiffto
,arvdifftotext
,arvdifftotextpst
See also
[edit]- API:Revisions - obtain revision information of page(s).
- API:Revisiondelete - Delete and undelete revisions.