API:Allimages/fr
Cette page fait partie de la documentation de l'API MediaWiki Action. |
Version de MediaWiki : | ≥ 1.13 |
Requête GET pour lister tous les fichiers d'images, triés soit par titre soit par date de téléversement.
Ce module peut être utilisé comme générateur .
Documentation de l'API
Exemples
Exemple 1 : récupérer les images par titre
Requête GET
Liste toutes les images de l'espace de noms en démarrant par les fichiers dont le titre commence par «
Graffiti_000
». Limite la réponse initiale seulement aux trois premières images.
Réponse
{
"batchcomplete": "",
"continue": {
"aicontinue": "Graffiti_BTER_0001.JPG",
"continue": "-||"
},
"query": {
"allimages": [
{
"name": "Graffiti_0001.JPG",
"timestamp": "2006-10-26T01: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-26T02: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-26T08: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"
}
]
}
}
Exemple de code
Python
#!/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
"""
import requests
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
<?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
/*
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
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
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){return response.json();})
.then(function(response) {
var images = response.query.allimages;
for (var img in images) {
console.log(images[img].title);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
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
*/
var params = {
action: 'query',
format: 'json',
list: 'allimages',
aifrom: 'Graffiti_000',
ailimit: '3'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var images = data.query.allimages,
img;
for ( img in images ) {
console.log( images[ img ].title );
}
} );
Exemple 2 : récupérer les images par date
Requête GET
Liste toutes les images de l'espace de noms téléversées à partir du 1er janvier 2010 à 18h05 et 46 secondes (UTC).
api.php? action=query& format=json& list=allimages& aisort=timestamp& aistart=2010-01-01T18:05:46Z [Essayez !]
Réponse
{
"batchcomplete": "",
"continue": {
"aicontinue": "20100101190633|Ryan_Baker_12-30-2009.JPG",
"continue": "-||"
},
"query": {
"allimages": [
{
"name": "DramaQueenThatGirl.jpg",
"timestamp": "2010-01-01T18: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-01T18: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-01T19: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"
}
...
]
}
}
Exemple de code
Python
#!/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
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "allimages",
"aisort": "timestamp",
"aistart": "2010-01-01T18:05:46Z"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
IMAGES = DATA["query"]["allimages"]
for img in IMAGES:
print(img["title"])
PHP
<?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-01T18: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
/*
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
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "allimages",
aisort: "timestamp",
aistart: "2010-01-01T18:05:46Z"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var images = response.query.allimages;
for (var img in images) {
console.log(images[img].title);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
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
*/
var params = {
action: 'query',
format: 'json',
list: 'allimages',
aisort: 'timestamp',
aistart: '2010-01-01T18:05:46Z'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var images = data.query.allimages,
img;
for ( img in images ) {
console.log( images[ img ].title );
}
} );
Historique des paramètres
- v1.23:
aiprop=canonicaltitle
,aiprop=commonmetadata
,aiprop=extmetadata
ajouté - v1.20:
aisort
,aistart
,aiend
,aiuser
,aifilterbots
,aidir=newer
,aidir=older
ajouté - v1.18:
aimime
,aiprop=mediatype
ajouté - v1.17:
aiprop=userid
,aiprop=parsedcomment
ajouté - v1.14:
bitdepth
ajouté
Notes additionnelles
- Seule la version la plus récente de chaque fichier est renvoyée.
- Voir Horodatages pour plus d'informations sur la manière d'écrire correctement les dates pour
aisort=timestamps
Voir aussi
- API:Images/fr - un module très similaire, mais qui est du type
prop
, et nonlist
comme celui-ci ; voir API:Properties/fr et API:Lists/fr pour les détails sur les différences entre ces deux types de modules. - API:Imageinfo/fr - récupère les informations détaillées à propos des fichiers d'images.
- API:Stashimageinfo - récupère les informations concernant les images de la zone de mise en place (stashed ).
- API:Fileusage/fr - trouve toutes les pages qui utilisent une ou plusieurs images données.
- API:Duplicatefiles/fr - recherche tous les doublons du ou des fichiers passés en paramètre.