Module:InfoboxBasic: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- | -- Keys to skip (already handled) | ||
local | local skip = { | ||
name=true, Name=true, title=true, Title=true, | |||
image=true, Image=true, | |||
color=true, Color=true, colour=true, Colour=true, | |||
class=true, style=true | |||
} | |||
local function | local function addRow(label, value) | ||
local row = tbl:tag('tr') | |||
row:tag('th'):attr('scope','row'):wikitext(labelFromKey(label)) | |||
row:tag('td'):wikitext(value) | |||
end | |||
-- Preserve the editor’s order: | |||
if parent and parent.argumentPairs then | |||
-- argumentPairs returns last→first on many installs; collect then reverse | |||
local seq = {} | |||
for key, value in parent:argumentPairs() do | |||
if not skip[key] and not tonumber(key) and not isBlank(value) then | |||
seq[#seq+1] = {key=key, value=value} | |||
end | end | ||
end | |||
for i = #seq, 1, -1 do | |||
addRow(seq[i].key, seq[i].value) | |||
end | |||
elseif parent and parent.getArgumentNames then | |||
-- Fallback: MediaWiki provides names in source order | |||
for _, key in ipairs(parent:getArgumentNames()) do | |||
local value = args[key] | |||
if not skip[key] and not tonumber(key) and not isBlank(value) then | |||
addRow(key, value) | |||
end | end | ||
end | |||
else | |||
-- Last-resort fallback (order may not be exact on very old setups) | |||
local names = {} | |||
for k,_ in pairs(args or {}) do names[#names+1] = k end | |||
for _, key in ipairs(names) do | |||
local v = args[key] | |||
if not skip[key] and not tonumber(key) and not isBlank(v) then | |||
addRow(key, v) | |||
end | end | ||
end | |||
end | end | ||
Revision as of 22:53, 1 October 2025
Documentation for this module may be created at Module:InfoboxBasic/doc
-- Keys to skip (already handled)
local skip = {
name=true, Name=true, title=true, Title=true,
image=true, Image=true,
color=true, Color=true, colour=true, Colour=true,
class=true, style=true
}
local function addRow(label, value)
local row = tbl:tag('tr')
row:tag('th'):attr('scope','row'):wikitext(labelFromKey(label))
row:tag('td'):wikitext(value)
end
-- Preserve the editor’s order:
if parent and parent.argumentPairs then
-- argumentPairs returns last→first on many installs; collect then reverse
local seq = {}
for key, value in parent:argumentPairs() do
if not skip[key] and not tonumber(key) and not isBlank(value) then
seq[#seq+1] = {key=key, value=value}
end
end
for i = #seq, 1, -1 do
addRow(seq[i].key, seq[i].value)
end
elseif parent and parent.getArgumentNames then
-- Fallback: MediaWiki provides names in source order
for _, key in ipairs(parent:getArgumentNames()) do
local value = args[key]
if not skip[key] and not tonumber(key) and not isBlank(value) then
addRow(key, value)
end
end
else
-- Last-resort fallback (order may not be exact on very old setups)
local names = {}
for k,_ in pairs(args or {}) do names[#names+1] = k end
for _, key in ipairs(names) do
local v = args[key]
if not skip[key] and not tonumber(key) and not isBlank(v) then
addRow(key, v)
end
end
end