Module:Teste: Difference between revisions

From determinar.ia.br - Determine suas informações
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
  function p.testarItem()
 
      local entity = mw.wikibase.getEntity('Q1')
function p.main(frame)
      if entity then
    local id = frame.args.ID or frame.args[1]
          return "Entidade encontrada! Label: " .. (entity.labels.pt and entity.labels.pt.value or "sem label pt")
    local entity = mw.wikibase.getEntity(id)
      else
 
          return "Entidade NÃO encontrada — self-client não está funcionando"
    if not entity then
      end
        return '<strong>Item não encontrado: ' .. tostring(id) .. '</strong>'
  end
    end
  return p
 
    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

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