Compare revisions
GET | /core/v1/{project}/{language}/revision/{from}/compare/{to}
|
---|
Returns data that lets you display a line-by-line comparison of two revisions. (See an example.) Only text-based wiki pages can be compared.
Examples
curl
# Compare revisions 847170467 and 851733941 to the Earth article on English Wikipedia
$ curl https://api.wikimedia.org/core/v1/wikipedia/en/revision/847170467/compare/851733941
Python
# Python 3
# Compare revisions 847170467 and 851733941 to the Earth article on English Wikipedia
import requests
from_revision = '847170467'
to_revision = '851733941'
url = 'https://api.wikimedia.org/core/v1/wikipedia/en/revision/' + from_revision + '/compare/' + to_revision
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
<?php
// Compare revisions 847170467 and 851733941 to the Earth article on English Wikipedia
$from = '847170467';
$to = '851733941';
$authorization = 'Authorization: Bearer YOUR_ACCESS_TOKEN';
$url = 'https://api.wikimedia.org/core/v1/wikipedia/en/revision/' . $from . '/compare/' . $to;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>
JavaScript
// Compare revisions 847170467 and 851733941 to the Earth article on English Wikipedia
let url = 'https://api.wikimedia.org/core/v1/wikipedia/en/revision/847170467/compare/851733941';
let response = await fetch( url,
{
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Api-User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
}
);
response.json()
.then(console.log).catch(console.error);
Parameters
project
required path |
Project name. For example: wikipedia (encyclopedia articles), commons (images, audio, and video), wiktionary (dictionary entries). List all projects.
|
language
required path |
Language code. For example: ar (Arabic), en (English), es (Spanish). List supported languages.
|
from
required path |
Revision identifier to use as the base for comparison |
to
required path |
Revision identifier to compare to the base |
Responses
200 | Success: Revisions found
Example
{
"from": {
"id": 847170467,
"slot_role": "main",
"sections": [
{
"level": 2,
"heading": "==Description==",
"offset": 3006
},
{
"level": 2,
"heading": "==Taxonomy==",
"offset": 4324
},
{
"level": 3,
"heading": "===Family placement===",
"offset": 4643
},
{
"level": 3,
"heading": "===Species===",
"offset": 9513
},
{
"level": 2,
"heading": "==Cultivation==",
"offset": 12089
},
{
"level": 2,
"heading": "==Allergenic potential==",
"offset": 15634
},
{
"level": 2,
"heading": "==References==",
"offset": 15985
},
{
"level": 2,
"heading": "==External links==",
"offset": 16018
}
]
},
"to": {
"id": 851733941,
"slot_role": "main",
"sections": [
{
"level": 2,
"heading": "==Description==",
"offset": 3006
},
{
"level": 2,
"heading": "==Taxonomy==",
"offset": 4324
},
{
"level": 3,
"heading": "===Family placement===",
"offset": 4643
},
{
"level": 3,
"heading": "===Species===",
"offset": 9513
},
{
"level": 2,
"heading": "==Cultivation==",
"offset": 12089
},
{
"level": 2,
"heading": "==Allergenic potential==",
"offset": 16157
},
{
"level": 2,
"heading": "==References==",
"offset": 16508
},
{
"level": 2,
"heading": "==External links==",
"offset": 16541
}
]
},
"diff": [
{
"type": 0,
"lineNumber": 95,
"text": "",
"offset": {
"from": 14692,
"to": 14692
}
},
{
"type": 0,
"lineNumber": 96,
"text": "Though ''Neuranethes spodopterodes'' is invasive in the regions where it has emerged as a pest, it is not an exotic invader, but a [[Species translocation|translocated species]], having been imported inadvertently from its natural range in more northerly regions of the country. In its original range the moth is not of horticultural importance, being controlled by natural enemies that as yet have neither been identified nor imported along with the host plants. In contrast the ''Agapanthus'' borer is of considerable concern in the South West, and its voracity is so impressive that the species shows promise as a possible control for invasive ''Agapanthus praecox'' in countries like New Zealand.<ref>M.D. Picker and M. Krüger. Spread and Impacts of the Agapanthus Borer (Neuranethes spodopterodes (Hampson, 1908), comb. nov.), a Translocated Native Moth Species (Lepidoptera: Noctuidae). African Entomology 2013 21 (1), 172-176</ref>",
"offset": {
"from": 14693,
"to": 14693
}
},
{
"type": 1,
"lineNumber": 97,
"text": "",
"offset": {
"from": null,
"to": 15633
}
},
{
"type": 1,
"lineNumber": 98,
"text": "In 2016, a new species of [[Cecidomyiidae|gall midge]], ''[[Enigmadiplosis agapanthi]]'', was described damaging Agapanthus in the [[United Kingdom]].<ref>{{cite journal| last1 =Harris | first1 =KM | last2 =Salisbury |first2=A| last3=Jones |first3=H | title =''Enigmadiplosis agapanthi'', a new genus and species of gall midge (Diptera, Cecidomyiidae) damaging Agapanthus flowers in England. | journal =Cecidology | volume =31 | issue = | pages =17-20 | publisher =British Gall Society | location = | date =2016 }} </ref>",
"offset": {
"from": null,
"to": 15634
}
},
{
"type": 0,
"lineNumber": 99,
"text": "",
"offset": {
"from": 15633,
"to": 16156
}
},
{
"type": 0,
"lineNumber": 100,
"text": "==Allergenic potential==",
"offset": {
"from": 15634,
"to": 16157
}
}
]
}
|
---|---|
400 | Error: Revision IDs are for different pages or for pages that can't be compared
Example
{
"messageTranslations": {
"en": "The specified revisions belong to different pages; refusing to compare them."
},
"httpCode": 400,
"httpReason": "Bad Request"
}
|
404 | Error: Revision not found
Example
{
"messageTranslations": {
"en": "The revision specified by the to parameter does not exist."
},
"httpCode": 404,
"httpReason": "Not Found"
}
|
Response schema
from
required object |
Information about the base revision used in the comparison
Properties
| ||||||||||||||||||||||||||||
to
required object |
Information about the revision being compared to the base revision
Properties
| ||||||||||||||||||||||||||||
diff
required string |
Each object in the diff array represents a line in a visual, line-by-line comparison between the two revisions.
Properties
|