API:Templates/ja
このページは MediaWiki 操作 API の説明文書の一部です。 |
MediaWiki バージョン: | ≧ 1.11 |
GET request to get a list of all pages (typically templates) transcluded in the provided pages.
APIの説明文書
例
GET リクエスト
Get a list of templates used on a page.
Response
{
"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"
},
...
]
}
}
}
サンプル コード
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 );
} );
パラメーターの履歴
- v1.19: Introduced
tldir
- v1.17: Introduced
tltemplates
- v1.x: Introduced
tlcontinue
,tllimit
追加的な注記
- This module can be used as a generator .
関連項目
- API:Transcludedin - Find all pages that transclude the given pages.