API:Allimages
MediaWiki Action API |
---|
Basics |
Authentication |
Accounts and Users |
Page Operations |
|
Search |
Developer Utilities |
Tutorials |
v · d · e |
GET request to list all image files, ordered by either title or timestamp.
This module can be used as a generator .
API documentation
[edit ]list=allimages (ai)
- This module requires read rights.
- This module can be used as a generator.
- Source: MediaWiki
- License: GPL-2.0-or-later
Enumerate all images sequentially.
- aisort
Property to sort by.
- One of the following values: name, timestamp
- Default: name
- aidir
The direction in which to list.
- One of the following values: ascending, descending, newer, older
- Default: ascending
- aifrom
The image title to start enumerating from. Can only be used with aisort=name.
- aito
The image title to stop enumerating at. Can only be used with aisort=name.
- aicontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
- aistart
The timestamp to start enumerating from. Can only be used with aisort=timestamp.
- Type: timestamp (allowed formats)
- aiend
The timestamp to end enumerating. Can only be used with aisort=timestamp.
- Type: timestamp (allowed formats)
- aiprop
Which file information to get:
- timestamp
- Adds timestamp for the uploaded version.
- user
- Adds the user who uploaded each file version. If the user has been revision deleted, a userhidden property will be returned.
- userid
- Add the ID of the user that uploaded each file version. If the user has been revision deleted, a userhidden property will be returned.
- comment
- Comment on the version. If the comment has been revision deleted, a commenthidden property will be returned.
- parsedcomment
- Parse the comment on the version. If the comment has been revision deleted, a commenthidden property will be returned.
- canonicaltitle
- Adds the canonical title of the file. If the file has been revision deleted, a filehidden property will be returned.
- url
- Gives URL to the file and the description page. If the file has been revision deleted, a filehidden property will be returned.
- size
- Adds the size of the file in bytes and the height, width and page count (if applicable).
- dimensions
- Alias for size.
- sha1
- Adds SHA-1 hash for the file. If the file has been revision deleted, a filehidden property will be returned.
- mime
- Adds MIME type of the file. If the file has been revision deleted, a filehidden property will be returned.
- mediatype
- Adds the media type of the file. If the file has been revision deleted, a filehidden property will be returned.
- metadata
- Lists Exif metadata for the version of the file. If the file has been revision deleted, a filehidden property will be returned.
- commonmetadata
- Lists file format generic metadata for the version of the file. If the file has been revision deleted, a filehidden property will be returned.
- extmetadata
- Lists formatted metadata combined from multiple sources. Results are HTML formatted. If the file has been revision deleted, a filehidden property will be returned.
Note: This is an expensive property to request, and should be avoided unless you need it. When using it, you should request only a few results at a time to avoid too much load.
- bitdepth
- Adds the bit depth of the version. If the file has been revision deleted, a filehidden property will be returned.
- badfile
- Adds whether the file is on the MediaWiki:Bad image list
- Values (separate with | or alternative): badfile, bitdepth, canonicaltitle, comment, commonmetadata, dimensions, extmetadata, mediatype, metadata, mime, parsedcomment, sha1, size, timestamp, url, user, userid
- Default: timestamp|url
- aiprefix
Search for all image titles that begin with this value. Can only be used with aisort=name.
- aiminsize
Limit to images with at least this many bytes.
- Type: integer
- aimaxsize
Limit to images with at most this many bytes.
- Type: integer
- aisha1
SHA1 hash of image. Overrides aisha1base36.
- aisha1base36
SHA1 hash of image in base 36 (used in MediaWiki).
- aiuser
Only return files where the last version was uploaded by this user. Can only be used with aisort=timestamp. Cannot be used together with aifilterbots.
- Type: user, by any of username, IP, Temporary user, interwiki name (e.g. "prefix>ExampleName") and user ID (e.g. "#12345")
- aifilterbots
How to filter files uploaded by bots. Can only be used with aisort=timestamp. Cannot be used together with aiuser.
- One of the following values: all, bots, nobots
- Default: all
- aimime
Disabled due to miser mode.
- Separate values with | or alternative.
- Maximum number of values is 50 (500 for clients that are allowed higher limits).
- ailimit
How many images in total to return.
- Type: integer or max
- The value must be between 1 and 500.
- Default: 10
- Show a list of files starting at the letter B.
- api.php?action=query&list=allimages&aifrom=B [open in sandbox]
- Show a list of recently uploaded files, similar to Special:NewFiles.
- api.php?action=query&list=allimages&aiprop=user|timestamp|url&aisort=timestamp&aidir=older [open in sandbox]
- Show a list of files with MIME type image/png or image/gif
- api.php?action=query&list=allimages&aimime=image/png|image/gif [open in sandbox]
- Show info about 4 files starting at the letter T.
- api.php?action=query&generator=allimages&gailimit=4&gaifrom=T&prop=imageinfo [open in sandbox]
Example
[edit ]Example 1: Get images by name
[edit ]GET request
[edit ]Graffiti_000
. Limit the initial response to just the first three images.Response
[edit ]{ "batchcomplete":"", "continue":{ "aicontinue":"Graffiti_BTER_0001.JPG", "continue":"-||" }, "query":{ "allimages":[ { "name":"Graffiti_0001.JPG", "timestamp":"2006年10月26日T01:48:05Z", "url":"https://upload.wikimedia.org/wikipedia/en/9/98/Graffiti_0001.JPG", "descriptionurl":"https://en.wikipedia.org/wiki/File:Graffiti_0001.JPG", "descriptionshorturl":"https://en.wikipedia.org/w/index.php?curid=7624737", "ns":6, "title":"File:Graffiti 0001.JPG" }, { "name":"Graffiti_0002.JPG", "timestamp":"2006年10月26日T02:03:40Z", "url":"https://upload.wikimedia.org/wikipedia/en/6/66/Graffiti_0002.JPG", "descriptionurl":"https://en.wikipedia.org/wiki/File:Graffiti_0002.JPG", "descriptionshorturl":"https://en.wikipedia.org/w/index.php?curid=7624935", "ns":6, "title":"File:Graffiti 0002.JPG" }, { "name":"Graffiti_0003.JPG", "timestamp":"2006年10月26日T08:05:08Z", "url":"https://upload.wikimedia.org/wikipedia/en/2/2b/Graffiti_0003.JPG", "descriptionurl":"https://en.wikipedia.org/wiki/File:Graffiti_0003.JPG", "descriptionshorturl":"https://en.wikipedia.org/w/index.php?curid=7628426", "ns":6, "title":"File:Graffiti 0003.JPG" } ] } }
Sample code
[edit ]Python
[edit ]#!/usr/bin/python3 """ get_allimages_by_name.py MediaWiki API Demos List all images in the namespace, starting from files that begin with 'Graffiti_000'. Limit the initial response to just the first three images. MIT License """ importrequests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "format": "json", "list": "allimages", "aifrom": "Graffiti_000", "ailimit": "3" } R = S.get(url=URL, params=PARAMS) DATA = R.json() IMAGES = DATA["query"]["allimages"] for img in IMAGES: print(img["title"])
PHP
[edit ]<?php /* get_allimages_by_name.php MediaWiki API Demos List all images in the namespace, starting from files that begin with 'Graffiti_000'. Limit the initial response to just the first three images. MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "format" => "json", "list" => "allimages", "aifrom" => "Graffiti_000", "ailimit" => "3" ]; $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"]["allimages"] as $k => $v ) { echo( $v["title"] . "\n" ); }
JavaScript
[edit ]/* get_allimages_by_name.js MediaWiki API Demos List all images in the namespace, starting from files that begin with 'Graffiti_000'. Limit the initial response to just the first three images. MIT License */ varurl="https://en.wikipedia.org/w/api.php"; varparams={ action:"query", format:"json", list:"allimages", aifrom:"Graffiti_000", ailimit:"3" }; url=url+"?origin=*"; Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];}); fetch(url) .then(function(response){returnresponse.json();}) .then(function(response){ varimages=response.query.allimages; for(varimginimages){ console.log(images[img].title); } }) .catch(function(error){console.log(error);});
MediaWiki JS
[edit ]/* get_allimages_by_name.js MediaWiki API Demos List all images in the namespace, starting from files that begin with 'Graffiti_000'. Limit the initial response to just the first three images. MIT License */ varparams={ action:'query', format:'json', list:'allimages', aifrom:'Graffiti_000', ailimit:'3' }, api=newmw.Api(); api.get(params).done(function(data){ varimages=data.query.allimages, img; for(imginimages){ console.log(images[img].title); } });
Example 2: Get images by date
[edit ]GET request
[edit ]Response
[edit ]{ "batchcomplete":"", "continue":{ "aicontinue":"20100101190633|Ryan_Baker_12-30-2009.JPG", "continue":"-||" }, "query":{ "allimages":[ { "name":"DramaQueenThatGirl.jpg", "timestamp":"2010年01月01日T18:21:57Z", "url":"https://upload.wikimedia.org/wikipedia/en/1/17/DramaQueenThatGirl.jpg", "descriptionurl":"https://en.wikipedia.org/wiki/File:DramaQueenThatGirl.jpg", "descriptionshorturl":"https://en.wikipedia.org/w/index.php?curid=25646192", "ns":6, "title":"File:DramaQueenThatGirl.jpg" }, { "name":"VS_in_viena_austria.JPG", "timestamp":"2010年01月01日T18:42:49Z", "url":"https://upload.wikimedia.org/wikipedia/en/b/bd/VS_in_viena_austria.JPG", "descriptionurl":"https://en.wikipedia.org/wiki/File:VS_in_viena_austria.JPG", "descriptionshorturl":"https://en.wikipedia.org/w/index.php?curid=25646382", "ns":6, "title":"File:VS in viena austria.JPG" }, { "name":"Vasanthamtv_channel.jpg", "timestamp":"2010年01月01日T19:03:08Z", "url":"https://upload.wikimedia.org/wikipedia/en/1/18/Vasanthamtv_channel.jpg", "descriptionurl":"https://en.wikipedia.org/wiki/File:Vasanthamtv_channel.jpg", "descriptionshorturl":"https://en.wikipedia.org/w/index.php?curid=25626466", "ns":6, "title":"File:Vasanthamtv channel.jpg" } ... ] } }
Sample code
[edit ]Python
[edit ]#!/usr/bin/python3 """ get_allimages_by_date.py MediaWiki API Demos List all images in the namespace, starting from January 1, 2010, at 18:05:46 UTC. MIT License """ importrequests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "format": "json", "list": "allimages", "aisort": "timestamp", "aistart": "2010年01月01日T18:05:46Z" } R = S.get(url=URL, params=PARAMS) DATA = R.json() IMAGES = DATA["query"]["allimages"] for img in IMAGES: print(img["title"])
PHP
[edit ]<?php /* get_allimages_by_date.php MediaWiki API Demos List all images in the namespace, starting from January 1, 2010, at 18:05:46 UTC. MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "format" => "json", "list" => "allimages", "aisort" => "timestamp", "aistart" => "2010年01月01日T18:05:46Z" ]; $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"]["allimages"] as $k => $v ) { echo( $v["title"] . "\n" ); }
JavaScript
[edit ]/* get_allimages_by_date.js MediaWiki API Demos List all images in the namespace, starting from January 1, 2010, at 18:05:46 UTC. MIT License */ varurl="https://en.wikipedia.org/w/api.php"; varparams={ action:"query", format:"json", list:"allimages", aisort:"timestamp", aistart:"2010年01月01日T18:05:46Z" }; url=url+"?origin=*"; Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];}); fetch(url) .then(function(response){returnresponse.json();}) .then(function(response){ varimages=response.query.allimages; for(varimginimages){ console.log(images[img].title); } }) .catch(function(error){console.log(error);});
MediaWiki JS
[edit ]/* get_allimages_by_date.js MediaWiki API Demos List all images in the namespace, starting from January 1, 2010, at 18:05:46 UTC. MIT License */ varparams={ action:'query', format:'json', list:'allimages', aisort:'timestamp', aistart:'2010年01月01日T18:05:46Z' }, api=newmw.Api(); api.get(params).done(function(data){ varimages=data.query.allimages, img; for(imginimages){ console.log(images[img].title); } });
Parameter history
[edit ]- v1.23: Introduced
aiprop=canonicaltitle
,aiprop=commonmetadata
,aiprop=extmetadata
- v1.20: Introduced
aisort
,aistart
,aiend
,aiuser
,aifilterbots
,aidir=newer
,aidir=older
- v1.18: Introduced
aimime
,aiprop=mediatype
- v1.17: Introduced
aiprop=userid
,aiprop=parsedcomment
- v1.14: Introduced
bitdepth
Additional notes
[edit ]- Only the most recent version of each file is returned.
- See Data formats for more information on how to properly format dates for
aisort=timestamps
See also
[edit ]- API:Images - a very similar module, but it is a
prop
, not alist
; see API:Properties and API:Lists for more details on how these two kinds of modules differ from one another. - API:Imageinfo - retrieves detailed information about image files.
- API:Stashimageinfo - retrieves information about stashed images.
- API:Fileusage - find all pages that use the given image or images.
- API:Duplicatefiles - find any duplicates of the given file or files.