Module:Mapframe Explained

-- Note: Originally written on English Wikipedia at https://en.wikipedia.org/wiki/Module:Mapframe

------------------------------------------------------------------------------ ##### Localisation (L10n) settings ##### Replace values in quotes ("") with localised values------------------------------------------------------------------------------local L10n =

-- Modue dependencieslocal transcluder -- local copy of https://www.mediawiki.org/wiki/Module:Transcluder loaded lazily-- "strict" should not be used, at least until all other modules which require this module are not using globals.

-- Template parameter names (unnumbered versions only)-- Specify each as either a single string, or a table of strings (aliases)-- Aliases are checked left-to-right, i.e. `` is equivalent to using `` in a templateL10n.para =

-- Names of other templates this module can extract coordinates fromL10n.template =

-- Error messagesL10n.error =

-- Other stringsL10n.str =

-- Default values for parametersL10n.defaults =

-- #### End of L10n settings ####

------------------------------------------------------------------------------ Utility methods------------------------------------------------------------------------------local util =

--nil} parameter value if found, or nil if not found--function util.getParameterValue(args, param_id, suffix) suffix = suffix or if type(L10n.para[param_id]) ~= 'table' then return args[L10n.para[param_id]..suffix] end for _i, paramAlias in ipairs(L10n.para[param_id]) do if args[paramAlias..suffix] then return args[paramAlias..suffix] end end return nilend

--Trim whitespace from args, and remove empty args. Also fix control characters.@param argsTable@returns trimmed args table--function util.trimArgs(argsTable) local cleanArgs = for key, val in pairs(argsTable) do if type(key)

'string' and type(val)

'string' then val = val:match('^%s*(.-)%s*$') if val ~= then -- control characters inside json need to be escaped, but stripping them is simpler -- See also T214984 -- However, *don't* strip control characters from wikitext (text or description parameters) or you'll break strip markers -- Alternatively it might be better to only strip control char from raw parameter content if util.matchesParam('text', key) or util.matchesParam('description', key, key:gsub('^%D+(%d+)$', '%1')) then cleanArgs[key] = val else cleanArgs[key] = val:gsub('%c',' ') end end else cleanArgs[key] = val end end return cleanArgsend

--nil} - an optional suffix to apply to the value(s) from the localization key@returns true if the name matches the parameter, false otherwise--function util.matchesParam(key, name, suffix) local param = L10n.para[key] suffix = suffix or if type(param)

'table' then for _, v in pairs(param) do if (v .. suffix)

name then return true end end return false end return ((param .. suffix)

name)end

--Check if a value is affirmed (one of the values in L10n.str.affirmedWords)@param val Value to be checked@returns true if affirmed, false otherwise--function util.isAffirmed(val) if not(val) then return false end return string.find(L10n.str.affirmedWords, ' '..val..' ', 1, true) and true or falseend

--Check if a value is declined (one of the values in L10n.str.declinedWords)@param val Value to be checked@returns true if declined, false otherwise--function util.isDeclined(val) if not(val) then return false end return string.find(L10n.str.declinedWords, ' '..val..' ', 1, true) and true or falseend

--Check if the name of a template matches the known coord templates or wrappers(in L10n.template.coord). The name is normalised when checked, so e.g. the names"Coord", "coord", and " Coord" all return true.@param name@returns true if it is a coord template or wrapper, false otherwise--function util.isCoordTemplateOrWrapper(name) name = mw.text.trim(name) local inputTitle = mw.title.new(name, 'Template') if not inputTitle then return false end

-- Create (or reuse) mw.title objects for each known coord template/wrapper. -- Stored in L10n.template.title so that they don't need to be recreated -- each time this function is called if not L10n.template.titles then L10n.template.titles = for _, v in pairs(L10n.template.coord) do table.insert(L10n.template.titles, mw.title.new(v, 'Template')) end end

for _, templateTitle in pairs(L10n.template.titles) do if mw.title.equals(inputTitle, templateTitle) then return true end end

return falseend

--Recursively extract coord templates which have a name parameter.@param wikitext@returns table sequence of coord templates--function util.extractCoordTemplates(wikitext) local output = local templates = mw.ustring.gmatch(wikitext, '') local subtemplates = for template in templates do local templateName = mw.ustring.match(template, '