API:帮助
本页是MediaWiki Action API帮助文档的一部份。 |
MediaWiki版本: | ≥ 1.8 |
请求GET来显示指定模块的帮助。
API帮助文档
示例
GET请求
显示指定模块的帮助。
回应
{
"help": {
"mime": "text/html",
"filename": "api-help.html",
"help": "<!DOCTYPE html>\n<html class=\"client-nojs\" lang=\"en\" dir=\"ltr\">\n<head>\n<meta charset=\"UTF-8\"/>\n<title>MediaWiki API help - Wikipedia</title>\n<script>document.documentElement.className=\"client-js\";RLCONF={\"wgBreakFrames\":!0,\"wgSeparatorTransformTable\":[\"\",\"\"],\"wgDigitTransformTable\":[\"\",\"\"],\"wgDefaultDateFormat\":\"dmy\",\"wgMonthNames\":
...
}
}
示例代码
Python
#!/usr/bin/python3
"""
get_help.py
MediaWiki API Demos
Demo of `Help` module: Get help for a specified module.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "help",
"modules": "query+tokens",
"wrap": "",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
get_help.php
MediaWiki API Demos
Demo of `Help` module: Get help for a specified module.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "help",
"modules" => "query+tokens",
"wrap" => "",
"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_help.js
MediaWiki API Demos
Demo of `Help` module: Get help for a specified module.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "help",
modules: "query+tokens",
wrap: "",
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) {console.log(response);})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_help.js
MediaWiki API Demos
Demo of `Help` module: Get help for a specified module.
MIT License
*/
var params = {
action: 'help',
modules: 'query+tokens',
wrap: '',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
可能的错误
代码 | 信息 |
---|---|
badmodule | 模块name不包含子模块“name2”。 |
参数历史
- v1.25: 启用
submodules
,recursivesubmodules
,wrap
,toc
- v1.25: 移除
querymodules
- v1.21: 弃用
querymodules
- v1.17: 启用
action
,format
,main