API:Fileusage
Appearance
From mediawiki.org
This page is part of the MediaWiki Action API documentation.
MediaWiki Action API |
---|
Basics |
Authentication |
Accounts and Users |
Page Operations |
|
Search |
Developer Utilities |
Tutorials |
v · d · e |
MediaWiki version:
≥ 1.24
GET request to find all pages that use the given files.
API documentation
[edit ] The following documentation is the output of Special:ApiHelp/query+fileusage , automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org).
prop=fileusage (fu)
- This module requires read rights.
- This module can be used as a generator.
- Source: MediaWiki
- License: GPL-2.0-or-later
Find all pages that use the given files.
Specific parameters:
Other general parameters are available.
- fuprop
Which properties to get:
- pageid
- Page ID of each page.
- title
- Title of each page.
- redirect
- Flag if the page is a redirect.
- Values (separate with | or alternative): pageid, redirect, title
- Default: pageid|title|redirect
- funamespace
Only include pages in these namespaces.
- Values (separate with | or alternative): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 710, 711, 828, 829, 1198, 1199, 2600, 5500, 5501
- To specify all values, use *.
- fushow
Show only items that meet these criteria:
- redirect
- Only show redirects.
- !redirect
- Only show non-redirects.
- Values (separate with | or alternative): !redirect, redirect
- fulimit
How many to return.
- Type: integer or max
- The value must be between 1 and 500.
- Default: 10
- fucontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
Examples:
- Get a list of pages using File:Example.jpg.
- api.php?action=query&prop=fileusage&titles=File%3AExample.jpg [open in sandbox]
- Get information about pages using File:Example.jpg.
- api.php?action=query&generator=fileusage&titles=File%3AExample.jpg&prop=info [open in sandbox]
Example
[edit ]GET request
[edit ]Get a list of pages using a given file.
Response
[edit ]{ "continue":{ "fucontinue":"4635245", "continue":"||" }, "query":{ "pages":{ "586539":{ "pageid":586539, "ns":6, "title":"File:Example.jpg", "fileusage":[ { "pageid":447341, "ns":5, "title":"Wikipedia talk:Extended image syntax" }, { "pageid":499974, "ns":4, "title":"Wikipedia:Tutorial/Formatting" }, { "pageid":554270, "ns":13, "title":"Help talk:Pictures" }, ... ] } } } }
Sample code
[edit ]Python
[edit ]#!/usr/bin/python3 """ get_file_usage.py MediaWiki API Demos Demo of `Fileusage` module: Get a list of pages using a given file. MIT License """ import requests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "titles": "File:Example.jpg", "prop": "fileusage", "format": "json" } R = S.get(url=URL, params=PARAMS) DATA = R.json() print(DATA)
PHP
[edit ]<?php /* get_file_usage.php MediaWiki API Demos Demo of `Fileusage` module: Get a list of pages using a given file. MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "titles" => "File:Example.jpg", "prop" => "fileusage", "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
[edit ]/* get_file_usage.js MediaWiki API Demos Demo of `Fileusage` module: Get a list of pages using a given file. MIT License */ varurl="https://en.wikipedia.org/w/api.php"; varparams={ action:"query", titles:"File:Example.jpg", prop:"fileusage", 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){console.log(response);}) .catch(function(error){console.log(error);});
MediaWiki JS
[edit ]/* get_file_usage.js MediaWiki API Demos Demo of `Fileusage` module: Get a list of pages using a given file. MIT License */ varparams={ action:'query', titles:'File:Example.jpg', prop:'fileusage', format:'json' }, api=newmw.Api(); api.get(params).done(function(data){ console.log(data); });
Possible errors
[edit ]Code | Info |
---|---|
fushow | Incorrect parameter - mutually exclusive values may not be supplied. |
Additional notes
[edit ]- This module can be used as a generator.
See also
[edit ]- API:Globalusage - List all file usages on wikis other than the one where the file is stored.
- API:Allfileusages - List all file usages, including non-existing.