Módulo:Wikidata: diferenças entre revisões

Fonte: Enciclopédia de conhecimento da Igreja de Deus
Saltar para a navegação Saltar para a pesquisa
Criou a página com "-- vim: set noexpandtab ft=lua ts=4 sw=4: require('strict') local p = {} local debug = false ------------------------------------------------------------------------------ -- module local variables and functions local wiki = { langcode = mw.language.getContentLanguage().code } -- internationalisation local i18n = { ["errors"] = { ["property-not-found"] = "Propriedade não encontrada.", ["entity-not-found"] = "Entidade Wikidata desconhecida.", ["unknown-claim-t..."
 
Sem resumo de edição
 
(Há uma edição intermédia do mesmo utilizador que não está a ser apresentada)
Linha 1: Linha 1:
-- vim: set noexpandtab ft=lua ts=4 sw=4:
require('strict')
local p = {}
local p = {}
local debug = false
local lang = 'pt'
------------------------------------------------------------------------------
 
-- module local variables and functions
local item = nil -- o elemento Wikidata ligado
local wiki =
local localdata = {}-- guarda parâmetros passados à predefinição
{
local page = { -- guarda parâmetros da página mostrados na infocaixa
langcode = mw.language.getContentLanguage().code
        name = mw.title.getCurrentTitle().prefixedText,
    namespace = mw.title.getCurrentTitle().namespace
}
}
-- internationalisation
local maincolor, secondcolor, thirdcolor = '#E1E1E1', '#E1E1E1', '#000000'
local i18n =
-- o objecto principal a mostrar
{
local infobox = mw.html.create('div')
["errors"] =
 
{
-- objetos secundários a mostrar
["property-not-found"] = "Propriedade não encontrada.",
local maintenance = '' -- cadeia devolvida com o módulo : cats de monitoramento
["entity-not-found"] = "Entidade Wikidata desconhecida.",
local externaltext = '' -- para exemplo com coordenadas no título
["unknown-claim-type"] = "Tipo claim com valor desconhecido.",
-- modules importados
["unknown-entity-type"] = "Tipo entity com valor desconhecido.",
local linguistic = require "Módulo:Linguística"
["qualifier-not-found"] = "Qualificador não encontrado.",
local wd = require 'Módulo:Infobox/Wikidata'
["site-not-found"] = "Projeto Wikimedia não encontrado.",
local valueexpl = wd.translate("activate-query")
["unknown-datetime-format"] = "Formato datatempo desconhecido.",
local CategorizacaoABeAD = require('Módulo:Categorização AD e AB de outras wikis')
["local-article-not-found"] = "Artigo ainda não se encontra disponível nesta wiki."
local i18n = {
},
        ['see doc'] = 'Documentação da predefinição',
["datetime"] =
        ['edit'] = 'editar',
{
        ['edit code'] = 'editar código-fonte',
-- $1 is a placeholder for the actual number
        ['edit item'] = 'editar Wikidata',
[0] = "$1 bilhão de anos",  -- precision: billion years
        ['tracking cat'] = "!Páginas que utilizam dados no Wikidata",
[1] = "$100 milhões de anos", -- precision: hundred million years
        ['invalid block type'] = "Bloco de dados inválidos dentro do módulo infobox",
[2] = "$10 milhões de anos", -- precision: ten million years
        ['default cat'] = "!Monitoramento das infobox",
[3] = "$1 milhão de anos",  -- precision: million years
[4] = "$100,000 anos",  -- precision: hundred thousand years
[5] = "$10,000 anos",  -- precision: ten thousand years
[6] = "$1 milênio",    -- precision: millennium
[7] = "século $1",    -- precision: century
[8] = "década de $10",  -- precision: decade
-- the following use the format of #time parser function
[9]  = "Y",    -- precision: year,
[10] = "F Y",    -- precision: month
[11] = "F j, Y",  -- precision: day
[12] = "F j, Y ga",  -- precision: hour
[13] = "F j, Y g:ia",  -- precision: minute
[14] = "F j, Y g:i:sa",  -- precision: second
["beforenow"] = "$1 AEC", -- how to format negative numbers for precisions 0 to 5
["afternow"] = "$1 EC",  -- how to format positive numbers for precisions 0 to 5
["bc"] = '$1 "AEC"',  -- how print negative years
["ad"] = "$1",    -- how print positive years
-- the following are for function getDateValue() and getQualifierDateValue()
["default-format"] = "dmy", -- default value of the #3 (getDateValue) or
-- #4 (getQualifierDateValue) argument
["default-addon"] = "a.C.", -- default value of the #4 (getDateValue) or
-- #5 (getQualifierDateValue) argument
["prefix-addon"] = false, -- set to true for languages put "BC" in front of the
-- datetime string; or the addon will be suffixed
["addon-sep"] = " ",  -- separator between datetime string and addon (or inverse)
["format"] =    -- options of the 3rd argument
{
["mdy"] = "F j, Y",
["my"] = "F Y",
["y"] = "Y",
["dmy"] = "j F Y",
["ymd"] = "Y-m-d",
["ym"] = "Y-m"
}
},
["monolingualtext"] = '<span lang="%language">%text</span>',
["warnDump"] = "[[Categoria:!Função chamada 'Dump' do módulo Wikidata]]",
["ordinal"] =
{
[1] = "st",
[2] = "nd",
[3] = "rd",
["default"] = "th"
}
}
}
--require("Module:i18n").loadI18n("Module:Wikidata/i18n", i18n)
 
-- got idea from [[:w:Module:Wd]] used by wikidata
local function addWikidataCat(prop)
-- this function needs to be internationalised along with the above:
          maintenance = maintenance .. wd.addTrackingCat(prop)
-- takes cardinal numer as a numeric and returns the ordinal as a string
-- we need three exceptions in English for 1st, 2nd, 3rd, 21st, .. 31st, etc.
local function makeOrdinal (cardinal)
local ordsuffix = i18n.ordinal.default
if cardinal % 10 == 1 then
ordsuffix = i18n.ordinal[1]
elseif cardinal % 10 == 2 then
ordsuffix = i18n.ordinal[2]
elseif cardinal % 10 == 3 then
ordsuffix = i18n.ordinal[3]
end
-- In English, 1, 21, 31, etc. use 'st', but 11, 111, etc. use 'th'
-- similarly for 12 and 13, etc.
if (cardinal % 100 == 11) or (cardinal % 100 == 12) or (cardinal % 100 == 13) then
ordsuffix = i18n.ordinal.default
end
return tostring(cardinal) .. ordsuffix
end
end
local function printError(code)
 
return '<span class="error">' .. (i18n.errors[code] or code) .. '</span>'
local function expandQuery(query)
          local value, number -- valor a mostrar, nome dos valores para o rótulo
        if not query.entity then
                query.entity = localdata.item
        end
        if not query.conjtype then
                query.conjtype = 'new line'
        end
        local claims = wd.getClaims(query)
                  if (not claims) then
              return nil
        end
        return wd.formatAndCat(query), #claims -- para acordo do plural
end
end
local function parseDateFormat(f, timestamp, addon, prefix_addon, addon_sep)  
 
local year_suffix
local function getWikidataValue(params, wikidataparam)
local tstr = ""
          -- Mostrar o valor Wikidata para o valor, quer no parâmetro "wikidata" ou no parâmetro "property"
local lang_obj = mw.language.new(wiki.langcode)
        if not localdata.item then
local f_parts = mw.text.split(f, 'Y', true)
                return nil
for idx, f_part in pairs(f_parts) do
        end
year_suffix = ''
 
if string.match(f_part, "x[mijkot]$") then
        if params.blockers then -- blockers are local parameters that disable the wikidata query
-- for non-Gregorian year
                  local blockers = params.blockers
f_part = f_part .. 'Y'
              if (type(blockers) == 'string') then
elseif idx < #f_parts then
                      blockers = {blockers}
-- supress leading zeros in year
              end
year_suffix = lang_obj:formatDate('Y', timestamp)
              for i, blocker in ipairs(blockers) do
year_suffix = string.gsub(year_suffix, '^0+', '', 1)
                      if localdata[blocker] then
end
                                  return nil
tstr = tstr .. lang_obj:formatDate(f_part, timestamp) .. year_suffix
                  end
end
              end
if addon ~= "" and prefix_addon then
        end
return addon .. addon_sep .. tstr
 
elseif addon ~= "" then
        local v, valnum -- o valor a retornar e o número de valores (para concordância gramatical)
return tstr .. addon_sep .. addon
else
    if not wikidataparam then -- por padrão o valor wikidata está no parâmetro "wikidata" mas nas estruturas compostas como "title", existem vários parâmetros wikidata
return tstr
              wikidataparam = 'wikidata'
end
        end
 
        if params[wikidataparam] then
              if type(params[wikidataparam]) == 'function' then
                      v, valnum = params[wikidataparam](localdata.item)
            elseif type(params[wikidataparam]) == 'table' then
                          v, valnum = expandQuery(params[wikidataparam])
            else
            v, valnum = params[wikidataparam]
            end
        end
        if not v then
                return nil
        end
        --v = linguistic.ucfirst(v)
        return v, valnum
end
end
local function parseDateValue(timestamp, date_format, date_addon)
 
local prefix_addon = i18n["datetime"]["prefix-addon"]
local function getValue(val, params)
local addon_sep = i18n["datetime"]["addon-sep"]
          if type(val) == 'string' then
local addon = ""
              return localdata[val]
-- check for negative date
        elseif type(val) == 'function' then
if string.sub(timestamp, 1, 1) == '-' then
              return val(localdata, localdata.item, params)
timestamp = '+' .. string.sub(timestamp, 2)
        elseif type(val) == 'table' then
addon = date_addon
              for i, j in pairs(val) do -- se vários parâmetros possíveis (legado do código antigo), tomar o primeiro não-vazio
end
                          if localdata[j] then
local _date_format = i18n["datetime"]["format"][date_format]
                                    return localdata[j]
if _date_format ~= nil then
                      end
return parseDateFormat(_date_format, timestamp, addon, prefix_addon, addon_sep)
              end
else
        end
return printError("unknown-datetime-format")
end
end
end
-- This local function combines the year/month/day/BC/BCE handling of parseDateValue{}
 
-- with the millennium/century/decade handling of formatDate()
local function addMaintenanceCat(cat, sortkey)
local function parseDateFull(timestamp, precision, date_format, date_addon)
          if page.namespace ~= 0 then
local prefix_addon = i18n["datetime"]["prefix-addon"]
              return ''
local addon_sep = i18n["datetime"]["addon-sep"]
        end
local addon = ""
        if cat then
-- check for negative date
        maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
if string.sub(timestamp, 1, 1) == '-' then
        end
timestamp = '+' .. string.sub(timestamp, 2)
addon = date_addon
end
-- get the next four characters after the + (should be the year now in all cases)
-- ok, so this is dirty, but let's get it working first
local intyear = tonumber(string.sub(timestamp, 2, 5))
if intyear == 0 and precision <= 9 then
return ""
end
-- precision is 10000 years or more
if precision <= 5 then
local factor = 10 ^ ((5 - precision) + 4)
local y2 = math.ceil(math.abs(intyear) / factor)
local relative = mw.ustring.gsub(i18n.datetime[precision], "$1", tostring(y2))
if addon ~= "" then
-- negative date
relative = mw.ustring.gsub(i18n.datetime.beforenow, "$1", relative)
else
relative = mw.ustring.gsub(i18n.datetime.afternow, "$1", relative)
end
return relative
end
-- precision is decades (8), centuries (7) and millennia (6)
local era, card
if precision == 6 then
card = math.floor((intyear - 1) / 1000) + 1
era = mw.ustring.gsub(i18n.datetime[6], "$1", makeOrdinal(card))
end
if precision == 7 then
card = math.floor((intyear - 1) / 100) + 1
era = mw.ustring.gsub(i18n.datetime[7], "$1", makeOrdinal(card))
end
if precision == 8 then
era = mw.ustring.gsub(i18n.datetime[8], "$1", tostring(math.floor(math.abs(intyear) / 10) * 10))
end
if era then
if addon ~= "" then
era = mw.ustring.gsub(mw.ustring.gsub(i18n.datetime.bc, '"', ""), "$1", era)
else
era = mw.ustring.gsub(mw.ustring.gsub(i18n.datetime.ad, '"', ""), "$1", era)
end
return era
end
local _date_format = i18n["datetime"]["format"][date_format]
if _date_format ~= nil then
-- check for precision is year and override supplied date_format
if precision == 9 then
_date_format = i18n["datetime"][9]
end
return parseDateFormat(_date_format, timestamp, addon, prefix_addon, addon_sep)
else
return printError("unknown-datetime-format")
end
end
end
-- the "qualifiers" and "snaks" field have a respective "qualifiers-order" and "snaks-order" field
 
