Module:BucketGet: Difference between revisions
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| Line 369: | Line 369: | ||
end | end | ||
row[spec.alias .. i] = val | -- Make missing split values genuinely empty. | ||
if val == nil or val == false then | |||
val = "" | |||
elseif type(val) == "string" then | |||
val = mw.text.trim(val) | |||
end | |||
row[spec.alias .. i] = val | |||
end | end | ||
end | end | ||
| Line 481: | Line 488: | ||
local function normalizeUserformatValue(value) | local function normalizeUserformatValue(value) | ||
-- Missing values. | -- Missing values. | ||
if value == nil | if value == nil or value == false then | ||
return '' | return '' | ||
end | end | ||
| Line 498: | Line 500: | ||
local s = mw.text.trim(tostring(v)) | local s = mw.text.trim(tostring(v)) | ||
if s ~= '' then | -- Ignore empty/null array entries. | ||
local lower = mw.ustring.lower(s) | |||
if s ~= '' | |||
and lower ~= 'null' | |||
and lower ~= 'nil' | |||
and lower ~= 'false' | |||
and lower ~= '<i>null</i>' then | |||
table.insert(values, s) | table.insert(values, s) | ||
end | end | ||
| Line 510: | Line 520: | ||
value = mw.text.trim(tostring(value)) | value = mw.text.trim(tostring(value)) | ||
-- Treat common null representations as empty. | -- Treat all common empty/null representations as empty. | ||
local lower = mw.ustring.lower(value) | local lower = mw.ustring.lower(value) | ||
| Line 516: | Line 526: | ||
or lower == 'null' | or lower == 'null' | ||
or lower == 'nil' | or lower == 'nil' | ||
or lower == 'false' then | or lower == 'false' | ||
or lower == '<i>null</i>' then | |||
return '' | return '' | ||
end | end | ||
-- Remove non-breaking spaces | -- Remove non-breaking spaces. | ||
value = value:gsub('\194\160', ' ') | value = value:gsub('\194\160', ' ') | ||
| Line 549: | Line 559: | ||
for _, col in ipairs(columns) do | for _, col in ipairs(columns) do | ||
local value = | local value = | ||
normalizeUserformatValue(row[col.alias]) | normalizeUserformatValue( | ||
row[col.alias] | |||
) | |||
local placeholder = | local placeholder = | ||
| Line 810: | Line 822: | ||
local value = row[fmt_info.column] | local value = row[fmt_info.column] | ||
if value == nil then | -- Empty values stay empty. | ||
if value == nil | |||
or value == false | |||
or ( | |||
type(value) == "string" | |||
and mw.text.trim(value) == "" | |||
) | |||
or ( | |||
type(value) == "string" | |||
and mw.ustring.lower( | |||
mw.text.trim(value) | |||
) == "<i>null</i>" | |||
) then | |||
row[fmt_info.column] = '' | |||
elseif type(value) == "table" then | elseif type(value) == "table" then | ||
| Line 817: | Line 842: | ||
for _, v in ipairs(value) do | for _, v in ipairs(value) do | ||
local | local clean = v | ||
if clean == nil or clean == false then | |||
clean = "" | |||
elseif type(clean) == "string" then | |||
clean = mw.text.trim(clean) | |||
end | |||
local lower = | |||
mw.ustring.lower( | |||
tostring(clean) | |||
) | ) | ||
table.insert( | if clean ~= "" | ||
and lower ~= "null" | |||
and lower ~= "nil" | |||
and lower ~= "false" | |||
and lower ~= "<i>null</i>" then | |||
local formatted = | |||
fmt_info.format:gsub( | |||
"%%s", | |||
function() | |||
return clean | |||
end | |||
) | |||
table.insert( | |||
formatted_values, | |||
formatted | |||
) | |||
end | |||
end | end | ||
| Line 1,864: | Line 1,909: | ||
if group_by_str then | if group_by_str then | ||
local group_by_cols = | local group_by_cols = | ||
parseGroupBy( | parseGroupBy(group_by_str) | ||
local agg_specs = | local agg_specs = | ||