API:Categoryinfo
Appearance
From mediawiki.org
This page is a translated version of the page API:Categoryinfo and the translation is 75% complete.
Outdated translations are marked like this.
Languages:
This page is part of the MediaWiki Action API documentation.
| MediaWiki Action API |
|---|
| พื้นฐาน |
| การอนุมัติ |
| บัญชีและผู้ใช้ |
| Page Operations |
|
| ค้นหา |
| Developer Utilities |
| Tutorials |
| v · d · e |
เวอร์ชันมีเดียวิกิ:
≥ 1.13
GET request เพื่อรับข้อมูลเกี่ยวกับบางหมวดหมู่
API documentation
The following documentation is the output of Special: ApiHelp/ query+categoryinfo, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org).
prop=categoryinfo (ci)
- This module requires read rights.
- Source: MediaWiki
- License: GPL-2.0-or-later
Returns information about the given categories.
Specific parameter:
Other general parameters are available.
- cicontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
Example:
- Get information about Category:Foo and Category:Bar.
- api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar [open in sandbox]
ตัวอย่าง
GET request
Get info about a few categories
api.php? action=query& titles=Albert|Category:Foo|Category:Infobox%20templates& prop=categoryinfo [ลองใช้ในกระบะทรายเอพีไอ]
Response
{ "batchcomplete":"", "query":{ "pages":{ "-1":{ "ns":14, "title":"Category:Foo", "missing":"", "categoryinfo":{ "size":1, "pages":1, "files":0, "subcats":0 } }, "1504":{ "pageid":1504, "ns":0, "title":"Albert" }, "3108204":{ "pageid":3108204, "ns":14, "title":"Category:Infobox templates", "categoryinfo":{ "size":2066, "pages":2048, "files":0, "subcats":18 } } } } }
รหัสตัวอย่าง
Python
#!/usr/bin/python3 """ get_category_info.py MediaWiki API Demos Demo of `Categoryinfo` module: Get information about few categories MIT license """ importrequests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "format": "json", "titles": "Category:Foo|Category:Infobox templates", "prop": "categoryinfo" } R = S.get(url=URL, params=PARAMS) DATA = R.json() PAGES = DATA["query"]["pages"] for k, v in PAGES.items(): print(v["title"] + " has " + str(v["categoryinfo"]["pages"]) + " pages.")
PHP
<?php //This file is autogenerated. See modules.json and autogenerator.py for details /* get_category_info.php MediaWiki API Demos Demo of `Categoryinfo` module: Get information about a few categories MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "format" => "json", "titles" => "Category:Foo|Category:Infobox templates", "prop" => "categoryinfo" ]; $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"]["pages"] as $k => $v ) { echo( $v["title"] . " has " . $v["categoryinfo"]["pages"] . " pages." . "\n" ); }
JavaScript
//This file is autogenerated. See modules.json and autogenerator.py for details /* get_category_items.js MediaWiki API Demos Demo of `Categorymembers` module : List twenty items in a category MIT License */ varurl="https://en.wikipedia.org/w/api.php"; varparams={ action:"query", prop:"categoryinfo", titles:"Category:Foo|Category:Infobox templates", format:"json" }; url=url+"?origin=*"; Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];}); fetch(url) .then(function(response){returnresponse.json();}) .then(function(response){ varpages=response.query.pages; for(varpageinpages){ console.log(pages[page].title+" has "+pages[page].categoryinfo.pages+" pages."); } }) .catch(function(error){console.log(error);});
MediaWiki JS
// This file is autogenerated. See modules.json and autogenerator.py for details /* get_category_info.js MediaWiki API Demos Demo of `Categoryinfo` module: Get information about a few categories MIT License */ varparams={ action:'query', format:'json', titles:'Category:Foo|Category:Infobox templates', prop:'categoryinfo' }, api=newmw.Api(); api.get(params).done(function(data){ varpages=data.query.pages, page; for(pageinpages){ console.log(pages[page].title+' has '+pages[page].categoryinfo.pages+' pages.'); } });
บันทึกเพิ่มเติม
- : ถ้าหน้าหมวดหมู่มีอยู่ แต่หมวดหมู่ไม่มีสมาชิกช่อง "categoryinfo" จะไม่รวมอยู่ในการตอบกลับของ API[clarification needed ]
- เมื่อมีผลมากขึ้นให้ใช้ข้อมูลนี้เพื่อดําเนินการต่อ