API:Logevents
Bu sayfa MediaWiki Eylem API'si belgelerinin bir parçasıdır. |
MediaWiki sürümü: | ≥ 1.9 |
Special:Log içinde gösterildiği gibi tüm kayıtlı olayların bir listesini almak için GET isteği.
API belgesi
Örnek
GET isteği
En son üç günlük olayları alın.
Yanıt
{
"batchcomplete": "",
"continue": {
"continue": "-||",
"lecontinue": "20190606150600|99729503"
},
"query": {
"logevents": [
{
"action": "create",
"comment": "added to WikiProject (via [[WP:JWB]])",
"logid": 99729506,
"logpage": 60974819,
"ns": 15,
"pageid": 60974819,
"params": {},
"timestamp": "2019-06-06T15:06:07Z",
"title": "Category talk:Electronic albums by Senegalese artists",
"type": "create",
"user": "Jevansen"
}
...
]
}
}
Örnek kod
Python
#!/usr/bin/python3
"""
get_logevents.py
MediaWiki API Demos
Demo of `Logevents` module: Get the three most recent logevents.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "logevents",
"lelimit": "3"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
LOGS = DATA["query"]["logevents"]
for l in LOGS:
print("There is " + l["type"] + " log for page " + l["title"])
PHP
<?php
/*
get_logevents.php
MediaWiki API Demos
Demo of `Logevents` module: Get the three most recent logevents.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "logevents",
"lelimit" => "3"
];
$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"]["logevents"] as $k => $v ) {
echo( "There is " . $v["type"] . " log for page " . $v["title"] . "\n" );
}
JavaScript
/*
get_logevents.js
MediaWiki API Demos
Demo of `Logevents` module: Get the three most recent logevents.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "logevents",
lelimit: "3"
};
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 logs = response.query.logevents;
for (var l in logs) {
console.log("There is " + logs[l].type + " log for page " + logs[l].title);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_logevents.js
MediaWiki API Demos
Demo of `Logevents` module: Get the three most recent logevents.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'logevents',
lelimit: '3'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var logs = data.query.logevents,
l;
for ( l in logs ) {
console.log( 'There is ' + logs[ l ].type + ' log for page ' + logs[ l ].title );
}
} );
Olası hatalar
Kod | Bilgi |
---|---|
leparam_user | User name username not found. |
leparam_title | Kötü başlık "title". This happens when you set letitle to an invalid title.
|
apierror-unrecognizedvalue | leaction parametresi için tanınmayan değer: value. |
apierror-prefixsearchdisabled | Önek Modu'nda önek araması devre dışı bırakılır. |
Parametre geçmişi
- v1.17:
leaction
tanıtıldı
Ek notlar
- This module cannot be used as a generator .
- For autoblock unblock entries, the
title
returned is shown as "User:$blockid". This is not a userpage, but just the way it is stored. See görev T19781. - When
userid
is specified for account creation events, theuserid
of the creating user is returned. When absent, theuserid
returned is that of the created account. See görev T73020. - See Manual:Log_actions for log types and log actions, and their log parameters and log_search entries and descriptions.
- Every log action is logged in the Manual:Logging_table . Users can see those edits on Special:Log, except for a few restricted logs like Special:Log/suppress.
Ayrıca bakınız
- API:Recentchanges - Son değişikliklerin bir listesini alır.
- API:Veritabanı alanı ve API özellik ilişkilendirmeleri .