-- use these as the second parameter and this function instead of the built-in "pairs" function
function p.separator(params)
-- to iterate over all qualifiers and snaks in the intended order.
        local style = params['estilo separador'] or {}
local function orderedpairs(array, order)
        style.height = style.height or '2px'
if not order then return pairs(array) end
        style['background-color'] = style['background-color'] or maincolor
-- return iterator function
local i = 0
    return mw.html.create('hr'):css( style )
return function()
i = i + 1
if order[i] then
return order[i], array[order[i]]
end
end
end
end
-- precision: 0 - billion years, 1 - hundred million years, ..., 6 - millennia, 7 - century, 8 - decade, 9 - year, 10 - month, 11 - day, 12 - hour, 13 - minute, 14 - second
 
local function normalizeDate(date)
function p.buildtitle(params)
date = mw.text.trim(date, "+")
        local text = getValue(params.value, params) or params.textdefaultvalue or  getWikidataValue(params) or mw.title.getCurrentTitle().text
-- extract year
    local subtext = getValue(params.subtitle) or  getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue
local yearstr = mw.ustring.match(date, "^\-?%d+")
    if subtext and (subtext ~= text) then
local year = tonumber(yearstr)
              text = text .. '<br /><small>' .. subtext .. '</small>'
-- remove leading zeros of year
        end
