Fetching Featured Images from Wikimedia Commons

Image for post
Image for post
Recently featured image on Commons: https://bit.ly/2IyitSG

Wikimedia Commons features many images regularly on its main page. As described by Commons,

Featured pictures are images from highly skilled photographers and illustrators that the Wikimedia Commons community has chosen as some of the highest quality on the site.

Getting an image featured is quite difficult as the statistics suggest.

There are currently 11,192 of such images in the Commons repository which is roughly 0.024% of the available images (46,591,843).

In the Wikimedia Commons Android app, we thought showing these featured images in the app would be a good addition as it would:

  • Show users what a great Commons picture is

I started exploring the API that would let us fetch featured images and then we could consume it in the app. I came across the MediaWiki Generator API.

Check out the following API call that returns the first 10 features images from the API. https://bit.ly/2KRXg4l

Here’s a screenshot from the app showing the featured images from Commons:

Image for post
Image for post
Featured Images Screen

Let us discuss the parameters that the API takes:

  • action: query which is common param for all MediaWiki API calls

We wanted to display all the images in a category instead of showing just the first 10. So we used the continue query of MediaWiki API. To get more data, you use the query-continue value in the response.

The query-continue node will contain a subnode for each module used in the query that needs continuation, and these subnodes will contain properties to be used when making the followup "continuation" query. Note that clients should not be depending on the particular property names given for continuation of any module or the format of the values returned for continuation, as these may change.

Continue query: https://bit.ly/2Idkhgt

Moreover, the implementation in generic enough to load images from any category of Commons.

CategoryImagesActivity.startYourself(this, "Page title", "Category name");

Check out the full implementation for this feature here:

The changes are now merged to master and you could take a pull of the code base and run it for yourself. :)

Make sure you give this post 50 claps and follow me if you enjoyed this post and want to see more!

Written by

Grad Student at ASU | Student Researcher at The Luminosity Lab | Ex Senior Software Engineer, Zeta | Volunteer, Wikimedia Foundation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store