FANDOM


This script is for PERSONAL use only!

You are free to install this script for yourself, but it is not allowed to be used wiki-wide (e.g., in MediaWiki:Common.js or MediaWiki:Wikia.js), as it would violate Fandom's Terms of Use.
(See the customization policy)

DPLquery is a JavaScript library that generates JSON data queries with DPL. It enables data extraction from templates and categories. Note that DPL must be available on the wiki for the library to work.

Usage

1. Importing the script

To use DPLquery, you need to import it into your script. You can listen for the dev.dpl event using mw.hook.

// register the hook before the import to avoid race conditions
mw.hook('dev.dpl').add(function (Dpl) {
    // Dpl is a shortcut to window.dev.Dpl
});
importArticle({ type: 'script', article: 'u:dev:MediaWiki:DPLquery.js' });

2. DPL parameter configuration

The script registers a window.dev.Dpl constructor which creates an instance of Dpl. The constructor accepts configuration options like so:

example = {};
example.dpl = new Dpl({
    ordermethod: 'size',
    category: 'JavaScript'
});

N.B: Fandom uses DynamicPageList 2.3.0. Some parameters have been internally blacklisted in the library - see the library code if your query reports that error.

3. Querying your DPL data

After you create your new Dpl object, use the query method to fetch your data. This requires an object with the following keys:

  • template - template name without namespace
  • data - array listing template parameters to extract

There are two ways to retrieve the data from the query:

  • it accepts a second callback parameter
  • it returns a thenable jQuery Deferred object
// Continuing from [[2. DPL parameter configuration]]
example.dpl.query({
    template: 'Infobox JavaScript',
    parameters: [
        'Description',
        'Author'
    ]
}, function(d) {
    // Have fun with your template's data!
});

Code summary

example = {};
mw.hook('dev.dpl').add(function (Dpl) {
    example.dpl = new Dpl({
        ordermethod: 'size',
        category: 'JavaScript'
    });
    example.dpl.query({
        template: 'Infobox JavaScript',
        data: [
            'Description',
            'Author'
        ]
    }, function(d) {
        localStorage.devScripts = JSON.stringify(d);
    });
});
importArticle({ type: 'script', article: 'u:dev:DPLquery.js' });

Changelog

June 2, 2018 (v1.0)
User:MACH-59330: Published on Fandom Developers Wiki.
June 2, 2018 (v1.1)
User:MACH-59330: Fix for wikitext and HTML data encoding.

TODO

  • Reduce dependency on Dpl.query method
  • Support for Lua output through some mode parameter
  • Data dump automation through MediaWiki API
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+