Fandom

Wikia Developers Wiki

Portable infoboxes

861pages on
this wiki
Add New Page
Talk0 Share
90210-infobox-light

Portable infoboxes are a way to create infoboxes on Wikia using simplified XML markup. This page details how to interact with these infoboxes using MediaWiki's built-in APIs.

Using the API

While there is no officially announced API for portable infoboxes, it is still possible to access some data related to them.

Listing all infoboxes

A list of all portable infoboxes on the wiki can be obtained by using the querypage API to access Special:AllInfoboxes, e.g.:

http://dev.wikia.com/api.php?action=query&list=querypage&qppage=AllInfoboxes&qplimit=500&format=json

Note: this data is cached and may not be up to date.

Listing all pages with a specific infobox

One simple way to retrieve all pages with an infobox is to use the embeddedin API to retrieve all pages that transclude the template, e.g.:

http://dev.wikia.com/api.php?action=query&list=embeddedin&eititle=Template:Infobox&eilimit=500&format=json

Listing all infoboxes on a page

To get data about the infoboxes on a specific page or group of pages, one can query the pageprops API:

// JavaScript
 
var config = {
    action: "query",
    prop: "pageprops",
    titles: [/* pages go here */].join("|")
};
 
function printInfoboxJson(data) {
    var pages = data.query.pages;
 
    Object.keys(pages).forEach(function (page) {
        console.log(pages[page].pageprops.infoboxes);
    });
}
 
new mw.Api().get(config).then(printInfoboxJson);

It is important to note that the API returns the infobox data as a string, and not as JSON. As such the above code retrieves information about the given pages, and logs a stringified JSON array for each. Those arrays contain the information added to each infobox's tags, and will look something like this:

[{
    "data": [{
        "type": "title",
        "data": {
            "value": "AjaxRC"
        }
    }, {
        "type": "data",
        "data": {
            "label": " Type",
            "value": " <a href=\"\/wiki\/Category:JavaScript\" title=\"Category:JavaScript\">JavaScript<\/a>"
        }
    }, {
        "type": "data",
        "data": {
            "label": "Description",
            "value": "Advanced auto refreshing recent changes and watchlist"
        } 
    }],
    "sources": ["Title", "type", "Description"]
}]
Actual output: http://dev.wikia.com/api.php?action=query&prop=pageprops&titles=AjaxRC&format=json

The "sources" array contains the parameter names used in the actual page and / or template.

Note that the data in the infobox is not saved as wikitext but rather as html, and wikitext like [[:Category:JavaScript]] is converted to:

<a href=\"\/wiki\/Category:JavaScript\" title=\"Category:JavaScript\">JavaScript<\/a>"

See also

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.