API:Templates/pl
Appearance
Ta strona jest częścią dokumentacji API akcji MediaWiki. |
Wersja MediaWiki: | ≥ 1.11 |
GET request to get a list of all pages (typically templates) transcluded in the provided pages.
Dokumentacja API
Przykład
Żądanie GET
Get a list of templates used on a page.
Odpowiedź
{
"continue": {
"tlcontinue": "736|10|Birth_date",
"continue": "||"
},
"query": {
"pages": {
"736": {
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"templates": [
{
"ns": 0,
"title": "Einstein"
},
{
"ns": 10,
"title": "Template:20th Century Press Archives"
},
...
]
}
}
}
Przykładowy kod
Python
#!/usr/bin/python3
"""
templates.py
MediaWiki API Demos
Demo of `Templates` module: Get a list of templates used on a page
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"titles": "Albert Einstein",
"prop": "templates",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
templates.php
MediaWiki API Demos
Demo of `Templates` module: Get a list of templates used on a page
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"titles" => "Albert Einstein",
"prop" => "templates",
"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
/*
templates.js
MediaWiki API Demos
Demo of `Templates` module: Get a list of templates used on a page
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
titles: "Albert Einstein",
prop: "templates",
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
/*
templates.js
MediaWiki API Demos
Demo of `Templates` module: Get a list of templates used on a page
MIT License
*/
var params = {
action: 'query',
titles: 'Albert Einstein',
prop: 'templates',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
Parameter history
- v1.19: Introduced
tldir
- v1.17: Introduced
tltemplates
- v1.x: Introduced
tlcontinue
,tllimit
Dodatkowe informacje
- This module can be used as a generator .
Zobacz też
- API:Transcludedin - Find all pages that transclude the given pages.