11.314
suntingan
Tidak ada ringkasan suntingan Tag: Dikembalikan |
Tidak ada ringkasan suntingan Tag: Pengembalian manual |
||
Baris 50: | Baris 50: | ||
id = mw.text.trim(v) | id = mw.text.trim(v) | ||
elseif type(k) == 'number' then | elseif type(k) == 'number' then | ||
params | table.insert(params, mw.text.trim(v)) | ||
elseif k == 'lang' and v ~= '_' then | elseif k == 'lang' and v ~= '_' then | ||
lang = mw.text.trim(v) | lang = mw.text.trim(v) | ||
Baris 96: | Baris 96: | ||
local data = loadData(dataset) | local data = loadData(dataset) | ||
local names = {} | local names = {} | ||
for _, field in | for _, field in pairs(data.schema.fields) do | ||
table.insert(names, field.name) | table.insert(names, field.name) | ||
end | end | ||
local params = {} | local params = {} | ||
local paramOrder = {} | local paramOrder = {} | ||
for _, row in | for _, row in pairs(data.data) do | ||
local newVal = {} | local newVal = {} | ||
local name = nil | local name = nil | ||
for pos, | for pos, val in pairs(row) do | ||
local columnName = names[pos] | |||
if columnName == 'name' then | if columnName == 'name' then | ||
name = | name = val | ||
else | else | ||
newVal[columnName] = | newVal[columnName] = val | ||
end | end | ||
end | end | ||
if name then | if name then | ||
params[name] = newVal | params[name] = newVal | ||
table.insert(paramOrder, name) | table.insert(paramOrder, name) | ||
Baris 129: | Baris 120: | ||
-- Work around json encoding treating {"1":{...}} as an [{...}] | -- Work around json encoding treating {"1":{...}} as an [{...}] | ||
params['zzz123']='' | |||
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":"",?', "") | |||
return json | return json | ||
Baris 170: | Baris 157: | ||
-- 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( | error('Missing JsonConfig extension; Cannot load https://commons.wikimedia.org/wiki/Data:' .. dataset) | ||
Cannot load https://commons.wikimedia.org/wiki/Data: | |||
end | end | ||