API:Alltransclusions
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.21 |
GET request to list all existing and non-existing transclusions .
This module can be used as a generator .
API documentation
Example
GET request
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 [try in ApiSandbox]
Response
{
"batchcomplete": "",
"continue": {
"atcontinue": "!Hero_(album)",
"continue": "-||"
},
"query": {
"alltransclusions": [
{
"ns": 0,
"title": "!!Destroy-Oh-Boy!!"
},
{
"ns": 0,
"title": "!Action Pact!"
},
{
"ns": 0,
"title": "!Arriba!"
}
]
}
}
Sample code
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 );
}
} );
Possible errors
Code | Info |
---|---|
unknown_atnamespace | Unrecognized value for parameter atnamespace: value.
Results from enumerating a non-existent namespace. |
Additional notes
- This module is part of API:Alllinks .
See also
- API:Templates - Gets a list of all pages transcluded in a page.