API:Allfileusages
Appearance
From mediawiki.org
This page is a translated version of the page API:Allfileusages and the translation is 27% 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.22
แสดงรายการไฟล์ทั้งหมดรวมถึงไฟล์ที่ไม่มีอยู่
API documentation
The following documentation is the output of Special: ApiHelp/ query+allfileusages, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org).
list=allfileusages (af)
- This module requires read rights.
- This module can be used as a generator.
- Source: MediaWiki
- License: GPL-2.0-or-later
List all file usages, including non-existing.
Specific parameters:
Other general parameters are available.
- afcontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
- affrom
The title of the file to start enumerating from.
- afto
The title of the file to stop enumerating at.
- afprefix
Search for all file titles that begin with this value.
- afunique
Only show distinct file titles. Cannot be used with afprop=ids.
When used as a generator, yields target pages instead of source pages.
- Type: boolean (details)
- afprop
Which pieces of information to include:
- ids
- Adds the page IDs of the using pages (cannot be used with afunique).
- title
- Adds the title of the file.
- Values (separate with | or alternative): ids, title
- Default: title
- aflimit
How many total items to return.
- Type: integer or max
- The value must be between 1 and 500.
- Default: 10
- afdir
The direction in which to list.
- One of the following values: ascending, descending
- Default: ascending
Examples:
- List file titles, including missing ones, with page IDs they are from, starting at B.
- api.php?action=query&list=allfileusages&affrom=B&afprop=ids|title [open in sandbox]
- List unique file titles.
- api.php?action=query&list=allfileusages&afunique=&affrom=B [open in sandbox]
- Gets all file titles, marking the missing ones.
- api.php?action=query&generator=allfileusages&gafunique=&gaffrom=B [open in sandbox]
- Gets pages containing the files.
- api.php?action=query&generator=allfileusages&gaffrom=B [open in sandbox]
ตัวอย่าง
GET request
แสดงรายการไฟล์ที่ใช้ 10 ไฟล์แรกโดยเริ่มจากคําว่า "ไอคอน" และใช้รหัสผ่านของหน้าเว็บใด
Response
{ "batchcomplete":"", "continue":{ "afcontinue":"Icon-C4004.jpg|7174658", "continue":"-||" }, "query":{ "allfileusages":[ { "fromid":12221220, "ns":6, "title":"File:Icon" }, { "fromid":12274856, "ns":6, "title":"File:Icon" }, { "fromid":14729339, "ns":6, "title":"File:Icon" } ... ] } }
Sample code
Python
#!/usr/bin/python3 """ get_allfileusages.py MediaWiki API Demos Demo of `allfileusage` module: List all file usages, including non-existing MIT License """ importrequests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "afprefix": "Icon", "list": "allfileusages", "afprop": "ids|title", "format": "json" } R = S.get(url=URL, params=PARAMS) DATA = R.json() USAGES = DATA["query"]["allfileusages"] for img in USAGES: print(img["title"])
PHP
<?php /* get_allfileusages.php MediaWiki API Demos Demo of `allfileusage` module: List all file usages, including non-existing. MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "format" => "json", "list" => "allfileusages", "afprefix" => "Icon", "afprop" => "ids|title" ]; $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"]["allfileusages"] as $k => $v ) { echo( $v["title"] . "\n" ); }
JavaScript
/* get_allfileusages.js MediaWiki API Demos Demo of `allfileusage` module: List all file usages, including non-existing. MIT License */ varurl="https://en.wikipedia.org/w/api.php"; varparams={ action:"query", format:"json", list:"allfileusages", afprefix:"Icon", afprop:"ids|title" }; url=url+"?origin=*"; Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];}); fetch(url) .then(function(response){returnresponse.json();}) .then(function(response){ varusages=response.query.allfileusages; for(varimginusages){ console.log(usages[img].title); } }) .catch(function(error){console.log(error);});
MediaWiki JS
/* get_allfileusages.js MediaWiki API Demos Demo of `allfileusage` module: List all file usages, including non-existing. MIT License */ varparams={ action:'query', format:'json', list:'allfileusages', afprefix:'Icon', afprop:'ids|title' }, api=newmw.Api(); api.get(params).done(function(data){ varusages=data.query.allfileusages, img; for(imginusages){ console.log(usages[img].title); } });
See also
- API:Properties - get properties of a page.
- API:Lists - list pages matching a criterion.