接口:Alltransclusions
Appearance
本页是MediaWiki Action API帮助文档的一部份。 |
MediaWiki版本: | ≥ 1.21 |
GET request to list all existing and non-existing transclusions .
该模块可用作生成器 。
API帮助文档
示例
GET请求
Get three unique pages in the main namespace which contain transclusions.
api.php? action=query& format=json& list=alltransclusions& atunique=1& atnamespace=0& atlimit=3 [在Api沙盒中尝试]
回应
{
"batchcomplete": "",
"continue": {
"atcontinue": "!Hero_(album)",
"continue": "-||"
},
"query": {
"alltransclusions": [
{
"ns": 0,
"title": "!!Destroy-Oh-Boy!!"
},
{
"ns": 0,
"title": "!Action Pact!"
},
{
"ns": 0,
"title": "!Arriba!"
}
]
}
}
示例代码
Python
#!/usr/bin/python3
"""
get_alltransclusions.py
MediaWiki API Demos
Demo of `Alltransclusions` module: Get three unique pages in the main
namespace which contain transclusions.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "alltransclusions",
"atunique": "1",
"atnamespace": "0",
"atlimit": "3"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
TRANSCLUSIONS = DATA["query"]["alltransclusions"]
for t in TRANSCLUSIONS:
print(t["title"])
PHP
<?php
/*
get_alltransclusions.php
MediaWiki API Demos
Demo of `Alltransclusions` module: Get three unique pages in the main namespace which contain transclusions.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "alltransclusions",
"atunique" => "1",
"atnamespace" => "0",
"atlimit" => "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"]["alltransclusions"] as $k => $v ) {
echo( $v["title"] . "\n" );
}
JavaScript
/*
get_alltransclusions.js
MediaWiki API Demos
Demo of `Alltransclusions` module: Get three unique pages in the main namespace which contain transclusions.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "alltransclusions",
atunique: "1",
atnamespace: "0",
atlimit: "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 transclusions = response.query.alltransclusions;
for (var t in transclusions) {
console.log(transclusions[t].title);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_alltransclusions.js
MediaWiki API Demos
Demo of `Alltransclusions` module: Get three unique pages
in the main namespace which contain transclusions.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'alltransclusions',
atunique: '1',
atnamespace: '0',
atlimit: '3'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var transclusions = data.query.alltransclusions,
t;
for ( t in transclusions ) {
console.log( transclusions[ t ].title );
}
} );
可能的错误
代码 | 信息 |
---|---|
unknown_atnamespace | 无法识别的参数atnamespace的值:value。
Results from enumerating a non-existent namespace. |
补充资料
- This module is part of API:Alllinks .
参见
- 接口:模板 - Gets a list of all pages transcluded in a page.