Module:Teste: Difference between revisions
From determinar.ia.br - Determine suas informações
Created page with "local p = {} function p.ola() return "Scribunto funcionando" end return p" |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p. | |||
return | function p.main(frame) | ||
local id = frame.args.ID or frame.args[1] | |||
local entity = mw.wikibase.getEntity(id) | |||
if not entity then | |||
return '<strong>Item não encontrado: ' .. tostring(id) .. '</strong>' | |||
end | |||
local label = entity:getLabel('pt-br') or entity:getLabel('pt') or entity:getLabel('en') or id | |||
local description = entity:getDescription('pt-br') or entity:getDescription('pt') or '' | |||
local html = mw.html.create('table') | |||
:addClass('infobox-medico') | |||
html:tag('tr') | |||
:tag('th'):attr('colspan', '2'):css('text-align', 'center'):wikitext(label) | |||
if description ~= '' then | |||
html:tag('tr') | |||
:tag('td'):attr('colspan', '2'):css('font-style', 'italic'):wikitext(description) | |||
end | |||
if entity.claims then | |||
for propertyId, claims in pairs(entity.claims) do | |||
local propLabel = mw.wikibase.label(propertyId) or propertyId | |||
local valores = {} | |||
for _, claim in ipairs(claims) do | |||
local snak = claim.mainsnak | |||
if snak and snak.datavalue then | |||
local dv = snak.datavalue | |||
local val | |||
if dv.type == 'string' then | |||
val = dv.value | |||
elseif dv.type == 'monolingualtext' then | |||
val = dv.value.text | |||
elseif dv.type == 'wikibase-entityid' then | |||
val = mw.wikibase.label(dv.value.id) or dv.value.id | |||
elseif dv.type == 'quantity' then | |||
val = dv.value.amount | |||
elseif dv.type == 'time' then | |||
val = dv.value.time | |||
else | |||
val = tostring(dv.value) | |||
end | |||
table.insert(valores, val) | |||
end | |||
end | |||
if #valores > 0 then | |||
local row = html:tag('tr') | |||
row:tag('th'):wikitext(propLabel) | |||
row:tag('td'):wikitext(table.concat(valores, ', ')) | |||
end | |||
end | |||
end | |||
return tostring(html) | |||
end | end | ||
return p | return p | ||
Latest revision as of 11:14, 1 August 2026
Documentation for this module may be created at Module:Teste/doc
local p = {}
function p.main(frame)
local id = frame.args.ID or frame.args[1]
local entity = mw.wikibase.getEntity(id)
if not entity then
return '<strong>Item não encontrado: ' .. tostring(id) .. '</strong>'
end
local label = entity:getLabel('pt-br') or entity:getLabel('pt') or entity:getLabel('en') or id
local description = entity:getDescription('pt-br') or entity:getDescription('pt') or ''
local html = mw.html.create('table')
:addClass('infobox-medico')
html:tag('tr')
:tag('th'):attr('colspan', '2'):css('text-align', 'center'):wikitext(label)
if description ~= '' then
html:tag('tr')
:tag('td'):attr('colspan', '2'):css('font-style', 'italic'):wikitext(description)
end
if entity.claims then
for propertyId, claims in pairs(entity.claims) do
local propLabel = mw.wikibase.label(propertyId) or propertyId
local valores = {}
for _, claim in ipairs(claims) do
local snak = claim.mainsnak
if snak and snak.datavalue then
local dv = snak.datavalue
local val
if dv.type == 'string' then
val = dv.value
elseif dv.type == 'monolingualtext' then
val = dv.value.text
elseif dv.type == 'wikibase-entityid' then
val = mw.wikibase.label(dv.value.id) or dv.value.id
elseif dv.type == 'quantity' then
val = dv.value.amount
elseif dv.type == 'time' then
val = dv.value.time
else
val = tostring(dv.value)
end
table.insert(valores, val)
end
end
if #valores > 0 then
local row = html:tag('tr')
row:tag('th'):wikitext(propLabel)
row:tag('td'):wikitext(table.concat(valores, ', '))
end
end
end
return tostring(html)
end
return p
