API:Showing interesting content

Showing interesting pages
You can query a curated selection of quality content using the FeaturedFeeds extension, which provides daily feeds of quality wiki content in RSS or Atom format. (This is contrast to the Recent changes stream, which on an active wiki is a firehose of non-stop changes.

How it works on Wikimedia wikis
mw:Extension:FeaturedFeeds/WMF deployment describes the feed names available on WMF wikis, including:
 * Today's Featured Article on most wikipedias
 * Did you know... on many wikis XXX why an error on English wikipedia?
 * On this day on many wikis
 * Quote of the day on wikiquote
 * Media of the Day on commons

Editors on each wiki select this content and often present it on the main page of the wiki, for example English Wikiquote, and other pages. They organize and name this featured content differently on each wiki. Using the featuredfeed API module you can retrieve an organized feed of the information. Simply make a request to the wiki that has a featured feed you like, giving it as the  parameter.

Example:

Note the featuredfeed API module ignores the  parameter if the API request succeeds. You should still specify  so you can check for errors such as , but if the request succeeds you always get XML back, either in RSS or Atom format. You can simply display this as is in most web browsers, or you can parse it. There are RSS parsing libraries available for most languages. You will probably parse the feed to show the most recent item in it.

Caution
Before offering this feature in a language, you should check to see if that language's wiki implements the feed.

Clients of featuredfeeds
The Wikipedia channel for IFTTT] provides "if this, then that" recipes from this such as The recipes use triggers such as "Word of the day". These run on a web service written in Python using Flask. The triggers query the corresponding featuredfeed as described above, using the feedparser Python library. For performance the server caches the information from the feed.
 * Send yourself a weekly vocabulary list of Wikipedia words of the day
 * Set your Android wallpaper to the Wikipedia picture of the day

Alternative approaches to Picture of the Day
The RSS feed returns an XML description of a series of Pictures of the Day. The first  element contains the HTML to display this picture and its caption at a reasonable size. But if you want to show the original image or at your own size, you have to look inside this HTML for the href attribute of the   tag.

commons:Commons:Picture of the day explains the templates that the Commons administrators update for each Picture of the day. If you can tolerate the risk of your client breaking, you can directly access these templates. This article discusses two approaches:

Query the first image in the Picture of the day template
https://github.com/jdlrobson/pushipedia takes this different approach. It relies on commons PotD putting the current image in Template:Potd, so it queries the images property of that page:

Example: and assumes  holds the relevant image (on 2015-08-02, ). Besides fragility, the downside is you have to figure out yourself when the picture changes.

TODO it seems this API request doesn't always resolve to the template's current contents, since the template contents don't change.

Parse the Potd/YYYY-MM-DD template
The Picture of the day page also says
 * ''The image can be accessed using

 File: ''

In other words, commons:Template:Potd/2015-08-02 evaluates to "Giant Manta AdF.jpg". (It actually contains a template that provides information about that Picture of the day if you visit it directly.)

You can ask an API to parse this template for you. You could compute YYYY-MM-DD yourself or ask the API to expand the magic words, etc.

You can use the parsoid API or the RESTBase v1 translation endpoint https://commons.wikimedia.org/api/rest_v1/transform/wikitext/to/html to parse such a string, but for low-volume requests it's probably easiest to request  and specify what you want to return:


 * API request to parse

This produces HTML with a link to the Picture of the day, so we query for the  property of the parsed wikitext. In  this returns a one-element array of links; in the single array element,   (on 2015-08-02) is the full title File:Giant Manta AdF.jpg, and   is true unless the image were to be deleted or moved.

You can ask the parser to parse any wikitext. So instead you could ask it to actually parse wikitext of an invocation of the image (no leading colon before "File"):


 * |text&contentmodel=wikitext API request to parse

This produces HTML with the image in it, so we query for the  property which on 2015-08-02 returns "Giant Manta AdF.jpg". You can also query for the  parser prop which has the HTML with the   tag that has the path to the actual jpeg: you could inspect this, or simply render this HTML in your client application and see the image. The benefit of the latter over parsing the  RSS response is you can provide wikitext that directs the parser to generate the HTML you prefer, using image wikitext parameters. For example, set an image width, or request the image caption.

Next steps
Try the various feeds, use their content however you wish.

The editors who curate these featured articles would love to know how you're using them, let them know on the talk page of the feature.