Module:Mapframe: Difference between revisions

update from sandbox mainly to fix unhelpful error at Railway Museum (Western Australia)
 
imported>Uzume
strict
 
(3 intermediate revisions by 2 users not shown)
Line 9: Line 9:
-- Modue dependencies
-- Modue dependencies
local transcluder -- local copy of https://www.mediawiki.org/wiki/Module:Transcluder loaded lazily
local transcluder -- local copy of https://www.mediawiki.org/wiki/Module:Transcluder loaded lazily
-- "Module:No globals" should not be used, at least until all other modules which require this module are not using globals.
-- "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)
-- Template parameter names (unnumbered versions only)
Line 191: Line 191:
local cleanArgs = {}
local cleanArgs = {}
for key, val in pairs(argsTable) do
for key, val in pairs(argsTable) do
if type(val) == 'string' then
if type(key) == 'string'  and type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
val = val:match('^%s*(.-)%s*$')
if val ~= '' then
if val ~= '' then
-- control characters inside json need to be escaped, but stripping them is simpler
-- control characters inside json need to be escaped, but stripping them is simpler
-- See also T214984
-- See also T214984
-- However, *don't* strip control characters from wikitext or you'll break strip markers
-- However, *don't* strip control characters from wikitext (text or description parameters) or you'll break strip markers
cleanArgs[key] = (not util.matchesParam('text', key)) and val:gsub('%c',' ') or val
-- 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
end
else
else