Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1123: | Строка 1123: | ||
return true | return true | ||
end | |||
local function append_table_tree_raw(parts, value) | |||
if type(value) ~= "table" or next(value) == nil then | |||
return | |||
end | |||
local keys = {} | |||
for k in pairs(value) do | |||
keys[#keys + 1] = k | |||
end | |||
table.sort(keys, function(a, b) | |||
return tostring(a) < tostring(b) | |||
end) | |||
for _, k in ipairs(keys) do | |||
local v = value[k] | |||
local key = tostring(k) | |||
if type(v) == "table" then | |||
if is_array_of_primitives(v) then | |||
local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | |||
if okJson and jsonVal then | |||
parts[#parts + 1] = key .. "=" .. to_nowiki(jsonVal) | |||
end | |||
end | |||
if next(v) ~= nil then | |||
append_table_tree_raw(parts, v) | |||
end | |||
else | |||
parts[#parts + 1] = key .. "=" .. tostring(v) | |||
end | |||
end | |||
end | end | ||
| Строка 1151: | Строка 1186: | ||
return | return | ||
end | end | ||
local idKey = choose_id_key(obj) | local idKey = choose_id_key(obj) | ||
if not idKey then | if not idKey then | ||
return | return | ||
end | end | ||
local parts = { makeTemplatePrefix() } | local parts = { makeTemplatePrefix() } | ||
if tplArgs ~= "" then | if tplArgs ~= "" then | ||
parts[#parts + 1] = tplArgs | parts[#parts + 1] = tplArgs | ||
end | end | ||
parts[#parts + 1] = tostring(idKey) | parts[#parts + 1] = tostring(idKey) | ||
local keys = {} | local keys = {} | ||
for k in pairs(obj) do | for k in pairs(obj) do | ||
| Строка 1171: | Строка 1206: | ||
end | end | ||
end | end | ||
table.sort(keys, function(a, b) | table.sort(keys, function(a, b) | ||
return tostring(a) < tostring(b) | return tostring(a) < tostring(b) | ||
end) | end) | ||
for _, k in ipairs(keys) do | for _, k in ipairs(keys) do | ||
local v = obj[k] | local v = obj[k] | ||
if k == idKey then | if k == idKey then | ||
if type(v) == "table" then | if type(k) == "string" and string.sub(k, 1, 6) == "!type:" then | ||
if type(v) == "table" then | |||
append_table_tree_raw(parts, v) | |||
elseif v ~= nil then | |||
parts[#parts + 1] = "value=" .. tostring(v) | |||
end | |||
elseif type(v) == "table" then | |||
if is_array_of_primitives(v) then | if is_array_of_primitives(v) then | ||
local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | ||
| Строка 1187: | Строка 1228: | ||
end | end | ||
end | end | ||
if next(v) ~= nil then | if next(v) ~= nil then | ||
append_table_tree(parts, k, v) | append_table_tree(parts, k, v) | ||
| Строка 1204: | Строка 1245: | ||
end | end | ||
end | end | ||
parts[#parts + 1] = "}}" | parts[#parts + 1] = "}}" | ||
calls[#calls + 1] = table.concat(parts, "|") | calls[#calls + 1] = table.concat(parts, "|") | ||