Module:TNT: Difference between revisions
From WikiOasis Meta
More actions
No edit summary |
m Reverted edit by MacFan4000 (talk) to last revision by Peterxy12 |
||
| 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 [{...}] | ||
params['zzz123']='' | if numOnly then | ||
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, | ||
}) | }) | ||
json = string.gsub(json,'"zzz123":"",?', "") | if numOnly then | ||
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('Missing JsonConfig extension; Cannot load https://commons.wikimedia.org/wiki/Data: | 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 | ||