Search code examples
phpwikipedia-apimediawiki-api

Finding images in Wikipedia that are being used across various articles


I'm trying to query wikipedia using MediaWiki api with php (and Curl), in order to search for images that are being used in various articles by a specific search term. For example - search for 'panda', but get only images that are being used somewhere and be able to go to the articles. I am able to search for images generally using:

https://en.wikipedia.org/w/api.php?action=query&list=allimages&ailimit=100&aifrom=Panda&aiprop=url&format=xmlfm

and I know that basically this should show the usage:

https://commons.wikimedia.org/w/api.php?action=query&prop=images&list=imageusage&iutitle=File:MY_IMAGE_NAME&format=xmlfm

Trying the above does not give me the result I need - I can see a list of images, but I cannot know if or where they are being used.

Can anyone assist?


Solution

  • list=imageusage does not show cross-wiki usage; you'll need prop=globalusage for that. Which is also conveniently a prop module, so it can be folded into the first query using allimages as a generator:

    action=query&generator=allimages&gailimit=100&gaifrom=Panda&prop=globalusage

    (Omitted prop=images since it does not seem to have any useful purpose.)