Module:Coordinates
|
|
This Lua module is used on a very large number of pages. To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its /sandbox or /testcases subpages. The tested changes can then be added to this page in one single edit. Please consider discussing any changes on the talk page before implementing them. |
|
|
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Template:Tracks and uses Wikidata
| This module depends on the following other modules: |
Lua error in Module:TNT at line 159: Missing JsonConfig extension; Cannot load https://commons.wikimedia.org/wiki/Data:I18n/Uses TemplateStyles.tab.
Note: The code which this module's main function (coord) outputs is directly parsed and/or manipulated by Module:Location map and other functions of this module itself (coord2text and coordinsert). If the structure of the output changes (for example, to use the <mapframe> and <maplink> tags), please update the aforementioned scripts as well.
Using the module with coordinsert
When using the {{Coord}} template inside another template, like an infobox, there may be parameters (like type:airport) which should be added automatically. To do so, do something like this:
{{#if:{{{coordinates|}}}|{{#invoke:Coordinates|coordinsert|{{{coordinates|}}}|parameter1:value1|parameter2:value2|parameter3:value3…}}|
Do not add more vertical bars | than necessary.
Using the module with coord2text to extract latitude or longitude
Developers maintaining legacy code may need to extract latitude or longitude to use a parameters in other code, or a mathematical expression. The module's "coord2text" function can be used to extract data from the {{Coord}} template. To extract the latitude from a Coord template, use:
{{#invoke:coordinates|coord2text|{{Coord|57|18|22|N|4|27|32|E}}|lat}} → Lua error at line 1: attempt to index global 'coordinates' (a nil value).
To extract the longitude, use:
{{#invoke:coordinates|coord2text|{{Coord|57|18|22|N|4|27|32|E}}|long}} → Lua error at line 1: attempt to index global 'coordinates' (a nil value).
Modules using this module directly
Tracking categories
- Category:Pages with malformed coordinate tags (0)
- Category:Coordinates not on Wikidata (0)
- Category:Coordinates on Wikidata (0)
- Category:Coordinates on Wikidata set to no value (0)
- Category:Coordinates on Wikidata set to unknown value (0)
function coordinates._coord( args )
local orig_args = args
-- Get arguments (wrapped by Template:Coord)
args = require('Module:Arguments').getArgs( orig_args, {
wrappers = 'Template:Coord',
removeBlanks = false
} )
-- Default display mode
local display = args.display or 'inline,title'
if display:find('^i$') then display = 'inline' end
if display:find('^it$') or display:find('^ti$') then display = 'inline,title' end
if display:find('^t$') then display = 'title' end
-- Parse the coordinates (same logic as before)
local contents, backward = formatTest( args )
-- Optional notes
local notes = args.notes or ''
-- Build output
local output = {}
if display:find('inline') then
table.insert( output, '<span class="geo-inline">' .. contents .. notes .. '</span>' )
end
if display:find('title') then
-- Simple title indicator (no Wikidata, no categories)
table.insert( output,
'<span class="geo-title" style="display:none">Coordinates: ' ..
contents .. notes .. '</span>'
)
end
-- Never call the #coordinates parser function on private wikis
-- (it is the source of the validator error when Wikibase is absent)
-- So we skip the whole "nosave/primary" logic completely.
return table.concat( output )
end