Module:TNT: Difference between revisions

From Test Wiki
Content deleted Content added
m Fix template
Tags: Reverted Mobile edit Mobile web edit
m 1 revision imported
Tags: Mobile edit Mobile web edit
 
(4 intermediate revisions by 4 users not shown)
Line 100: Line 100:
end
end


local numOnly = true
local params = {}
local params = {}
local paramOrder = {}
local paramOrder = {}
Line 113: Line 114:
end
end
if name then
if name then
if (
(type(name) ~= "number")
and (
(type(name) ~= "string")
or not string.match(name, "^%d+$")
)
) then
numOnly = false
end
params[name] = newVal
params[name] = newVal
table.insert(paramOrder, name)
table.insert(paramOrder, name)
Line 119: Line 129:


-- Work around json encoding treating {"1":{...}} as an [{...}]
-- Work around json encoding treating {"1":{...}} as an [{...}]
if numOnly then
params['zzz123']=''
params['zzz123']=''
end


local json = mw.text.jsonEncode({
local json = mw.text.jsonEncode({
params=params,
params=params,
paramOrder=paramOrder,
paramOrder=paramOrder,
description=data.description
description=data.description,
})
})


if numOnly then
json = string.gsub(json,'"zzz123":"",?', "")
json = string.gsub(json,'"zzz123":"",?', "")
end


return json
return json
Line 156: Line 170:
-- Give helpful error to thirdparties who try and copy this module.
-- Give helpful error to thirdparties who try and copy this module.
if not mw.ext or not mw.ext.data or not mw.ext.data.get then
if not mw.ext or not mw.ext.data or not mw.ext.data.get then
error(string.format([['''Missing JsonConfig extension, or not properly configured;

Cannot load https://commons.wikimedia.org/wiki/Data:%s.
See https://www.mediawiki.org/wiki/Extension:JsonConfig#Supporting_Wikimedia_templates''']], dataset))
end
end