Using External Data and the MediaWiki API to Build a List of Popular Wiki Pages

popular

For one of our internal MediaWiki installations we used the DynamicPageList extension to show a list of the most popular page on our wiki’s main page. We found it to be handy to have an at-a-glance view into what’s the most utilized content. However, we recently upgraded to a newer version of MediaWiki (1.23) and were having issues with DPL. As such our list disappeared while I worked on another solution.

What I discovered is that you can use the External Data extension paired with the MediaWiki API to produce a dynamic list of Special:PopularPages1

First to understand what the API query looks like. Here’s what I’m using:

https://yourwiki.org/w/api.php?action=query&list=querypage&qppage=Popularpages&qplimit=10&format=xml

Breaking that down, we’re asking to query (action=query) the API, return a list from a page (list=querypage) and defining which page (qppqge=Popularpages). Then we set some limits and formats (qplimit=10 and format=xml). Note: You can even use an offset (qpoffset=5) to display multiple selections of data combined with the limits.

Then, on the page you want the list to appear add the following External Data syntax.

{{#get_web_data:url=https://yourwiki.org/w/api.php?action=query&list=querypage&qppage=Popularpages&qplimit=10&format=xml
|format=XML
|data=Title=title
}}

<div>{{#display_external_table:
template=PopularPagesExtAPITable
|data=title=Title}}</div>

That syntax says get the data from the API query, format it as XML, and match up the value for Title to a local variable of title.

Then, we use #display_external_table to format the results using a template. The <div> and other syntax is for styling the results.

In the template, this case named PopularPagesExt, we have the following:

<li style="list-style-type: none;">[[{{{title}}}|{{{title}}}]]</li>

This says for each result returned in our #get_web_data query make it a list item, apply some styles (in this case removing bullets), and then use the returned value as a standard wiki link – [[Page Name|Link Text]]

The link text is the same as the name of the page. Makes sense, no?

The result is a dynamic list of Popular pages that you can place on any wiki page.

Cadillac’s new Shield

“We’ve been working on it for more than two years now, and we’ve just been going through the motions of making it, designing it, figuring out how to manufacture it, incorporating all the right details, getting the colors, the grid patterns. And putting everything together, you just kinda do your work without the overall importance of it in a way.”

http://www.coolhunting.com/design/interview-nathan-korkus-anne-marie-laverge-webb-cadillac.php

I’m a big fan of the various crests, icons, and emblems used on automobiles. They signify much about the company, each true to its own time in history, and some instantly classic and recognizable.

This was an interesting read into the work behind the design of the new Caddy crest. I had no idea that the duck-like icons weren’t ducks at all!