2

I want to display images from Wikimedia Commons inside my website (as links) using the following mediawiki-api call to search for images:

https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&list=allimages&format=json&aifrom=LG%20G4&aiprop=dimensions%7Cmime&ailimit=5

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)?

eebbesen
  • 5,070
  • 8
  • 48
  • 70
Ole Albers
  • 8,715
  • 10
  • 73
  • 166
  • I think you will need [Commons API](https://commons.wikimedia.org/wiki/Commons:Commons_API) for that. – svick Aug 05 '15 at 19:07
  • IMHO the commons API gets details about the different license variants, but not, which image uses what license? – Ole Albers Aug 06 '15 at 10:50

2 Answers2

1

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"
}
Jakob
  • 3,570
  • 3
  • 36
  • 49