FANDOM


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.:

https://dev.fandom.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.:

https://dev.fandom.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:

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);
    });
}
 
function makeQuery() {
    new mw.Api()
        .get(config)
        .done(printInfoboxJson);
}
 
mw.loader.using('mediawiki.api').then(makeQuery);

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: https://dev.fandom.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

Community content is available under CC-BY-SA unless otherwise noted.

Fandom may earn an affiliate commission on sales made from links on this page.

Stream the best stories.

Fandom may earn an affiliate commission on sales made from links on this page.

Get Disney+