Module:LabelAndData
Jump to navigation
Jump to search
Documentation for this module may be created at Module:LabelAndData/doc
-- Small module for use in infoboxes to add a label and data
-- for MDWiki
-- example usage: {{#invoke:LabelAndData|main|40|[[WHO Aware]]|P12081}}
local p = {}
function p.main(frame)
local args = {}
for k, v in pairs(frame:getParent().args) do
if v ~= "" then args[k] = v end
end
for k, v in pairs(frame.args) do
if v ~= "" then args[k] = v end
end
local out = ""
local labelnumber = args[1] or args.labelnumber
local label = args[2] or args.label
local propertyId = args[3] or args.propertyId
if not (labelnumber and label) then
return nil
end
local v = frame:callParserFunction("#statements", propertyId)
-- if not found, we get an html comment beginning "<!--"
if string.sub(v, 1, 4) ~= "<!--" then
-- strip html markup: <span class="ext-UnlinkedWikibase-statements"> & <span>
local p1 = string.find(v, ">", 1, true) or 0
local p2 = string.find(v, "<", -1, true) or #v + 1
v = string.sub(v, p1 + 1, p2 - 1)
-- uppercase first letter
v = v:gsub("^%l", string.upper)
out = "| label" .. labelnumber .. " = " .. label .. "<br>"
out = out .. "| data" .. labelnumber .. " = " .. v
end
return out
end
return p