API:RecentChanges
Tato stránka je součástí dokumentace k API Action MediaWiki. |
Verze MediaWiki: | ≥ 1.9 |
Požadavek GET pro seznam všech posledních změn na wiki, stejným způsobem jako je uvádí Special:RecentChanges.
Dokumentace API
Příklad
Dotazování přes GET
Získejte 3 nejnovější změny s velikostmi a příznaky
api.php? action=query& list=recentchanges& rcprop=title|ids|sizes|flags|user& rclimit=3 [zkuste v ApiSandbox]
Odpověď
{
"batchcomplete": "",
"continue": {
"rccontinue": "20180330090522|1041353210",
"continue": "-||"
},
"query": {
"recentchanges": [
{
"type": "edit",
"ns": 0,
"title": "Histology",
"pageid": 13570,
"revid": 833218500,
"old_revid": 833218201,
"rcid": 1041353213,
"user": "Iztwoz",
"oldlen": 25718,
"newlen": 25749
}
...
]
}
}
Ukázkový kód
Python
#!/usr/bin/python3
"""
get_recent_changes.py
MediaWiki API Demos
Demo of `RecentChanges` module: Get the three most recent changes with
sizes and flags
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"format": "json",
"rcprop": "title|ids|sizes|flags|user",
"list": "recentchanges",
"action": "query",
"rclimit": "3"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
RECENTCHANGES = DATA['query']['recentchanges']
for rc in RECENTCHANGES:
print(str(rc['title']))
PHP
<?php
/*
get_recent_changes.php
MediaWiki API Demos
Demo of `RecentChanges` module: Get the three most recent changes with sizes and flags
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"list" => "recentchanges",
"rcprop" => "title|ids|sizes|flags|user",
"rclimit" => "3",
"format" => "json"
];
$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"]["recentchanges"] as $rc ){
echo( $rc["title"] . "\n" );
}
JavaScript
/*
get_recent_changes.js
MediaWiki API Demos
Demo of `RecentChanges` module: Get the three most recent changes with sizes and flags
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
list: "recentchanges",
rcprop: "title|ids|sizes|flags|user",
rclimit: "3",
format: "json"
};
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 recentchanges = response.query.recentchanges;
for (var rc in recentchanges) {
console.log(recentchanges[rc].title);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_recent_changes.js
MediaWiki API Demos
Demo of `RecentChanges` module: Get the three most recent changes with sizes and flags
MIT License
*/
var params = {
action: 'query',
list: 'recentchanges',
rcprop: 'title|ids|sizes|flags|user',
rclimit: '3',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var recentchanges = data.query.recentchanges,
rc;
for ( rc in recentchanges ) {
console.log( recentchanges[ rc ].title );
}
} );
Možné chyby
Kód | Popis |
---|---|
rcshow | Incorrect parameter - mutually exclusive values may not be supplied. |
rcpermissiondenied | You need the patrol or patrolmarks right to request the patrolled flag.
|
Historie parametrů
- v1.24: Zastaralé
rctoken
- v1.15: Odebráno
rctitles
- v1.14: Představeno
rctitles
- v1.13: Představeno
loginfo
Další poznámky
- Mnoho akcí log lze zobrazit pomocí tohoto modulu, s výjimkou akcí patrol , protože ty nejsou v tabulce recentchanges přítomny.
- Hodnota timestamp , od které se má začít s výpisem, nesmí být více než $wgRCMaxAge do minulosti, což je na wiki Wikimedia 30 dní.
- Nové změny mohou být do tabulky
recentchanges
vloženy mírně mimo pořadí vzhledem k jejich časovému razítku. Pokud tedy dvakrát po sobě požadujete nejnovější změny, druhá odpověď může obsahovat nové změny vložené několik sekund před nejnovější změnou v první odpovědi. Pokud tento modul opakovaně voláte, abyste získali aktuální změnu v datovém proudu, zvažte přidání překrývání mezi požadavky, abyste žádné změny nezmeškali. - Tento modul nelze použít jako zdroj.
- Tento modul je implementován programem ApiQueryRecentChanges.php .