API:Contributors
This page is part of the MediaWiki Action API documentation. |
เวอร์ชันมีเดียวิกิ: | ≥ 1.23 |
GET request to view the list of logged-in contributors and the count of anonymous contributors to a page.
API documentation
ตัวอย่าง
GET request
GET request to view the logged-in and anonymous contributors to a page.
Response
{
"continue": {
"pccontinue": "323710|1591",
"continue": "||"
},
"query": {
"pages": {
"323710": {
"pageid": 323710,
"ns": 0,
"title": "MediaWiki",
"anoncontributors": 603,
"contributors": [
{
"userid": 1,
"name": "Damian Yerrick"
},
{
"userid": 11,
"name": "Kpjas"
},
{
"userid": 43,
"name": "Lee Daniel Crocker"
},
...
]
}
}
}
}
รหัสตัวอย่าง
Python
#!/usr/bin/python3
"""
get_contributors.py
MediaWiki API Demos
Demo of `Contributors` module: List all the logged-in contributors and count of anonymous
contributors to a page.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"titles": "MediaWiki",
"prop": "contributors",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
get_contributors.php
MediaWiki API Demos
Demo of `Contributors` module: List all the logged-in contributors and count of anonymous
contributors to a page.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"titles" => "MediaWiki",
"prop" => "contributors",
"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 );
var_dump( $result );
Javascript
/*
get_contributors.js
MediaWiki API Demos
Demo of `Contributors` module: Get request to list all logged-in contributors and count of anonymous contributors to a page.
MIT License
*/
const fetch = require('node-fetch');
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
titles: "MediaWiki",
prop: "contributors",
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 pages = response.query.pages;
for (var page in pages) {
console.log(pages[page].anoncontributors);
console.log(pages[page].contributors);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_contributors.js
MediaWiki API Demos
Demo of `Contributors` module: List all the logged-in contributors and count of anonymous
contributors to a page.
MIT License
*/
var params = {
action: 'query',
titles: 'MediaWiki',
prop: 'contributors',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
บันทึกเพิ่มเติม
- This module cannot be used as a generator.
ดูเพิ่ม
- API:Users - to view information about a list of users.