return year .. mw.ustring.sub(date, #yearstr + 1), year
        local style = {
                  border = 'none',
            ['text-align'] = 'center',
            ['font-size'] = '1.3em',
            padding = '0',
            display = 'table',
            height = '45px',
            width = '100%',
            ['*height'] = 'auto', -- be kind ie7
            ['*padding'] = '12px 0',
    }
    local style2 = {
                  display = 'table-cell',
                  ['vertical-align'] = 'middle',
                  padding = '3px',
    }
        local icon = params.icon or ''
        if icon ~= '' and not params.large then
                  icon = ' ' .. icon
        else
          -- style.padding = '12px'
                icon = " "
        end
        local class = 'topo' .. icon
    -- overwrites with those provided in the module
        -- local style = {}
        style['background-color'] = maincolor
        style['color'] = thirdcolor
        if params.style then
                  for i, j in pairs(params.style) do
                            style[i] = j
                end
        end
        local title = mw.html.create('div')
                  :addClass(class)
            :css(style)
            :tag('div')
            :css(style2)
        :wikitext(text)
            :allDone()
        return title
end
end
local function formatDate(date, precision, timezone)
p.buildTitle = p.buildtitle
precision = precision or 11
 
local date, year = normalizeDate(date)
function p.buildnavbox(params)
if year == 0 and precision <= 9 then return "" end
-- precision is 10000 years or more
    -- definição do estilo
if precision <= 5 then
        local class = "navbox " .. (params.class or '')
local factor = 10 ^ ((5 - precision) + 4)
        local style = params.style or {['overflow'] = 'hidden'}
local y2 = math.ceil(math.abs(year) / factor)
 
local relative = mw.ustring.gsub(i18n.datetime[precision], "$1", tostring(y2))
        if params.separated then -- opções para adicionar uma linha de separação acima
if year < 0 then
              class = class .. ' bordered'
relative = mw.ustring.gsub(i18n.datetime.beforenow, "$1", relative)
            style['border-top'] = '1px solid' .. maincolor
else
        end
relative = mw.ustring.gsub(i18n.datetime.afternow, "$1", relative)
 
end
        -- ajuste de parâmetros de dados
return relative
        params.previousval = params.previousval or params.previousparameter -- nome do parâmetro obsoleto
end
        params.nextval = params.nextval or params.nextparameter
-- precision is decades, centuries and millennia
local era
    if params.previousproperty then
if precision == 6 then era = mw.ustring.gsub(i18n.datetime[6], "$1", tostring(math.floor((math.abs(year) - 1) / 1000) + 1)) end
              params.previouswikidata = {property = params.previousproperty}
if precision == 7 then era = mw.ustring.gsub(i18n.datetime[7], "$1", tostring(math.floor((math.abs(year) - 1) / 100) + 1)) end
        end
if precision == 8 then era = mw.ustring.gsub(i18n.datetime[8], "$1", tostring(math.floor(math.abs(year) / 10) * 10)) end
        if params.nextproperty then
if era then
              params.nextwikidata = {property = params.nextproperty}
if year < 0 then era = mw.ustring.gsub(mw.ustring.gsub(i18n.datetime.bc, '"', ""), "$1", era)
        end
elseif year > 0 then era = mw.ustring.gsub(mw.ustring.gsub(i18n.datetime.ad, '"', ""), "$1", era) end
return era
 
end
    local previousval = getValue(params.previousval, params) or getWikidataValue(params, 'previouswikidata')
-- precision is year
        local nextval = getValue(params.nextval, params) or getWikidataValue(params, 'nextwikidata')
if precision == 9 then
return year
    local navbox
end
        if params.inner then -- para quem está dentro de uma tabela
-- precision is less than years
              navbox = mw.html.create('tr'):tag('th'):attr('colspan', 2)
if precision > 9 then
            style['font-weight'] = style['font-weight'] or 'normal'
--[[ the following code replaces the UTC suffix with the given negated timezone to convert the global time to the given local time
        else
timezone = tonumber(timezone)
        navbox = mw.html.create('div')
if timezone and timezone ~= 0 then
        end
timezone = -timezone
timezone = string.format("%.2d%.2d", timezone / 60, timezone % 60)
    navbox
if timezone[1] ~= '-' then timezone = "+" .. timezone end
    :css({['background-color'] = '#E6E6E6'})
date = mw.text.trim(date, "Z") .. " " .. timezone
        :addClass(class)
end
        -- :css(style)
]]--
        :css{border = '2px ' .. maincolor, ['font-weight'] = 'normal'}
local formatstr = i18n.datetime[precision]
        :tag('div')
if year == 0 then formatstr = mw.ustring.gsub(formatstr, i18n.datetime[9], "")
        :addClass('prev_bloc')
elseif year < 0 then
        :wikitext(previousval)
-- Mediawiki formatDate doesn't support negative years
        :done()
date = mw.ustring.sub(date, 2)
        :tag('div')
formatstr = mw.ustring.gsub(formatstr, i18n.datetime[9], mw.ustring.gsub(i18n.datetime.bc, "$1", i18n.datetime[9]))
        :addClass('next_bloc')
elseif year > 0 and i18n.datetime.ad ~= "$1" then
        :wikitext(nextval)
formatstr = mw.ustring.gsub(formatstr, i18n.datetime[9], mw.ustring.gsub(i18n.datetime.ad, "$1", i18n.datetime[9]))
        :done()
end
        :allDone()
return mw.language.new(wiki.langcode):formatDate(formatstr, date)
        return navbox
end
end
end
local function printDatavalueEntity(data, parameter)
p.buildNavbox = p.buildnavbox
-- data fields: entity-type [string], numeric-id [int, Wikidata id]
 
local id
function p.buildimages(params)
if data["entity-type"] == "item" then id = "Q" .. data["numeric-id"]
        local images = {}
elseif data["entity-type"] == "property" then id = "P" .. data["numeric-id"]
        local upright, link, caption, alt, size    -- size is deprecated
else return printError("unknown-entity-type")
        if type(params.imageparameters) == 'string' then
end
                params.imageparameters = {params.imageparameters}
if parameter then
        end
if parameter == "link" then
        if not params.imageparameters then -- se não houver nenhum parâmetro de imagem, continue, talvez haja uma imagem padrão definida no módulo de infobox
local linkTarget = mw.wikibase.sitelink(id)
              params.imageparameters = {}
local linkName = mw.wikibase.label(id)
        end
if linkTarget then
        for j, k in ipairs(params.imageparameters) do
-- if there is a local Wikipedia article link to it using the label or the article title
              table.insert(images, localdata[k])
return "[[" .. linkTarget .. "|" .. (linkName or linkTarget) .. "]]"
        end
else
        -- Images de Wikidata
-- if there is no local Wikipedia article output the label or link to the Wikidata object to let the user input a proper label
        if #images == 0 and localdata.item then
if linkName then return linkName else return "[[:d:" .. id .. "|" .. id .. "]]" end
          if params.property then
end
                                params.wikidata = {entity = localdata.item, property = params.property}
else
            end
return data[parameter]
            if params.wikidata then
end
                        local wdq = params.wikidata
else
                    wdq.excludespecial = true
return mw.wikibase.label(id) or id
                    if type(wdq) == 'table' then
end
                          wdq.entity = wdq.entity or localdata.item
                        wdq.numval = wdq.numval or params.numval or 1
                        images = wd.getClaims(wdq)
                end
                if type(wdq) == 'function' then
                          images = params.wikidata()
                        if type(images) == 'string' then
                        return images
                        end --provavelmente é um erro no pedido => mostrar a mensagem
                end
                if (not images) then
                          images = {}
                end
                if (#images > 0) and (params.wikidata.property) then
                          addWikidataCat(params.wikidata.property)
                end
 
                if type(images[1]) == 'table' then
                      for i, image in pairs(images) do
                              if image.mainsnak.snaktype ~= 'value' then
                            return
                        end
                        if #images == 1 then -- se apenas uma imagem, usamos a legenda (se mais duas imagens, como formatar?)
                                      caption = wd.getFormattedQualifiers('P18', {qualifier = 'P2096'}, {isinlang = 'pt'})
                        end
                        images[i] = image.mainsnak.datavalue.value
                    end
              end
              end
        end
 
        -- Imagens por padrao
        if #images == 0 then
              if params.maintenancecat then
                      addMaintenanceCat(params.maintenancecat, params.sortkey)
            end
            if params.defaultimages then
                      images = params.defaultimages
                    if type(images) == 'string' then
                          images = {images}
                    end
                    upright = params.defaultimageupright
                    caption = params.defaultimagecaption
                    link = params.defaultimagelink
                    alt = params.defaultimagealt
                    if not alt and ( images[1] == 'Padrao.svg' or images[1] == 'Padrao 2.svg' ) then
                            alt = 'uma ilustração licenciada gratuita seria bem-vinda'
                    end
            end
        end
        if #images == 0 then
              return nil
        end
    upright = upright or getValue(params.uprightparameter) or params.defaultupright or "1" -- 1.2 deixa uma margem
        link = link or getValue(params.linkparameter) or params.defaultlink
        caption = caption or getValue(params.captionparameter) or params.defaultcaption
        alt = alt or getValue( params.altparameter) or params.defaultalt
 
        -- tamanho com "size" (obsoleto)
        size = size or getValue(params.sizeparameter) or params.defaultsize or params.tamanho-- deprecated
        if size then
              local numsize = size:gsub('px', '')
            numsize = mw.ustring.gsub(numsize, 'x.*', '')
            numsize = tonumber(numsize)
            if type(numsize) ~= 'number' or numsize > 280 then
                      addMaintenanceCat("tamanho da imagem inválido")
            end
            if tonumber(size) then
                      size = size .. 'px'
            end
            size = '|' .. size
        else
        size = ''
        end
    if tonumber(upright) then
              upright = tostring(tonumber(upright) ) / #images
        end
        if tonumber(size) then
              size = tostring(tonumber(size) ) / #images
        end
 
    local style = params.style or {
                  padding ='2px 0',
        ['text-align'] = 'center',
          ['display'] = 'flex',
          ['justify-content'] = 'space-around',
          ['align-items'] = 'center',
    }
        local styleLegend = params.stylelegend or {
                  ['font-size'] = '0.9em',
          ['text-align'] = 'center',
          ['margin'] = '5px 0 5px 0',
        }
 
    -- Imagem da peça
 
        local imagesString = ''
        for i,image in pairs(images) do
                if image == '-' then
                      return
            end
            imagesString = imagesString ..      '[[File:' .. image .. "|" .. size .. '|frameless'
            if alt then
            imagesString = imagesString .. '|alt=' .. alt
            end
            if link then
                      imagesString = imagesString .. '|link=' .. link
            end
            if upright then
                      imagesString = imagesString .. '|upright=' .. upright
            elseif #images > 1 then
                          imagesString = imagesString .. '|upright=' .. ( 1 / #images )
            end
            imagesString = imagesString .. ']]'
        end
 
        local image = mw.html.create('div')
                  :addClass("image")
            :css(style)
            :wikitext(imagesString)
 
        -- Parte da legenda
        local captionobj
        if caption then
              captionobj = mw.html.create('p')
                    :css(styleLegend)
            :wikitext(caption)
                    :css(params.style or {})
                    :addClass("caption")
                    :done()
        end
        -- separador
          local separator
        if params.separator then
              separator = separator(params)
        end
        return mw.html.create('div')
                :node(image)
                :node(captionobj)
                :node(separator)
                :done()
end
end
local function printDatavalueTime(data, parameter)
p.buildImages = p.buildimages
-- data fields: time [ISO 8601 time], timezone [int in minutes], before [int], after [int], precision [int], calendarmodel [wikidata URI]
 
--  precision: 0 - billion years, 1 - hundred million years, ..., 6 - millennia, 7 - century, 8 - decade, 9 - year, 10 - month, 11 - day, 12 - hour, 13 - minute, 14 - second
function p.buildtext(params)
--  calendarmodel: e.g. http://www.wikidata.org/entity/Q1985727 for the proleptic Gregorian calendar or http://www.wikidata.org/wiki/Q11184 for the Julian calendar]
        local class = params.class or ''
if parameter then
        local style = {
if parameter == "calendarmodel" then data.calendarmodel = mw.ustring.match(data.calendarmodel, "Q%d+") -- extract entity id from the calendar model URI
                ['text-align'] = 'center',
elseif parameter == "time" then data.time = normalizeDate(data.time) end
            ['font-weight'] = 'bold'
return data[parameter]
        }
else
        if params.style then
return formatDate(data.time, data.precision, data.timezone)
              for i, j in pairs(params.style) do
end
                        style[i] = j
            end
        end
        local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue
        if text == '-' then
              return
        end
        if not text then
                addMaintenanceCat(params.maintenancecat, params.sortkey)
        return nil
        end
        local formattedtext = mw.html.create('p')
                :addClass(class)
            :css(style)
            :wikitext(text)
            :done()
        return formattedtext
end
end
local function printDatavalueMonolingualText(data, parameter)
p.buildText = p.buildtext
-- data fields: language [string], text [string]
 
if parameter then
function p.buildrow(params)
return data[parameter]
    local class = params.class or ''
else
        local style = params.style or {}
local result = mw.ustring.gsub(mw.ustring.gsub(i18n.monolingualtext, "%%language", data["language"]), "%%text", data["text"])
    style['vertical-align'] = 'middle'
return result
 
end
    local style2 = {
          ['text-align'] = 'left',
          ['padding-right'] = '10px',
          ['width'] = '8em',
          ['max-width'] = '140px',
          ['word-wrap'] = 'normal',
    }
        local value, number =  getValue(params.value, params)
        if (value == valueexpl) then
                value = nil
            params.wikidata.expl = false
        end
        if (not value) then
              value, number = getWikidataValue(params, 'wikidata')
        end
        if (not value) and (params.property) then
              value, number = expandQuery{ property = params.property, ucfirst = params.ucfirst }
        end
        if not value then
                value = params.defaultvalue
        end
        if value == '-' then
                return nil
        end
        if not number then
                number = 0 -- == indefinido
        end
 
        if not value then
                if params.maintenancecat then
                      local maintenancecat = getValue(params.maintenancecat, params)
                    addMaintenanceCat(maintenancecat, params.sortkey)
            end
            return nil
        end
 
        local label = params.label
        if number > 1 and (params.plurallabel) then
              label = params.plurallabel
        elseif number == 1 and (params.singularlabel) then
                label = params.singularlabel
        end
        if type(label) == 'function' then
              label = label(localdata, localdata.item)
        end
 
        -- format
        local formattedvalue = mw.html.create('div')
        :wikitext('\n' .. value) -- 'não é necessário quando o valor é uma lista que começa com '*' ou '#'
        if (params.hidden == true)then
                formattedvalue
                    :attr({class="NavContent", background= "none !important", ['padding-top'] = "0 !important", ['padding-bottom']="0 !important", ['border-top']= "1px solid grey !important", ['border-bottom']= "1px solid grey !important", ['margin-left']= "2em !important", ['margin-right']= "2em !important", style="display: none; text-align: left;"})
            formattedvalue = mw.html.create('div')
                        :attr({class="NavFrame", title="[Mostrar]/[Esconder]", style="border: none; padding: 0;"})
                    :node(formattedvalue)
        end
        formattedvalue =  mw.html.create('td')
                  :node(formattedvalue)
                  :allDone()
    local formattedlabel
        if label then
              formattedlabel = mw.html.create('th')
                :attr('scope', 'row')
                :css(style2)
                :wikitext(label)
                :done()
        end
        local row = mw.html.create('tr')
            :attr('scope', 'row')
            :addClass(class)
            :css(style)
            :node(formattedlabel)
            :node(formattedvalue)
            :done()
        return row
end
end
local function findClaims(entity, property)
p.buildRow = p.buildrow
if not property or not entity or not entity.claims then return end
 
if mw.ustring.match(property, "^P%d+$") then
function p.buildsuccession(params)
-- if the property is given by an id (P..) access the claim list by this id
        if not params.value then
return entity.claims[property]
                return nil
else
        end
property = mw.wikibase.resolvePropertyId(property)
if not property then return end
    --local style = params.style or {}
return entity.claims[property]
        --style['text-align'] = style['text-align'] or 'center'
end
        --style['color'] = style['color'] or '#000000'
        --style['background-color'] = style['background-color'] or '#F9F9F9'
    local rowI = mw.html.create('tr')
    local colspan = '2'
        cellI = mw.html.create('td')
            :attr({colspan = colspan})
                :attr({align = 'center'})
    local styleT = {}
        styleT['background-color'] = 'transparent'
        styleT['width'] = '100%'
        tabC = mw.html.create('table')
            :attr({cellspacing = '0'})
                :addClass('navigation-not-searchable')
                :css(styleT)
    local row = mw.html.create('tr')
 
        local color = params.color
 
        local style = {}
        local arrowLeft
        local arrowRight
    if color == 'default' then
              style['background-color'] = '#E6E6E6'
            arrowLeft = '[[Ficheiro:Fleche-defaut-gauche.png|13px|alt=Precedente|link=]]'
            arrowRight = '[[Ficheiro:Fleche-defaut-droite.png|13px|alt=Precedente|link=]]'
        else
        style['background-color'] = color
            arrowLeft = '[[Ficheiro:Fleche-defaut-gauche-gris-32.png|13px|alt=Próximo|link=]]'
            arrowRight = '[[Ficheiro:Fleche-defaut-droite-gris-32.png|13px|alt=Próximo|link=]]'
        end
    local styleTrans = {}
        styleTrans['background-color'] = '#F9F9F9'
    local values = params.value
        local before = values['before']
        local center = values['center']
        local after = values['after']
    local widthCell = '44%'
        if center then
              widthCenter = '28%'
            widthCell = '29%'
        end
    local formattedbefore
        if before then
              formattedbefore = mw.html.create('td')
                    :attr({valign = 'middle'})
                    :attr({align = 'left'})
                    :attr({width = '5%'})
                    :css(style)
                    :wikitext(arrowLeft)
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(style)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({align = 'left'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(style)
                    :wikitext(before)
                    :done()
                row:node(formattedbefore)
        else
        formattedbefore = mw.html.create('td')
                    :attr({valign = 'middle'})
                    :attr({align = 'left'})
                    :attr({width = '5%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({align = 'left'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
        end
    local formattedcenter
        formattedcenter = mw.html.create('td')
            :attr({width = '1%'})
            :css(styleTrans)
            :wikitext('')
            :done()
        row:node(formattedcenter)
    if center then
              formattedcenter = mw.html.create('td')
                    :attr({align = 'center'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCenter})
                    :css(style)
                    :wikitext(center)
                    :done()
            row:node(formattedcenter)
            formattedcenter = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedcenter)
        end
    local formattedafter
        if after then
              formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(style)
                    :wikitext(after)
                    :done()
            row:node(formattedafter)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(style)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = '5%'})
                    :css(style)
                    :wikitext(arrowRight)
                    :done()
            row:node(formattedafter)
        else
        formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedafter)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = '5%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedafter)
        end
    row:done()
        tabC:node(row)
        tabC:done()
        cellI:node(tabC)
        cellI:done()
        rowI:node(cellI)
        rowI:allDone()
    return rowI
end
end
local function getSnakValue(snak, parameter)
p.buildSuccession = p.buildsuccession
if snak.snaktype == "value" then
 
-- call the respective snak parser
function p.buildrow1col(params)
if snak.datavalue.type == "string" then return snak.datavalue.value
elseif snak.datavalue.type == "globecoordinate" then return printDatavalueCoordinate(snak.datavalue.value, parameter)
    if not params.value then
elseif snak.datavalue.type == "quantity" then return printDatavalueQuantity(snak.datavalue.value, parameter)
                return nil
elseif snak.datavalue.type == "time" then return printDatavalueTime(snak.datavalue.value, parameter)
        end
elseif snak.datavalue.type == "wikibase-entityid" then return printDatavalueEntity(snak.datavalue.value, parameter)
elseif snak.datavalue.type == "monolingualtext" then return printDatavalueMonolingualText(snak.datavalue.value, parameter)
    --local style = params.style or {}
end
        --style['text-align'] = style['text-align'] or 'center'
end
        --style['color'] = style['color'] or '#000000'
return mw.wikibase.renderSnak(snak)
        --style['background-color'] = style['background-color'] or '#F9F9F9'
        local class = params.class
        local rowcolor
        if params.color == 'secondcolor' then
              rowcolor = secondcolor
        else
        rowcolor = params.color
        end
    local style = {}
        style['padding'] = '4px'
        style['text-align'] = 'center'
        style['background-color'] = rowcolor or '#F9F9F9'
        style['color'] = '#000000'
    local text = params.value
 
        local colspan ='2'
 
        local formattedlabel
        formattedlabel = mw.html.create('th')
            :attr({colspan = colspan})
            :css(style)
            :wikitext(text)
            :done()
 
        local row = mw.html.create('tr')
                :addClass(class)
            :css(style)
            :node(formattedlabel)
            :done()
    return row
end
end
local function getQualifierSnak(claim, qualifierId)
p.buildRow1Col = p.buildrow1col
-- a "snak" is Wikidata terminology for a typed key/value pair
 
-- a claim consists of a main snak holding the main information of this claim,
function p.buildtable(params)
-- as well as a list of attribute snaks and a list of references snaks
        local tab = mw.html.create('table'):css(params.style or {})
if qualifierId then
 
-- search the attribute snak with the given qualifier as key
        local rows = params.rows
if claim.qualifiers then
local qualifier = claim.qualifiers[qualifierId]
    -- expand parameters so that we have a list of tables
if qualifier then return qualifier[1] end
        local i = 1
end
 
return nil, printError("qualifier-not-found")
        while (i <= #rows) do
else
                  local l = rows[i]
-- otherwise return the main snak
            if type(l) == 'function' then
return claim.mainsnak
                      l = l(localdata, localdata.item)
end
            end
            if (type(l) == 'table') and (l.type == 'multi') then
                      table.remove(rows, i)
                    for j, row in ipairs(l.rows) do
                              table.insert(rows, i + j - 1, row)
                    end
            elseif type(l) == 'nil' then
                        table.remove(rows, i)
            elseif type(l) ~= 'table' then
                          return error('as linhas da infobox ("rows") devem ser tabelas, e ' .. type(l))
            else
            i = i + 1
            end
        end
 
        -- CREATE ROW
        local expandedrows = {}
        for k, row in ipairs(rows) do
                  local v = p.buildblock(row)
            if v then
            table.insert(expandedrows, v)
            end
        end
        if (#expandedrows == 0) then
              return nil
        end
        rows = expandedrows
 
        -- ADD TITLE
        local title
        if params.title or params.singulartitle or params.pluraltitle then
              local text
            if #rows > 1 and params.pluraltitle then
                  text = params.pluraltitle
            elseif #rows == 1 and params.singulartitle then
                      text = params.singulartitle
            else
            text = params.title
            end
 
            local style = params.titlestyle or {}
            style['font-weight'] = style['font-weight'] or 'bolder'
            style['width'] = style['width'] or '23em'
            style['text-align'] = style['text-align'] or 'center'
            style['line-height'] = style['line-height'] or '1.5'
            style['margin'] = style['margin'] or '0 0 5px 0'
            --style['padding-top'] = style['padding-top'] or '.5em'
            --style['padding-bottom'] = style['padding-bottom'] or '.5em'
            style['color'] = style['color'] or thirdcolor
            style['background-color'] = style['background-color'] or maincolor
        style['max-width'] = style['max-width'] or '300px'
        style['word-wrap'] = style['word-wrap'] or 'break-word'
 
 
 
            local colspan ='2'
            title = mw.html.create('caption')
                      :attr({colspan = colspan})
                :css(style)
                :wikitext(text)
                :done()
    end
    if title then
              tab:node(title)
        end
    for i, j in pairs (rows) do
                  tab:node(j)
        end
    if params.separator then
              local separator = p.separator(params)
            tab:node(separator)
        end
        tab:allDone()
        return tab
end
end
local function getValueOfClaim(claim, qualifierId, parameter)
p.buildTable = p.buildtable
local error
 
local snak
function p.buildinvalidblock(args)
snak, error = getQualifierSnak(claim, qualifierId)
        addMaintenanceCat(defaultcat)
if snak then
        local text = ''
return getSnakValue(snak, parameter)
        if type(args) ~= 'table' then
else
              text = "Blocos de infobox devem ser tabelas"
return nil, error
        else
end
        text = i18n["invalid block type"] .. ' : ' .. (args.type or '??')
        end
        return text
end
end
local function getReferences(frame, claim)
p.buildInvalidBlock = p.buildinvalidblock
local result = ""
 
-- traverse through all references
function p.buildmap(params)
for ref in pairs(claim.references or {}) do
 
local refparts
        -- configuração de exibição
-- traverse through all parts of the current reference
        local maplist = getValue(params.maps)
for snakkey, snakval in orderedpairs(claim.references[ref].snaks or {}, claim.references[ref]["snaks-order"]) do
        local pointtype = params.pointtype
if refparts then refparts = refparts .. ", " else refparts = "" end
        local maptype = params.maptype -- escolhe o tipo de mapa mais adequado (alívio, administrativo, etc.)
-- output the label of the property of the reference part, e.g. "imported from" for P143
        if type(maplist) == 'function' then
refparts = refparts .. tostring(mw.wikibase.label(snakkey)) .. ": "
              maplist = maplist(localdata, localdata.item)
-- output all values of this reference part, e.g. "German Wikipedia" and "English Wikipedia" if the referenced claim was imported from both sites
        end
for snakidx = 1, #snakval do
        local width = tonumber(params.largura) or 270 -- 280 padrao f.ajustar
if snakidx > 1 then refparts = refparts .. ", " end
        if width > 280 then
refparts = refparts .. getSnakValue(snakval[snakidx])
              addMaintenanceCat("!Erro de infobox - imagem muito grande")
end
            return 'imagem muito grande, a largura deve ser menor ou igual a 280px'
end
        end
if refparts then result = result .. frame:extensionTag("ref", refparts) end
 
end
        -- mostrar os dados locais
return result
        local pointtable = {}
        local globe = params.globe
        if params.latitude then
              local lat, long
            if type(params.latitude) == 'function' then
                        lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item)
        else
        lat, long = localdata[params.latitude], localdata[params.longitude]
            end
            if lat then
            table.insert(pointtable, {latitude = lat, longitude = long})
            end
        end
 
        -- mostrar os dados wikidata
        local function processWDval(claim, displayformat)
                  if not claim then
                      return nil
            end
            local val = wd.formatSnak( claim.mainsnak )
            return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker}
        end
    local function getWDvals(query)
                  query.excludespecial = true
            query.numval = query.numval or 1
            query.entity = query.entity or localdata.item
            local claims = wd.getClaims(query)
            if (not claims) then
                  return
            end
            for i, claim in ipairs(claims) do
                      claim = processWDval(claim, query)
                table.insert(pointtable, claim)
            end
        end
    if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then
              for i, query in ipairs(params.wikidata) do
                          if type(query) == 'function' then
                          query = query()
                    end
                    if query then
                              getWDvals(query)
                    end
            end
        end
    if (not pointtable) or (#pointtable == 0) then
              return nil
        end
    local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor }
        if params.params and type(params.params) == 'table' then -- parâmetro adicionais
              for i, j in pairs(params.params) do
                          newparams[i] = j
            end
        end
        return require('Módulo:Mapa').multimap(newparams)
end
end
local function parseInput(frame)
p.buildMap = p.buildmap
local qid = frame.args.qid
 
if qid and (#qid == 0) then qid = nil end
function p.buildexternaltext(params)
local propertyID = mw.text.trim(frame.args[1] or "")
    local value = getValue(params.value)
local input_parm = mw.text.trim(frame.args[2] or "")
        if value and (type(value) == 'string') then
if input_parm ~= "FETCH_WIKIDATA" then
              externaltext = externaltext .. value
return false, input_parm, nil, nil
        end
end
local entity = mw.wikibase.getEntityObject(qid)
local claims
if entity and entity.claims then
claims = entity.claims[propertyID]
if not claims then
return false, "", nil, nil
end
else
return false, "", nil, nil
end
return true, entity, claims, propertyID
end
end
local function isType(claims, type)
p.buildExternalText = p.buildexternaltext
return claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == type
 
function p.buildfooter(params)
        if not params then
                  params = {}
        end
    local class = 'navbar noprint bordered ' .. (params.class or '')
        local style = params.style or {['border-width'] = '1px'}
        style['margin-top'] = '5px' -- espaço vertical para o footer
    style['margin-bottom'] = '-0.125em'
        style['border-top'] = style['border-top'] or '1px solid ' .. maincolor
    style['border-bottom'] = '0'
    style['display'] = 'block'
 
    local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.name, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']'
                  .. ' - [' .. tostring( mw.uri.fullUrl( page.name, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'
 
        local itemlinkstr
        if localdata.item then
              itemlinkstr = '[[d:' .. localdata.item.id .. '|' .. i18n['edit item'] .. ']]'
        end
        local editstr = backlinkstr
      if itemlinkstr then
                editstr = editstr .. ' - ' .. itemlinkstr
        end
        local editlinkspan =  mw.html.create('span')
                  :css({['text-align'] = "left"})
            :css({['width'] = "23em"})
        --:css({['float'] = "left"})
            :addClass('plainlinks') --?existe
            :wikitext(editstr)
            :done()
        local doclinkstr = '[[Imagem:Info Simple.svg|12px|link=' .. localdata.templatename .. '|' .. i18n['see doc'] .. ']]'
        -- Se esse link nem sempre funcionar, adicione uma variável para o nome da infobox recuperada pelo quadro
        local doclinkspan = mw.html.create('span')
                  :css({['text-align'] = "right"})
            :css({['float'] = "right"})
            :wikitext(doclinkstr)
            :done()
    local footer = mw.html.create('p')
                  :addClass(class)
            :css(style)
            :node(editlinkspan)
            :node(doclinkspan)
        return footer
end
end
local function getValue(entity, claims, propertyID, delim, labelHook)  
p.buildFooter = p.buildfooter
if labelHook == nil then
 
labelHook = function (qnumber)
function p.buildblock(block)
return nil;
        if type(block) == 'function' then
end
              block = block( localdata )
end
        end
if isType(claims, "wikibase-entityid") then
 
local out = {}
        local blocktypes = { -- list of functions for block buildings
for k, v in pairs(claims) do
                  ['invalid'] = p.buildinvalidblock,
local qnumber = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
            ['external text'] = p.buildexternaltext,
local sitelink = mw.wikibase.sitelink(qnumber)
            ['footer'] = p.buildfooter,
local label = labelHook(qnumber) or mw.wikibase.label(qnumber) or qnumber
            ['images'] = p.buildimages,
if sitelink then
            ['map']= p.buildmap,
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
            ['mixed'] = p.buildrow,
else
            ['navbox'] = p.buildnavbox,
out[#out + 1] = "[[:d:" .. qnumber .. "|" .. label .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
            ['table'] = p.buildtable,
end
            ['row'] = p.buildrow,
end
            ['row1col'] = p.buildrow1col,
return table.concat(out, delim)
            ['succession'] = p.buildnavbox,
else
            ['text'] = p.buildtext,
-- just return best values
            ['title'] = p.buildtitle,
return entity:formatPropertyValues(propertyID).value
        }
end
        if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then
          return blocktypes['invalid'](block)
        end
        return blocktypes[block.type](block)
end
end
------------------------------------------------------------------------------
p.buildBlock = p.buildblock
-- module global functions
 
if debug then
function p.build()
function p.inspectI18n(frame)
local val = i18n
    localdata = require( 'Módulo:Infobox/Localdata' )
for _, key in pairs(frame.args) do
        item = localdata.item
key = mw.text.trim(key)
 
val = val[key]
        -- assign rank to the infobox, "secondary" means special formatting like no displaytitle for coordinates
end
        local infoboxrank = 'main' -- main infobox of the page, with coordinates displayed in title etc.
return val
        if page.namespace ~= 0 then
end
              infoboxrank = 'secondary'
end
        end
function p.descriptionIn(frame)
        -- if infobox is linked to another item: rank = secondary
local langcode = frame.args[1]
        if localdata.item then
local id = frame.args[2]
              local itemlink = mw.wikibase.sitelink(localdata.item.id)
-- return description of a Wikidata entity in the given language or the default language of this Wikipedia site
            local pagetitle = mw.title.getCurrentTitle().text
return mw.wikibase.getEntityObject(id).descriptions[langcode or wiki.langcode].value
            if (itemlink or '') ~= pagetitle then
end
                      infoboxrank = 'secondary'
function p.labelIn(frame)
            end
local langcode = frame.args[1]
        end
local id = frame.args[2]
        localdata.infoboxrank = infoboxrank
-- return label of a Wikidata entity in the given language or the default language of this Wikipedia site
 
return mw.wikibase.getEntityObject(id).labels[langcode or wiki.langcode].value
        -- load infobox module page
end
        local moduledata = require('Módulo:Infobox/' .. localdata.modulename)
-- This is used to get a value, or a comma separated list of them if multiple values exist
        moduledata.name = localdata.modulename
p.getValue = function(frame)
        -- defines main color
local delimdefault = ", " -- **internationalise later**
        maincolor = localdata['cor infobox'] or localdata['caixa de cor'] or moduledata.maincolor or maincolor
local delim = frame.args.delimiter or ""
        secondcolor = moduledata.secondcolor or secondcolor
delim = string.gsub(delim, '"', '')
        thirdcolor = moduledata.thirdcolor or thirdcolor
if #delim == 0 then
        if maincolor:match( '^%x%x%x%x%x%x$' ) or maincolor:match( '^%x%x%x$' ) then
delim = delimdefault
              maincolor = '#' .. maincolor
end
        end
local go, errorOrentity, claims, propertyID = parseInput(frame)
if not go then
        -- class
return errorOrentity
        local class = 'infobox_v2'
end
        if moduledata.class then
return getValue(errorOrentity, claims, propertyID, delim)
            class = class .. ' ' .. moduledata.class
end
        end
-- Same as above, but uses the short name property for label if available.
p.getValueShortName = function(frame)
    -- style
local go, errorOrentity, claims, propertyID = parseInput(frame)
        local style = moduledata.style or {} --{'width: 20em; text-align: left; font-size: 88%; max-width: 23em'}
if not go then
        style['font-size'] = style['font-size'] or '88%'
return errorOrentity
end
    -- build infobox
local entity = errorOrentity
        infobox :addClass(class)
-- if wiki-linked value output as link if possible
            :attr({cellpadding= "3"})
local function labelHook (qnumber)
                :attr({border= "0"})
local label
                :css(style)
local claimEntity = mw.wikibase.getEntity(qnumber)
        for i, j in pairs( moduledata.parts ) do
if claimEntity ~= nil then
                  infobox:node( p.buildblock(j) )
if claimEntity.claims.P1813 then
        end
for k2, v2 in pairs(claimEntity.claims.P1813) do
        infobox :node(p.buildfooter(moduledata.footer))
if v2.mainsnak.datavalue.value.language == "en" then
                :done()
label = v2.mainsnak.datavalue.value.text
 
end
        if CategorizacaoABeAD.hasAnyBadge() == '1' then
end
            maintenance = maintenance .. (CategorizacaoABeAD.badgesCategories())
end
        end
end
 
if label == nil or label == "" then return nil end
        return tostring(infobox) .. externaltext, maintenance
return label
end
return getValue(errorOrentity, claims, propertyID, ", ", labelHook);
end
-- This is used to get a value, or a comma separated list of them if multiple values exist
-- from an arbitrary entry by using its QID.
-- Use : {{#invoke:Wikidata|getValueFromID|<ID>|<Property>|FETCH_WIKIDATA}}
-- E.g.: {{#invoke:Wikidata|getValueFromID|Q151973|P26|FETCH_WIKIDATA}} - to fetch value of 'spouse' (P26) from 'Richard Burton' (Q151973)
-- Please use sparingly - this is an *expensive call*.
p.getValueFromID = function(frame)
local itemID = mw.text.trim(frame.args[1] or "")
local propertyID = mw.text.trim(frame.args[2] or "")
local input_parm = mw.text.trim(frame.args[3] or "")
if input_parm == "FETCH_WIKIDATA" then
local entity = mw.wikibase.getEntity(itemID)
local claims
if entity and entity.claims then
claims = entity.claims[propertyID]
end
if claims then
return getValue(entity, claims, propertyID, ", ")
else
return ""
end
else
return input_parm
end
end
local function getQualifier(frame, outputHook)
local propertyID = mw.text.trim(frame.args[1] or "")
local qualifierID = mw.text.trim(frame.args[2] or "")
local input_parm = mw.text.trim(frame.args[3] or "")
if input_parm == "FETCH_WIKIDATA" then
local entity = mw.wikibase.getEntityObject()
if entity.claims[propertyID] ~= nil then
local out = {}
for k, v in pairs(entity.claims[propertyID]) do
for k2, v2 in pairs(v.qualifiers[qualifierID]) do
if v2.snaktype == 'value' then
out[#out + 1] = outputHook(v2);
end
end
end
return table.concat(out, ", "), true
else
return "", false
end
else
return input_parm, false
end
end
p.getQualifierValue = function(frame)
local function outputValue(value)
local qnumber = "Q" .. value.datavalue.value["numeric-id"]
if (mw.wikibase.sitelink(qnumber)) then
return "[[" .. mw.wikibase.sitelink(qnumber) .. "]]"
else
return "[[:d:" .. qnumber .. "|" ..qnumber .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return (getQualifier(frame, outputValue))
end
-- This is used to get a value like 'male' (for property p21) which won't be linked and numbers without the thousand separators
p.getRawValue = function(frame)
local go, errorOrentity, claims, propertyID = parseInput(frame)
if not go then
return errorOrentity
end
local entity = errorOrentity
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
-- if number type: remove thousand separators, bounds and units
if isType(claims, "quantity") then
result = mw.ustring.gsub(result, "(%d),(%d)", "%1%2")
result = mw.ustring.gsub(result, "(%d)±.*", "%1")
end
return result
end
-- This is used to get the unit name for the numeric value returned by getRawValue
p.getUnits = function(frame)
local go, errorOrentity, claims, propertyID = parseInput(frame)
if not go then
return errorOrentity
end
local entity = errorOrentity
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
if isType(claims, "quantity") then
result = mw.ustring.sub(result, mw.ustring.find(result, " ")+1, -1)
end
return result
end
-- This is used to get the unit's QID to use with the numeric value returned by getRawValue
p.getUnitID = function(frame)
local go, errorOrentity, claims = parseInput(frame)
if not go then
return errorOrentity
end
local entity = errorOrentity
local result
if isType(claims, "quantity") then
-- get the url for the unit entry on Wikidata:
result = claims[1].mainsnak.datavalue.value.unit
-- and just reurn the last bit from "Q" to the end (which is the QID):
result = mw.ustring.sub(result, mw.ustring.find(result, "Q"), -1)
end
return result
end
p.getRawQualifierValue = function(frame)
local function outputHook(value)
if value.datavalue.value["numeric-id"] then
return mw.wikibase.label("Q" .. value.datavalue.value["numeric-id"])
else
return value.datavalue.value
end
end
local ret, gotData = getQualifier(frame, outputHook)
if gotData then
ret = string.upper(string.sub(ret, 1, 1)) .. string.sub(ret, 2)
end
return ret
end
-- This is used to get a date value for date_of_birth (P569), etc. which won't be linked
-- Dates and times are stored in ISO 8601 format (sort of).
-- At present the local formatDate(date, precision, timezone) function doesn't handle timezone
-- So I'll just supply "Z" in the call to formatDate below:
p.getDateValue = function(frame)
local date_format = mw.text.trim(frame.args[3] or i18n["datetime"]["default-format"])
local date_addon = mw.text.trim(frame.args[4] or i18n["datetime"]["default-addon"])
local go, errorOrentity, claims = parseInput(frame)
if not go then
return errorOrentity
end
local entity = errorOrentity
local out = {}
for k, v in pairs(claims) do
if v.mainsnak.datavalue.type == 'time' then
local timestamp = v.mainsnak.datavalue.value.time
local dateprecision = v.mainsnak.datavalue.value.precision
-- A year can be stored like this: "+1872-00-00T00:00:00Z",
-- which is processed here as if it were the day before "+1872-01-01T00:00:00Z",
-- and that's the last day of 1871, so the year is wrong.
-- So fix the month 0, day 0 timestamp to become 1 January instead:
timestamp = timestamp:gsub("%-00%-00T", "-01-01T")
out[#out + 1] = parseDateFull(timestamp, dateprecision, date_format, date_addon)
end
end
return table.concat(out, ", ")
end
p.getQualifierDateValue = function(frame)
local date_format = mw.text.trim(frame.args[4] or i18n["datetime"]["default-format"])
local date_addon = mw.text.trim(frame.args[5] or i18n["datetime"]["default-addon"])
local function outputHook(value)
local timestamp = value.datavalue.value.time
return parseDateValue(timestamp, date_format, date_addon)
end
return (getQualifier(frame, outputHook))
end
-- This is used to fetch all of the images with a particular property, e.g. image (P18), Gene Atlas Image (P692), etc.
-- Parameters are | propertyID | value / FETCH_WIKIDATA / nil | separator (default=space) | size (default=frameless)
-- It will return a standard wiki-markup [[File:Filename | size]] for each image with a selectable size and separator (which may be html)
-- e.g. {{#invoke:Wikidata|getImages|P18|FETCH_WIKIDATA}}
-- e.g. {{#invoke:Wikidata|getImages|P18|FETCH_WIKIDATA|<br>|250px}}
-- If a property is chosen that is not of type "commonsMedia", it will return empty text.
p.getImages = function(frame)
local sep = mw.text.trim(frame.args[3] or " ")
local imgsize = mw.text.trim(frame.args[4] or "frameless")
local go, errorOrentity, claims = parseInput(frame)
if not go then
return errorOrentity
end
local entity = errorOrentity
if (claims[1] and claims[1].mainsnak.datatype == "commonsMedia") then
local out = {}
for k, v in pairs(claims) do
local filename = v.mainsnak.datavalue.value
out[#out + 1] = "[[File:" .. filename .. "|" .. imgsize .. "]]"
end
return table.concat(out, sep)
else
return ""
end
end
-- This is used to get the TA98 (Terminologia Anatomica first edition 1998) values like 'A01.1.00.005' (property P1323)
-- which are then linked to http://www.unifr.ch/ifaa/Public/EntryPage/TA98%20Tree/Entity%20TA98%20EN/01.1.00.005%20Entity%20TA98%20EN.htm
-- uses the newer mw.wikibase calls instead of directly using the snaks
-- formatPropertyValues returns a table with the P1323 values concatenated with ", " so we have to split them out into a table in order to construct the return string
p.getTAValue = function(frame)
local ent = mw.wikibase.getEntityObject()
local props = ent:formatPropertyValues('P1323')
local out = {}
local t = {}
for k, v in pairs(props) do
if k == 'value' then
t = mw.text.split( v, ", ")
for k2, v2 in pairs(t) do
out[#out + 1] = "[http://www.unifr.ch/ifaa/Public/EntryPage/TA98%20Tree/Entity%20TA98%20EN/" .. string.sub(v2, 2) .. "%20Entity%20TA98%20EN.htm " .. v2 .. "]"
end
end
end
local ret = table.concat(out, "<br> ")
if #ret == 0 then
ret = "Invalid TA"
end
return ret
end
--[[
This is used to return an image legend from Wikidata
image is property P18
image legend is property P2096
Call as {{#invoke:Wikidata |getImageLegend | <PARAMETER> | lang=<ISO-639code> |id=<QID>}}
Returns PARAMETER, unless it is equal to "FETCH_WIKIDATA", from Item QID (expensive call)
If QID is omitted or blank, the current article is used (not an expensive call)
If lang is omitted, it uses the local wiki language, otherwise it uses the provided ISO-639 language code
ISO-639: https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqisocodes.html#wp1252447
Ranks are: 'preferred' > 'normal'
This returns the label from the first image with 'preferred' rank
Or the label from the first image with 'normal' rank if preferred returns nothing
Ranks: https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
]]
p.getImageLegend = function(frame)
-- look for named parameter id; if it's blank make it nil
local id = frame.args.id
if id and (#id == 0) then
id = nil
end
-- look for named parameter lang
-- it should contain a two-character ISO-639 language code
-- if it's blank fetch the language of the local wiki
local lang = frame.args.lang
if (not lang) or (#lang < 2) then
lang = mw.language.getContentLanguage().code
end
-- first unnamed parameter is the local parameter, if supplied
local input_parm = mw.text.trim(frame.args[1] or "")
if input_parm == "FETCH_WIKIDATA" then
local ent = mw.wikibase.getEntityObject(id)
local imgs
if ent and ent.claims then
imgs = ent.claims.P18
end
local imglbl
if imgs then
-- look for an image with 'preferred' rank
for k1, v1 in pairs(imgs) do
if v1.rank == "preferred" and v1.qualifiers and v1.qualifiers.P2096 then
local imglbls = v1.qualifiers.P2096
for k2, v2 in pairs(imglbls) do
if v2.datavalue.value.language == lang then
imglbl = v2.datavalue.value.text
break
end
end
end
end
-- if we don't find one, look for an image with 'normal' rank
if (not imglbl) then
for k1, v1 in pairs(imgs) do
if v1.rank == "normal" and v1.qualifiers and v1.qualifiers.P2096 then
local imglbls = v1.qualifiers.P2096
for k2, v2 in pairs(imglbls) do
if v2.datavalue.value.language == lang then
imglbl = v2.datavalue.value.text
break
end
end
end
end
end
end
return imglbl
else
return input_parm
end
end
-- This is used to get the QIDs of all of the values of a property, as a comma separated list if multiple values exist
-- Usage: {{#invoke:Wikidata |getPropertyIDs |<PropertyID> |FETCH_WIKIDATA}}
-- Usage: {{#invoke:Wikidata |getPropertyIDs |<PropertyID> |<InputParameter> |qid=<QID>}}
p.getPropertyIDs = function(frame)
local go, errorOrentity, propclaims = parseInput(frame)
if not go then
return errorOrentity
end
local entity = errorOrentity
-- if wiki-linked value collect the QID in a table
if (propclaims[1] and propclaims[1].mainsnak.snaktype == "value" and propclaims[1].mainsnak.datavalue.type == "wikibase-entityid") then
local out = {}
for k, v in pairs(propclaims) do
out[#out + 1] = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
end
return table.concat(out, ", ")
else
-- not a wikibase-entityid, so return empty
return ""
end
end
-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidata
function p.pageId(frame)
local entity = mw.wikibase.getEntityObject()
if not entity then return nil else return entity.id end
end
function p.claim(frame)
local property = frame.args[1] or ""
local id = frame.args["id"]
local qualifierId = frame.args["qualifier"]
local parameter = frame.args["parameter"]
local list = frame.args["list"]
local references = frame.args["references"]
local showerrors = frame.args["showerrors"]
local default = frame.args["default"]
if default then showerrors = nil end
-- get wikidata entity
local entity = mw.wikibase.getEntityObject(id)
if not entity then
if showerrors then return printError("entity-not-found") else return default end
end
-- fetch the first claim of satisfying the given property
local claims = findClaims(entity, property)
if not claims or not claims[1] then
if showerrors then return printError("property-not-found") else return default end
end
-- get initial sort indices
local sortindices = {}
for idx in pairs(claims) do
sortindices[#sortindices + 1] = idx
end
-- sort by claim rank
local comparator = function(a, b)
local rankmap = { deprecated = 2, normal = 1, preferred = 0 }
local ranka = rankmap[claims[a].rank or "normal"] .. string.format("%08d", a)
local rankb = rankmap[claims[b].rank or "normal"] .. string.format("%08d", b)
return ranka < rankb
end
table.sort(sortindices, comparator)
local result
local error
if list then
local value
-- iterate over all elements and return their value (if existing)
result = {}
for idx in pairs(claims) do
local claim = claims[sortindices[idx]]
value, error = getValueOfClaim(claim, qualifierId, parameter)
if not value and showerrors then value = error end
if value and references then value = value .. getReferences(frame, claim) end
result[#result + 1] = value
end
result = table.concat(result, list)
else
-- return first element
local claim = claims[sortindices[1]]
result, error = getValueOfClaim(claim, qualifierId, parameter)
if result and references then result = result .. getReferences(frame, claim) end
end
if result then return result else
if showerrors then return error else return default end
end
end
-- look into entity object
function p.ViewSomething(frame)
local f = (frame.args[1] or frame.args.id) and frame or frame:getParent()
local id = f.args.id
if id and (#id == 0) then
id = nil
end
local data = mw.wikibase.getEntityObject(id)
if not data then
return nil
end
local i = 1
while true do
local index = f.args[i]
if not index then
if type(data) == "table" then
return mw.text.jsonEncode(data, mw.text.JSON_PRESERVE_KEYS + mw.text.JSON_PRETTY)
else
return tostring(data)
end
end
data = data[index] or data[tonumber(index)]
if not data then
return
end
i = i + 1
end
end
-- getting sitelink of a given wiki
-- get sitelink of current item if qid not supplied
function p.getSiteLink(frame)
local qid = frame.args.qid
if qid == "" then qid = nil end
local f = mw.text.trim( frame.args[1] or "")
local entity = mw.wikibase.getEntity(qid)
if not entity then
return
end
local link = entity:getSitelink( f )
if not link then
return
end
return link
end
function p.Dump(frame)
local f = (frame.args[1] or frame.args.id) and frame or frame:getParent()
local data = mw.wikibase.getEntityObject(f.args.id)
if not data then
return i18n.warnDump
end
local i = 1
while true do
local index = f.args[i]
if not index then
return "<pre>"..mw.dumpObject(data).."</pre>".. i18n.warnDump
end
data = data[index] or data[tonumber(index)]
if not data then
return i18n.warnDump
end
i = i + 1
end
end
end
return p
return p

Edição atual desde as 04h59min de 22 de maio de 2024

A documentação para este módulo pode ser criada na página Módulo:Wikidata/doc

local p = {}
local lang = 'pt'

local item = nil -- o elemento Wikidata ligado
local localdata = {}-- guarda parâmetros passados à predefinição
local page = { -- guarda parâmetros da página mostrados na infocaixa
        name = mw.title.getCurrentTitle().prefixedText,
    namespace =  mw.title.getCurrentTitle().namespace
}
local maincolor, secondcolor, thirdcolor = '#E1E1E1', '#E1E1E1', '#000000'
-- o objecto principal a mostrar
local infobox = mw.html.create('div')

-- objetos secundários a mostrar
local maintenance = '' -- cadeia devolvida com o módulo : cats de monitoramento
local externaltext = '' -- para exemplo com coordenadas no título
-- modules importados
local linguistic = require "Módulo:Linguística"
local wd = require 'Módulo:Infobox/Wikidata'
local valueexpl = wd.translate("activate-query")
local CategorizacaoABeAD = require('Módulo:Categorização AD e AB de outras wikis')
local i18n = {
        ['see doc'] = 'Documentação da predefinição',
        ['edit'] = 'editar',
        ['edit code'] = 'editar código-fonte',
        ['edit item'] = 'editar Wikidata',
        ['tracking cat'] = "!Páginas que utilizam dados no Wikidata",
        ['invalid block type'] = "Bloco de dados inválidos dentro do módulo infobox",
        ['default cat'] = "!Monitoramento das infobox",
}

local function addWikidataCat(prop)
          maintenance = maintenance .. wd.addTrackingCat(prop)
end

local function expandQuery(query)
          local value, number -- valor a mostrar, nome dos valores para o rótulo
        if not query.entity then
                query.entity = localdata.item
        end
        if not query.conjtype then
                query.conjtype = 'new line'
        end
        local claims = wd.getClaims(query)
                  if (not claims) then
               return nil
        end
        return wd.formatAndCat(query), #claims -- para acordo do plural
end

local function getWikidataValue(params, wikidataparam)
          -- Mostrar o valor Wikidata para o valor, quer no parâmetro "wikidata" ou no parâmetro "property"
        if not localdata.item then
                return nil
        end

        if params.blockers then -- blockers are local parameters that disable the wikidata query
                  local blockers = params.blockers
               if (type(blockers) == 'string') then
                      blockers = {blockers}
               end
               for i, blocker in ipairs(blockers) do
                      if localdata[blocker] then
                                   return nil
                   end
               end
        end

        local v, valnum -- o valor a retornar e o número de valores (para concordância gramatical)
 
    if not wikidataparam then -- por padrão o valor wikidata está no parâmetro "wikidata" mas nas estruturas compostas como "title", existem vários parâmetros wikidata
               wikidataparam = 'wikidata'
        end

        if params[wikidataparam] then
               if type(params[wikidataparam]) == 'function' then
                       v, valnum = params[wikidataparam](localdata.item)
            elseif type(params[wikidataparam]) == 'table' then
                           v, valnum = expandQuery(params[wikidataparam])
            else
            v, valnum = params[wikidataparam]
            end
        end
        if not v then
                return nil
        end
        --v = linguistic.ucfirst(v)
        return v, valnum
end

local function getValue(val, params)
          if type(val) == 'string' then
               return localdata[val]
        elseif type(val) == 'function' then
               return val(localdata, localdata.item, params)
        elseif type(val) == 'table' then
               for i, j in pairs(val) do -- se vários parâmetros possíveis (legado do código antigo), tomar o primeiro não-vazio
                          if localdata[j] then
                                    return localdata[j]
                      end
               end
        end
end

local function addMaintenanceCat(cat, sortkey)
          if page.namespace ~= 0 then
               return ''
        end
        if cat then
        maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
        end
end

function p.separator(params)
        local style = params['estilo separador'] or {}
        style.height = style.height or '2px'
        style['background-color'] = style['background-color'] or maincolor
 
    return mw.html.create('hr'):css( style )
end

function p.buildtitle(params)
        local text = getValue(params.value, params) or params.textdefaultvalue or  getWikidataValue(params) or mw.title.getCurrentTitle().text
    local subtext = getValue(params.subtitle) or  getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue
    if subtext and (subtext ~= text) then
              text = text .. '<br /><small>' .. subtext .. '</small>'
        end
        local style = {
                  border = 'none',
             ['text-align'] = 'center',
             ['font-size'] = '1.3em',
             padding = '0',
             display = 'table',
             height = '45px',
             width = '100%',
             ['*height'] = 'auto', -- be kind ie7
             ['*padding'] = '12px 0',
    }
    local style2 = {
                  display = 'table-cell',
                  ['vertical-align'] = 'middle',
                  padding = '3px',
    }
        local icon = params.icon or ''
        if icon ~= '' and not params.large then
                   icon = ' ' .. icon
        else
           -- style.padding = '12px'
                icon = " "
        end
        local class = 'topo' .. icon
 
    -- overwrites with those provided in the module
        -- local style = {}
        style['background-color'] = maincolor
        style['color'] = thirdcolor
        if params.style then
                  for i, j in pairs(params.style) do
                             style[i] = j
                end
        end
        local title = mw.html.create('div')
                  :addClass(class)
            :css(style)
            :tag('div')
            :css(style2)
        :wikitext(text)
            :allDone()
        return title
end
p.buildTitle = p.buildtitle

function p.buildnavbox(params)
 
    -- definição do estilo
        local class = "navbox " .. (params.class or '')
        local style = params.style or {['overflow'] = 'hidden'}

        if params.separated then -- opções para adicionar uma linha de separação acima
               class = class .. ' bordered'
            style['border-top'] = '1px solid' .. maincolor
        end

        -- ajuste de parâmetros de dados
        params.previousval = params.previousval or params.previousparameter -- nome do parâmetro obsoleto
        params.nextval = params.nextval or params.nextparameter
 
    if params.previousproperty then
               params.previouswikidata = {property = params.previousproperty}
        end
        if params.nextproperty then
               params.nextwikidata = {property = params.nextproperty}
        end
 

    local previousval = getValue(params.previousval, params) or getWikidataValue(params, 'previouswikidata')
        local nextval = getValue(params.nextval, params) or getWikidataValue(params, 'nextwikidata')
 
    local navbox
        if params.inner then -- para quem está dentro de uma tabela
               navbox = mw.html.create('tr'):tag('th'):attr('colspan', 2)
            style['font-weight'] = style['font-weight'] or 'normal'
        else
        navbox = mw.html.create('div')
        end
 
    navbox
    :css({['background-color'] = '#E6E6E6'})
        :addClass(class)
        -- :css(style)
        :css{border = '2px ' .. maincolor, ['font-weight'] = 'normal'}
        :tag('div')
        :addClass('prev_bloc')
        :wikitext(previousval)
        :done()
        :tag('div')
        :addClass('next_bloc')
        :wikitext(nextval)
        :done()
        :allDone()
        return navbox
end
p.buildNavbox = p.buildnavbox

function p.buildimages(params)
        local images = {}
        local upright, link, caption, alt, size    -- size is deprecated
        if type(params.imageparameters) == 'string' then
                params.imageparameters = {params.imageparameters}
        end
        if not params.imageparameters then -- se não houver nenhum parâmetro de imagem, continue, talvez haja uma imagem padrão definida no módulo de infobox
               params.imageparameters = {}
        end
        for j, k in ipairs(params.imageparameters) do
               table.insert(images, localdata[k])
        end
        -- Images de Wikidata
        if #images == 0 and localdata.item then
           if params.property then
                                 params.wikidata = {entity = localdata.item, property = params.property}
            end
            if params.wikidata then
                        local wdq = params.wikidata
                    wdq.excludespecial = true
                    if type(wdq) == 'table' then
                           wdq.entity = wdq.entity or localdata.item
                        wdq.numval = wdq.numval or params.numval or 1
                        images = wd.getClaims(wdq)
                end
                if type(wdq) == 'function' then
                           images = params.wikidata()
                        if type(images) == 'string' then
                        return images
                        end --provavelmente é um erro no pedido => mostrar a mensagem
                end
                if (not images) then
                           images = {}
                end
                if (#images > 0) and (params.wikidata.property) then
                           addWikidataCat(params.wikidata.property)
                end

                if type(images[1]) == 'table' then
                      for i, image in pairs(images) do
                               if image.mainsnak.snaktype ~= 'value' then
                            return
                        end
                        if #images == 1 then -- se apenas uma imagem, usamos a legenda (se mais duas imagens, como formatar?)
                                      caption = wd.getFormattedQualifiers('P18', {qualifier = 'P2096'}, {isinlang = 'pt'})
                        end
                        images[i] = image.mainsnak.datavalue.value
                    end
               end
              end
        end

        -- Imagens por padrao
        if #images == 0 then
               if params.maintenancecat then
                       addMaintenanceCat(params.maintenancecat, params.sortkey)
            end
            if params.defaultimages then
                       images = params.defaultimages
                    if type(images) == 'string' then
                           images = {images}
                    end
                    upright = params.defaultimageupright
                    caption = params.defaultimagecaption
                    link = params.defaultimagelink
                    alt = params.defaultimagealt
                    if not alt and ( images[1] == 'Padrao.svg' or images[1] == 'Padrao 2.svg' ) then
                            alt = 'uma ilustração licenciada gratuita seria bem-vinda'
                    end
            end
        end
        if #images == 0 then
               return nil
        end
 
    upright = upright or getValue(params.uprightparameter) or params.defaultupright or "1" -- 1.2 deixa uma margem
        link = link or getValue(params.linkparameter) or params.defaultlink
        caption = caption or getValue(params.captionparameter) or params.defaultcaption
        alt = alt or getValue( params.altparameter) or params.defaultalt

        -- tamanho com "size" (obsoleto)
        size = size or getValue(params.sizeparameter) or params.defaultsize or params.tamanho-- deprecated
        if size then
               local numsize = size:gsub('px', '')
            numsize = mw.ustring.gsub(numsize, 'x.*', '')
            numsize = tonumber(numsize)
            if type(numsize) ~= 'number' or numsize > 280 then
                       addMaintenanceCat("tamanho da imagem inválido")
            end
            if tonumber(size) then
                       size = size .. 'px'
            end
            size = '|' .. size
        else
        size = ''
        end
 
    if tonumber(upright) then
               upright = tostring(tonumber(upright) ) / #images
        end
        if tonumber(size) then
               size = tostring(tonumber(size) ) / #images
        end

    local style = params.style or {
                  padding ='2px 0',
        ['text-align'] = 'center',
          ['display'] = 'flex',
          ['justify-content'] = 'space-around',
          ['align-items'] = 'center',
    }
        local styleLegend = params.stylelegend or {
                  ['font-size'] = '0.9em',
          ['text-align'] = 'center',
          ['margin'] = '5px 0 5px 0',
        }

    -- Imagem da peça

        local imagesString = ''
        for i,image in pairs(images) do
                if image == '-' then
                       return
            end
            imagesString = imagesString ..      '[[File:' .. image .. "|" .. size .. '|frameless'
            if alt then
            imagesString = imagesString .. '|alt=' .. alt
            end
            if link then
                       imagesString = imagesString .. '|link=' .. link
            end
            if upright then
                       imagesString = imagesString .. '|upright=' .. upright
            elseif #images > 1 then
                           imagesString = imagesString .. '|upright=' .. ( 1 / #images )
            end
            imagesString = imagesString .. ']]'
        end

        local image = mw.html.create('div')
                  :addClass("image")
            :css(style)
            :wikitext(imagesString)

        -- Parte da legenda
        local captionobj
        if caption then
               captionobj = mw.html.create('p')
                    :css(styleLegend)
            :wikitext(caption)
                    :css(params.style or {})
                    :addClass("caption")
                    :done()
        end
 
        -- separador
           local separator
        if params.separator then
               separator = separator(params)
        end
        return mw.html.create('div')
                :node(image)
                :node(captionobj)
                :node(separator)
                :done()
end
p.buildImages = p.buildimages

function p.buildtext(params)
        local class = params.class or ''
        local style = {
                ['text-align'] = 'center',
            ['font-weight'] = 'bold'
        }
        if params.style then
               for i, j in pairs(params.style) do
                        style[i] = j
            end
        end
        local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue
        if text == '-' then
               return
        end
        if not text then
                addMaintenanceCat(params.maintenancecat, params.sortkey)
        return nil
        end
        local formattedtext = mw.html.create('p')
                :addClass(class)
            :css(style)
            :wikitext(text)
            :done()
        return formattedtext
end
p.buildText = p.buildtext

function p.buildrow(params)
    local class = params.class or ''
        local style = params.style or {}
    style['vertical-align'] = 'middle'

    local style2 = {
          ['text-align'] = 'left',
          ['padding-right'] = '10px',
          ['width'] = '8em',
          ['max-width'] = '140px',
          ['word-wrap'] = 'normal',
    }
        local value, number =  getValue(params.value, params)
        if (value == valueexpl) then
                value = nil
            params.wikidata.expl = false
        end
        if (not value) then
               value, number = getWikidataValue(params, 'wikidata')
        end
        if (not value) and (params.property) then
               value, number = expandQuery{ property = params.property, ucfirst = params.ucfirst }
        end
        if not value then
                value = params.defaultvalue
        end
        if value == '-' then
                return nil
        end
        if not number then
                number = 0 -- == indefinido
        end

        if not value then
                if params.maintenancecat then
                       local maintenancecat = getValue(params.maintenancecat, params)
                    addMaintenanceCat(maintenancecat, params.sortkey)
            end
            return nil
        end

        local label = params.label
        if number > 1 and (params.plurallabel) then
               label = params.plurallabel
        elseif number == 1 and (params.singularlabel) then
                label = params.singularlabel
        end
        if type(label) == 'function' then
               label = label(localdata, localdata.item)
        end

        -- format
        local formattedvalue = mw.html.create('div')
        :wikitext('\n' .. value) -- 'não é necessário quando o valor é uma lista que começa com '*' ou '#'
 
        if (params.hidden == true)then
                formattedvalue
                    :attr({class="NavContent", background= "none !important", ['padding-top'] = "0 !important", ['padding-bottom']="0 !important", ['border-top']= "1px solid grey !important", ['border-bottom']= "1px solid grey !important", ['margin-left']= "2em !important", ['margin-right']= "2em !important", style="display: none; text-align: left;"})
            formattedvalue = mw.html.create('div')
                        :attr({class="NavFrame", title="[Mostrar]/[Esconder]", style="border: none; padding: 0;"})
                    :node(formattedvalue)
        end
        formattedvalue =  mw.html.create('td')
                   :node(formattedvalue)
                   :allDone()
 
    local formattedlabel
        if label then
               formattedlabel = mw.html.create('th')
                 :attr('scope', 'row')
                 :css(style2)
                 :wikitext(label)
                 :done()
        end
        local row = mw.html.create('tr')
            :attr('scope', 'row')
            :addClass(class)
            :css(style)
            :node(formattedlabel)
            :node(formattedvalue)
            :done()
 
        return row
end
p.buildRow = p.buildrow

function p.buildsuccession(params)
        if not params.value then
                return nil
        end
 
    --local style = params.style or {}
        --style['text-align'] = style['text-align'] or 'center'
        --style['color'] = style['color'] or '#000000'
        --style['background-color'] = style['background-color'] or '#F9F9F9'
 
    local rowI = mw.html.create('tr')
 
    local colspan = '2'
        cellI = mw.html.create('td')
            :attr({colspan = colspan})
                :attr({align = 'center'})
 
    local styleT = {}
        styleT['background-color'] = 'transparent'
        styleT['width'] = '100%'
        tabC = mw.html.create('table')
            :attr({cellspacing = '0'})
                :addClass('navigation-not-searchable')
                :css(styleT)
 
    local row = mw.html.create('tr')

        local color = params.color

        local style = {}
        local arrowLeft
        local arrowRight
 
    if color == 'default' then
               style['background-color'] = '#E6E6E6'
            arrowLeft = '[[Ficheiro:Fleche-defaut-gauche.png|13px|alt=Precedente|link=]]'
            arrowRight = '[[Ficheiro:Fleche-defaut-droite.png|13px|alt=Precedente|link=]]'
        else
        style['background-color'] = color
            arrowLeft = '[[Ficheiro:Fleche-defaut-gauche-gris-32.png|13px|alt=Próximo|link=]]'
            arrowRight = '[[Ficheiro:Fleche-defaut-droite-gris-32.png|13px|alt=Próximo|link=]]'
        end
 
    local styleTrans = {}
        styleTrans['background-color'] = '#F9F9F9'
 
    local values = params.value
        local before = values['before']
        local center = values['center']
        local after = values['after']
 
    local widthCell = '44%'
        if center then
               widthCenter = '28%'
            widthCell = '29%'
        end
 
    local formattedbefore
        if before then
               formattedbefore = mw.html.create('td')
                    :attr({valign = 'middle'})
                    :attr({align = 'left'})
                    :attr({width = '5%'})
                    :css(style)
                    :wikitext(arrowLeft)
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(style)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({align = 'left'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(style)
                    :wikitext(before)
                    :done()
                row:node(formattedbefore)
        else
        formattedbefore = mw.html.create('td')
                    :attr({valign = 'middle'})
                    :attr({align = 'left'})
                    :attr({width = '5%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedbefore = mw.html.create('td')
                    :attr({align = 'left'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
        end
 
    local formattedcenter
        formattedcenter = mw.html.create('td')
            :attr({width = '1%'})
            :css(styleTrans)
            :wikitext('')
            :done()
        row:node(formattedcenter)
 
    if center then
               formattedcenter = mw.html.create('td')
                    :attr({align = 'center'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCenter})
                    :css(style)
                    :wikitext(center)
                    :done()
            row:node(formattedcenter)
            formattedcenter = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedcenter)
        end
 
    local formattedafter
        if after then
               formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(style)
                    :wikitext(after)
                    :done()
            row:node(formattedafter)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(style)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = '5%'})
                    :css(style)
                    :wikitext(arrowRight)
                    :done()
            row:node(formattedafter)
        else
        formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = widthCell})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedafter)
            formattedbefore = mw.html.create('td')
                    :attr({width = '1%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedbefore)
            formattedafter = mw.html.create('td')
                    :attr({align = 'right'})
                    :attr({valign = 'middle'})
                    :attr({width = '5%'})
                    :css(styleTrans)
                    :wikitext('')
                    :done()
            row:node(formattedafter)
        end
 
    row:done()
        tabC:node(row)
        tabC:done()
        cellI:node(tabC)
        cellI:done()
        rowI:node(cellI)
        rowI:allDone()
 
    return rowI
end
p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)
 
    if not params.value then
                return nil
        end
 
    --local style = params.style or {}
        --style['text-align'] = style['text-align'] or 'center'
        --style['color'] = style['color'] or '#000000'
        --style['background-color'] = style['background-color'] or '#F9F9F9'
        local class = params.class
        local rowcolor
        if params.color == 'secondcolor' then
               rowcolor = secondcolor
        else
        rowcolor = params.color
        end
 
    local style = {}
        style['padding'] = '4px'
        style['text-align'] = 'center'
        style['background-color'] = rowcolor or '#F9F9F9'
        style['color'] = '#000000'
 
    local text = params.value

        local colspan ='2'

        local formattedlabel
        formattedlabel = mw.html.create('th')
            :attr({colspan = colspan})
            :css(style)
            :wikitext(text)
            :done()

        local row = mw.html.create('tr')
                :addClass(class)
            :css(style)
            :node(formattedlabel)
            :done()
 
    return row
end
p.buildRow1Col = p.buildrow1col

function p.buildtable(params)
        local tab = mw.html.create('table'):css(params.style or {})

        local rows = params.rows
 
    -- expand parameters so that we have a list of tables
        local i = 1

        while (i <= #rows) do
                  local l = rows[i]
            if type(l) == 'function' then
                       l = l(localdata, localdata.item)
            end
            if (type(l) == 'table') and (l.type == 'multi') then
                       table.remove(rows, i)
                    for j, row in ipairs(l.rows) do
                               table.insert(rows, i + j - 1, row)
                    end
            elseif type(l) == 'nil' then
                        table.remove(rows, i)
            elseif type(l) ~= 'table' then
                           return error('as linhas da infobox ("rows") devem ser tabelas, e ' .. type(l))
            else
            i = i + 1
            end
        end

        -- CREATE ROW
        local expandedrows = {}
        for k, row in ipairs(rows) do
                   local v = p.buildblock(row)
            if v then
            table.insert(expandedrows, v)
            end
        end
        if (#expandedrows == 0) then
               return nil
        end
        rows = expandedrows

        -- ADD TITLE
        local title
        if params.title or params.singulartitle or params.pluraltitle then
               local text
            if #rows > 1 and params.pluraltitle then
                   text = params.pluraltitle
            elseif #rows == 1 and params.singulartitle then
                       text = params.singulartitle
            else
            text = params.title
            end

            local style = params.titlestyle or {}
            style['font-weight'] = style['font-weight'] or 'bolder'
            style['width'] = style['width'] or '23em'
            style['text-align'] = style['text-align'] or 'center'
            style['line-height'] = style['line-height'] or '1.5'
            style['margin'] = style['margin'] or '0 0 5px 0'
            --style['padding-top'] = style['padding-top'] or '.5em'
            --style['padding-bottom'] = style['padding-bottom'] or '.5em'
            style['color'] = style['color'] or thirdcolor
            style['background-color'] = style['background-color'] or maincolor
        style['max-width'] = style['max-width'] or '300px'
        style['word-wrap'] = style['word-wrap'] or 'break-word'



            local colspan ='2'
            title = mw.html.create('caption')
                      :attr({colspan = colspan})
                :css(style)
                :wikitext(text)
                :done()
     end
 
    if title then
               tab:node(title)
        end
 
    for i, j in pairs (rows) do
                   tab:node(j)
        end
 
    if params.separator then
               local separator = p.separator(params)
            tab:node(separator)
        end
        tab:allDone()
        return tab
end
p.buildTable = p.buildtable

function p.buildinvalidblock(args)
        addMaintenanceCat(defaultcat)
        local text = ''
        if type(args) ~= 'table' then
               text = "Blocos de infobox devem ser tabelas"
        else
        text = i18n["invalid block type"] .. ' : ' .. (args.type or '??')
        end
        return text
end
p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

        -- configuração de exibição
        local maplist = getValue(params.maps)
        local pointtype = params.pointtype
        local maptype = params.maptype -- escolhe o tipo de mapa mais adequado (alívio, administrativo, etc.)
        if type(maplist) == 'function' then
               maplist = maplist(localdata, localdata.item)
        end
        local width = tonumber(params.largura) or 270 -- 280 padrao f.ajustar
        if width > 280 then
               addMaintenanceCat("!Erro de infobox - imagem muito grande")
            return 'imagem muito grande, a largura deve ser menor ou igual a 280px'
        end

        -- mostrar os dados locais
        local pointtable = {}
        local globe = params.globe
        if params.latitude then
               local lat, long
             if type(params.latitude) == 'function' then
                        lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item)
        else
        lat, long = localdata[params.latitude], localdata[params.longitude]
            end
            if lat then
            table.insert(pointtable, {latitude = lat, longitude = long})
             end
        end

        -- mostrar os dados wikidata
        local function processWDval(claim, displayformat)
                  if not claim then
                       return nil
            end
            local val = wd.formatSnak( claim.mainsnak )
            return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker}
        end
 
    local function getWDvals(query)
                  query.excludespecial = true
            query.numval = query.numval or 1
            query.entity = query.entity or localdata.item
            local claims = wd.getClaims(query)
            if (not claims) then
                   return
            end
            for i, claim in ipairs(claims) do
                       claim = processWDval(claim, query)
                table.insert(pointtable, claim)
            end
        end
 
    if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then
               for i, query in ipairs(params.wikidata) do
                           if type(query) == 'function' then
                           query = query()
                    end
                    if query then
                              getWDvals(query)
                    end
            end
        end
 
    if (not pointtable) or (#pointtable == 0) then
               return nil
        end
 
    local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor }
        if params.params and type(params.params) == 'table' then -- parâmetro adicionais
               for i, j in pairs(params.params) do
                           newparams[i] = j
            end
        end
        return require('Módulo:Mapa').multimap(newparams)
end
p.buildMap = p.buildmap

function p.buildexternaltext(params)
    local value = getValue(params.value)
        if value and (type(value) == 'string') then
               externaltext = externaltext .. value
        end
end
p.buildExternalText = p.buildexternaltext

function p.buildfooter(params)
        if not params then
                   params = {}
        end
 
    local class = 'navbar noprint bordered ' .. (params.class or '')
        local style = params.style or {['border-width'] = '1px'}
        style['margin-top'] = '5px' -- espaço vertical para o footer
    style['margin-bottom'] = '-0.125em'
        style['border-top'] = style['border-top'] or '1px solid ' .. maincolor
    style['border-bottom'] = '0'
    style['display'] = 'block'

    local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.name, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']'
                  .. ' - [' .. tostring( mw.uri.fullUrl( page.name, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

        local itemlinkstr
        if localdata.item then
               itemlinkstr = '[[d:' .. localdata.item.id .. '|' .. i18n['edit item'] .. ']]'
        end
        local editstr = backlinkstr
       if itemlinkstr then
                editstr = editstr .. ' - ' .. itemlinkstr
        end
        local editlinkspan =  mw.html.create('span')
                  :css({['text-align'] = "left"})
            :css({['width'] = "23em"})
        --:css({['float'] = "left"})
            :addClass('plainlinks') --?existe
            :wikitext(editstr)
            :done()
        local doclinkstr = '[[Imagem:Info Simple.svg|12px|link=' .. localdata.templatename .. '|' .. i18n['see doc'] .. ']]'
        -- Se esse link nem sempre funcionar, adicione uma variável para o nome da infobox recuperada pelo quadro
        local doclinkspan = mw.html.create('span')
                  :css({['text-align'] = "right"})
            :css({['float'] = "right"})
            :wikitext(doclinkstr)
            :done()
 
    local footer = mw.html.create('p')
                  :addClass(class)
            :css(style)
            :node(editlinkspan)
            :node(doclinkspan)
        return footer
end
p.buildFooter = p.buildfooter

function p.buildblock(block)
        if type(block) == 'function' then
               block = block( localdata )
        end

        local blocktypes = { -- list of functions for block buildings
                  ['invalid'] = p.buildinvalidblock,
            ['external text'] = p.buildexternaltext,
            ['footer'] = p.buildfooter,
            ['images'] = p.buildimages,
            ['map']= p.buildmap,
            ['mixed'] = p.buildrow,
            ['navbox'] = p.buildnavbox,
            ['table'] = p.buildtable,
            ['row'] = p.buildrow,
            ['row1col'] = p.buildrow1col,
            ['succession'] = p.buildnavbox,
            ['text'] = p.buildtext,
            ['title'] = p.buildtitle,
        }
        if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then
           return blocktypes['invalid'](block)
        end
        return blocktypes[block.type](block)
end
p.buildBlock = p.buildblock

function p.build()
 
    localdata = require( 'Módulo:Infobox/Localdata' )
        item = localdata.item

        -- assign rank to the infobox, "secondary" means special formatting like no displaytitle for coordinates
        local infoboxrank = 'main' -- main infobox of the page, with coordinates displayed in title etc.
        if page.namespace ~= 0 then
               infoboxrank = 'secondary'
        end
        -- if infobox is linked to another item: rank = secondary
        if localdata.item then
               local itemlink = mw.wikibase.sitelink(localdata.item.id)
            local pagetitle = mw.title.getCurrentTitle().text
            if (itemlink or '') ~= pagetitle then
                       infoboxrank = 'secondary'
            end
        end
        localdata.infoboxrank = infoboxrank

        -- load infobox module page
        local moduledata = require('Módulo:Infobox/' .. localdata.modulename)
        moduledata.name = localdata.modulename
        -- defines main color
        maincolor = localdata['cor infobox'] or localdata['caixa de cor'] or moduledata.maincolor or maincolor
        secondcolor =  moduledata.secondcolor or secondcolor
        thirdcolor =  moduledata.thirdcolor or thirdcolor
        if maincolor:match( '^%x%x%x%x%x%x$' ) or maincolor:match( '^%x%x%x$' ) then
               maincolor = '#' .. maincolor
        end
 
        -- class
        local class = 'infobox_v2'
        if moduledata.class then
            class = class .. ' ' .. moduledata.class
        end
 
    -- style
        local style = moduledata.style or {} --{'width: 20em; text-align: left; font-size: 88%; max-width: 23em'}
        style['font-size'] = style['font-size'] or '88%'
 
    -- build infobox
        infobox :addClass(class)
            :attr({cellpadding= "3"})
                :attr({border= "0"})
                :css(style)
        for i, j in pairs( moduledata.parts ) do
                   infobox:node( p.buildblock(j) )
        end
        infobox :node(p.buildfooter(moduledata.footer))
                :done()

        if CategorizacaoABeAD.hasAnyBadge() == '1' then
            maintenance = maintenance .. (CategorizacaoABeAD.badgesCategories())
        end

        return tostring(infobox) .. externaltext, maintenance
end

return p