Extension:Cargo/Other features

From MediaWiki.org
Jump to: navigation, search
Cargo - navigation
Basics Main pageExtension:Cargo (talk) · Download and installationExtension:Cargo/Download and installation · Quick start guideExtension:Cargo/Quick start guide · Other documentationExtension:Cargo/Other documentation · SMW migration guideExtension:Cargo/SMW migration guide
Using Cargo Storing dataExtension:Cargo/Storing data · Querying dataExtension:Cargo/Querying data (Display formatsExtension:Cargo/Display formats) · Browsing dataExtension:Cargo/Browsing data · Exporting dataExtension:Cargo/Exporting data · Other featuresExtension:Cargo/Other features
Resources for help Common problemsExtension:Cargo/Common problems · Known bugs and planned featuresExtension:Cargo/Known bugs and planned features · Getting supportExtension:Cargo/Getting support
About Cargo Authors and creditsExtension:Cargo/Authors and credits · Version historyExtension:Cargo/Version history · Sites that use CargoExtension:Cargo/Sites that use Cargo · Cargo and Semantic MediaWikiExtension:Cargo/Cargo and Semantic MediaWiki · FAQExtension:Cargo/FAQ

"Purge cache" tab[edit]

MediaWiki does extensive caching of its pages, for performance reasons. This can impact pages that display Cargo queries, in that data that has recently been added or changed will often not show up yet in other pages that query it. MediaWiki lets you purge the cache of any page by going to the URL "action=purge" for that page, after which you should see the correct, most recent data in any queries on that page. However, MediaWiki does not offer any convenient way to get to that URL. For that purpose, Cargo defines a tab/dropdown action, "Purge cache". It is viewable only to those users who have the "purge" permission, which normally is all users in the "sysop" group. (In truth, all users can purge a page's cache, though non-admins need to confirm by hitting "OK" before the purge happens; thus the "purge" permission might be better named "one-step purge".)

The "Purge cache" tab is equivalent to the "Refresh" tab from Semantic MediaWiki; in fact, if SMW is already installed, the "Purge cache" tab will not show up at all, since it is redundant.

Displaying maps[edit]

Within templates that hold coordinates, it is usually not very helpful to simply display those coordinates; the vast majority of people will have no knowledge of where in the world a certain set of coordinates are. Rather, it is much preferable to display a map. For that, Cargo defines the parser function #cargo_display_map. It takes in coordinates, as well as a few optional parameters, and displays a map for that one point.

The parameters for #cargo_display_map are:

  • point= - takes in a set of coordinates (mandatory).
  • service= - the mapping service used; can be googlemaps (for Google Maps) or openlayers (for OpenLayers). OpenLayers is the default service.
  • zoom= - sets the zoom level. For both Google Maps and OpenLayers, the zoom level is an integer number between 1 and around 20, with higher numbers being more zoomed in. The default value for this parameter is 16 for both mapping services.
  • height= - sets the height of the map; the default value is 400px.
  • width= - sets the width of the map; the default value is 700px.

If you are using Google Maps, you may need to get an API key for it to work - once you get an API key, you should set it in LocalSettings.php via the "$wgCargoGoogleMapsKey" variable.

The standard usage of #cargo_display_map is within a template, where point= takes in a template parameter. However, it can be used to display hardcoded maps as well.

Lua support[edit]

You can call Cargo queries from within Lua modules defined by the Scribunto extension. To do that, just place something like the following code in a module:

local p = {}
local cargo = mw.ext.cargo

function p.Main( frame )
    tables = 'table1, table2, etc.'
    fields = 'field1=alias1,field2=alias2, etc.'
    -- optional parameters are grouped in one table
    -- you can omit any or all of them, except joinOn if you use more than one table
    local args = {
        where = 'table1.fieldE="some value", etc.'
        join = 'table1.fieldA = table2.fieldB,table2.fieldC=table3.fieldD, etc.',
        groupBy = 'table1.fieldG',
        having = 'table1.fieldG="some value", etc.',
        orderBy = 'table2.fieldF, etc.',
        limit = some number,
    local result = cargo.query( tables, fields, args )
--  . . .