I want to display images from Wikimedia Commons inside my website (as links) using the following mediawiki-api call to search for images:
This returns a search result containing all images that match my query. But what I do not see in that response is the license information. I can retrieve the uploader information using "user" inside the aiprop, but how do I retrieve the license information (like CC-BY-SA)?
As already answered, the extmetadata API extension provides license information. The result format is a bit verbose and some fields are duplicated with different spellings, so I created the PHP wrapper image-attribution:
$attribution = commons_image_attribution("Loewe_frontal.JPG");
$credit = $attribution['credit'];
The response has following structure (here given as JSON):
{
"src": "https://upload.wikimedia.org/wikipedia/commons/a/ac/Loewe_frontal.JPG",
"url": "https://commons.wikimedia.org/wiki/File:Loewe_frontal.JPG",
"description": "Portrait of a young lion (Panthera leo), taken at Tierpark Hellabrunn, Munich.",
"creator": "Martin Falbisoner",
"date": "2012-07-14 15:39:06",
"attribution": true,
"license": "CC BY-SA 3.0",
"credit": "CC BY-SA 3.0: Martin Falbisoner"
}