API:Allmessages
Appearance
This page is part of the MediaWiki Action API documentation. |
เวอร์ชันมีเดียวิกิ: | ≥ 1.12 |
GET request เพื่อแสดงรายการเนื้อหาของข้อความอินเทอร์เฟซบางส่วนหรือทั้งหมด
API documentation
ตัวอย่าง
GET request
รับข้อความแปลเป็นภาษาดัตช์
api.php? action=query& meta=allmessages& ammessages=august|mainpage|edit|rollback-success|Acct%20creation%20throttle%20hit|thismessagedoesntexist& amlang=nl& format=json [ลองใช้ในกระบะทรายเอพีไอ]
Response
{
"batchcomplete": "",
"query": {
"allmessages": [
{
"name": "august",
"normalizedname": "august",
"*": "augustus"
},
{
"name": "mainpage",
"normalizedname": "mainpage",
"*": "Hoofdpagina"
},
{
"name": "edit",
"normalizedname": "edit",
"*": "Bewerken"
},
...
]
}
}
รหัสตัวอย่าง
Python
#!/usr/bin/python3
"""
all_messages.py
MediaWiki API Demos
Demo of `Allmessages` module: Get the Dutch translations of some messages
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"meta": "allmessages",
"ammessages": "august|mainpage|edit|rollback-success",
"amlang": "nl",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
all_messages.php
MediaWiki API Demos
Demo of `Allmessages` module: Get the Dutch translations of some messages
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"meta" => "allmessages",
"ammessages" => "august|mainpage|edit|rollback-success",
"amlang" => "nl",
"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
/*
all_messages.js
MediaWiki API Demos
Demo of `Allmessages` module: Get the Dutch translations of some messages
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
meta: "allmessages",
ammessages: "august|mainpage|edit|rollback-success",
amlang: "nl",
format: "json"
};
url = url + "?origin=*";
for (var key in params) { url += "&" + key + "=" + encodeURIComponent(params[key]) ;};
fetch(url)
.then(function(response) { return response.json(); })
.then(function(response) { console.log(response); })
.catch(function(error) { console.log(error); });
MediaWiki JS
/*
all_messages.js
MediaWiki API Demos
Demo of `Allmessages` module: Get the Dutch translations of some messages
MIT License
*/
var params = {
action: 'query',
meta: 'allmessages',
ammessages: 'august|mainpage|edit|rollback-success',
amlang: 'nl'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
ประวัติพารามิเตอร์ (Parameter history)
- v1.19: เปิดตัว
amnocontent
,amincludelocal
- v1.18: เปิดตัว
amtitle
,amprefix
,amcustomised
- v1.17: เปิดตัว
amto
- v1.16: เปิดตัว
amprop
,default
,amenableparser
,amargs
- v1.15: เปิดตัว
amfrom