Módulo:Infobox/Estrada

Origem: Wikipédia, a enciclopédia livre.
Documentação do módulo[ver] [editar] [histórico] [purgar]

Descrição[editar código-fonte]

Este módulo implementa a predefinição {{Info/Estrada}}

Outra documentação:

local localdata = require 'Módulo:Infobox/Localdata'
local general = require 'Módulo:Infobox/Funções'
local wikidata = require 'Módulo:Infobox/Wikidata'
local linguistic = require 'Módulo:Linguística'

local function DivisionsAdministratives()
    if not localdata.item then
        return nil
    end
    -- on cherche le pays pour être sûr de s'arrêter avant
    local country = wikidata.stringTable{entity = localdata.item, property = 'P17', displayformat = 'raw'}
    if table.getn(country) > 1 then
        return nil
    end
    local countryid
    if country then
        countryid = country[1]
    end

    -- récupération des valeurs
    local list = wikidata.transitiveVals(localdata.item, {property = 'P131', atdate = 'today'}, 3, 30, countryid)
    if not list then
        return nil
    end

    -- criação das colunas
    local rows = {}
    for i, div in pairs(list) do
        if (div == countryid) then
            break
        end
        local label = wikidata.formatStatements{
            entity = div,
            property =  'P31',
            defaultlinkquery = {property = 'P2354'},-- se não tem link, ligar à página de lista e.g lista dos Estados da Califórnia
            defaultlink = '-', -- se nenhum link Wikipédia, não tem link Wikidata
            labelformat = function(id)
                local str = wikidata.getLabel(id)
                if str then
                    return linguistic.removecomplement(str)
                else
                    return ''
                end
            end
        }
        local val = wikidata.formatEntity(div)
       
        table.insert(rows, 1, {type = 'row', label = label, value = function() return val end})
    end
    return rows
end

return
    {
    maincolor = '#CCCCCC',
    parts =
        {
            -- Título
            {
                type = 'title',
                value = function()
                    return localdata['número de rota']
                        or wikidata.formatStatements{entity = localdata.item, property = 'P1824', conjtype = ' / '}
                        or wikidata.getLabel(id)
                    end,
                subtitle = function()
                    local localname = localdata['nome']
                    if not localname then
                        return nil
                    end
                    localname = '<i>' .. localname .. '</i>'
                    local lang = localdata['código língua']
                    lang = require 'Módulo:Língua'.languagueIcon{nil, lang}
                    return linguistic.conj({lang, localname}, ' ')
                end,
                wikidatasubtitle = function()
                    local data = wikidata.formatAndCat({entity = localdata.item, property = 'P1705', conjtype = 'new line', showlang = true})
                    if (data == nil) or (data == "") then
                        return nil
                    else
                        return '<i>' .. data .. '</i>'
                    end
            end,
                icon = 'route'
            },
       
            -- Sinalética da rota
            {
                type = 'images',
                defaultupright = '0.4',
                defaultalt = 'Sinalética representando a rota',
                wikidata = {property = 'P14'},
                numval = 5,
                style = {padding = '0 0 6px 0'}
                },
            general.mainimage('!Artigos sem imagens'),
            -- Mapa de localização
            {
                type = 'images',
                imageparameters = 'mapa',
                sizeparameter = 'tamanho mapa',
                captionparameter = 'legenda mapa',
                wikidata = {property = 'P15'},
                numval = 1
                },
        -- Tabela sem título
            {
                type = 'table',
                rows = {
                    {
                        type = 'mixed',
                        label = 'Outro nome',
                        plurallabel = 'Outros nomes',
                        valeur = 'outrso nomes',
                        wikidata = {property = 'P1449', showlang = true, conjtype = 'new line'}
                    },
                    {
                        type = 'mixed',
                        label = 'Histórico',
                        wikidata = {property = 'P793', showdate = true, sorttype = 'chronological',
                            conjtype = 'new line'}
                    }
                }
            },
        -- Tabela de características
            {
                type = 'table',
                title = 'Características',
                rows =     {
                    {
                        type = 'mixed',
                        label = 'Comprimento',
                        value = 'comprimento',
                        wikidata = {property = 'P2043', targetunit = 'quilómetro', rounding = 1}
                    },
                    {
                        type = 'mixed',
                        label = 'Direção',
                        value = function(localdata)
                            local dir = localdata['direção'] or wikidata.formatStatements{
                                entity = localdata.item,
                                property = {'P559', 'P609'},
                                showonlyqualifier = 'P560',
                                conjtype = '/',
                                link = '-',
                                ucfirst = '-',
                                removedupes = true
                            }
                            if (dir == nil) or (dir == "") then
                                return nil
                            end
                            return dir
                            end
                        },
                    {
                        type = 'mixed',
                        label = 'Itinerário',
                        value = 'itinenário',
                        wikidata = {
                            property = 'P609',
                            showqualifiers = 'P559',
                            conjtype = ' – ',
                            labelformat = function(id)
                                return wikidata.formatStatements{entity = id, property = 'P1824', numval = 1} or wikidata.getLabel(id)
                            end
                        }
                    },
                    {
                        type = 'mixed',
                        label = 'Intersecções',
                        value = {'interseções', 'intersecções'},
                        wikidata = function()
                            local data = wikidata.formatAndCat{
                                entity = localdata.item,
                                property = 'P2789',
                                showqualifiers = 'P131',
                                conjtype = 'new line',
                                labelformat = function(id)
                                    return wikidata.formatStatements{ entity = id, property = 'P1824', numval = 1 } or wikidata.getLabel(id)
                                end
                            }
                            if (data == nil) or (data == "") then
                                return nil
                            else
                                return "<div class='NavFrame'><div class='NavHead'></div><div class='NavContent' style='text-align:left; display:block;'>" .. data .. '</div></div>'
                            end
                        end
                    },
                    {type = 'mixed', label = '[[Rodoanel|Cintura periférica]]', value = 'cintura periférica' },
                    {
                        type = 'mixed',
                        label = 'Sistema',
                        plurallabel = 'Sistemas',
                        value = 'sistema', -- sistema de autoestradas
                        wikidata = {property = 'P16', defaultlinkquery = {property = 'P2354'}}
                    },
                    {
                        type = 'mixed',
                        label = 'Outra classificação',
                        plurallabel = 'Outras classificações',
                        value = 'Outra classificação',
                        wikidata = {
                            property = {'P361', 'P1382'},
                            excludespecial = true,
                            labelformat = function(id)
                                return wikidata.formatStatements{entity = id, property = 'P1824', numval = 1} or wikidata.getLabel(id)
                            end
                        }
                    },
                    {
                        type = 'mixed',
                        label = 'Operador',
                        plurallabel = 'Operadores',
                        value = 'operador',
                        wikidata = {property = 'P137', conjtype = 'new line'}
                    },
                    {
                        type = 'mixed',
                        label = 'Mantido por',
                        plurallabel = 'Mantidos por',
                        value = 'mantido por',
                        wikidata = {property = 'P126', conjtype = 'new line'}
                    }
                }
            },
        -- Territórios percorridos
            {
                type = 'table',
                title = 'Territórios atravessados',
                rows =     {
                    general.country(),
                    {type = 'multi', rows = DivisionsAdministratives() or {} },
                    {type = 'mixed', label = 'Cidade principal', plurallabel = 'Cidades principais', value = 'cidades principais', property = 'P1302' },
                }
            }
        }
    }