Módulu:Ficha de llicencia de software

La documentación pa esti módulu pue crease en Módulu:Ficha de llicencia de software/usu

local p = {}
local ModuluArgumentos = require('Módulu:Argumentos')
local ModuluFicha = require('Módulu:Ficha')    
local ModuluWikidata = require('Module:Wikidata')
local ModuluPaxines = require('Módulu:Páxines')
local elementoTabla = require('Módulu:Tables').elemento
local argumentos
local Entidad

function p.Ficha(frame)
    argumentos = ModuluArgumentos.obtenerArgumentosConValor(frame)
    Entidad = mw.wikibase.getEntity(argumentos.id) or {}
    local Titulo = argumentos['títulu'] or obtenerEtiquetaWikidata() or ModuluPaxines.nombrePagina({desambiguar='sí'})
    -- Propiedades
    local Imaxe = argumentos['imaxe']
    local Pie
    if Imaxe then
        Pie = argumentos['pie de foto']
    else
        Imaxe, Pie = obtenerImaxeWikidata()
    end
    local Tamano = argumentos['tamañu'] or "250px"
    local Autor = argumentos['autor'] or propiedad('P50', {['enllaz']='sí', ['linkback']='sí'}) or ""
    local Version = argumentos['versión'] or propiedad('P348', {['linkback']='sí'}) or ""
    local Editorial = argumentos['publicáu'] or propiedad('P123', {['linkback']='sí'}) or ""
    local Fecha = argumentos['fecha'] or propiedad('P577', {['linkback']='sí'}) or ""
    local AprobadoDebian
    local AprobadoFSF
    local SoftwareLibre
    local AprobadoOSI
    local Copyleft
    if argumentos['aprobáu Debian'] then
        AprobadoDebian = argumentos['aprobáu Debian']
    elseif esUnValor(Entidad,'P790','Q903054') then
        AprobadoDebian = frame:preprocess('{{sí}}')
    else
        AprobadoDebian = ""
    end
    if argumentos['aprobáu FSF'] then
        AprobadoFSF = argumentos['aprobáu FSF']
    elseif esUnValor(Entidad,'P790','Q48413') then
        AprobadoFSF = frame:preprocess('{{sí}}')
    else
        AprobadoFSF = ""
    end
    if argumentos['software llibre'] then
        SoftwareLibre = argumentos['software llibre']
    elseif esUnValor(Entidad,'P31','Q3943414') or esUnValor(Entidad,'P31','Q1437937') or esUnValor(Entidad,'P31','Q5975031') then
        SoftwareLibre = frame:preprocess('{{sí}}')
    else
        SoftwareLibre = ""
    end
    if argumentos['códigu abiertu'] then
        AprobadoOSI = argumentos['códigu abiertu']
    elseif esUnValor(Entidad,'P790','Q845918') then
        AprobadoOSI = frame:preprocess('{{sí}}')
    else
        AprobadoOSI = ""
    end
    local CompatibleGPL = argumentos['compatible GPL'] or "" -- Pendiente proponer propiedad "compatible con"
    if argumentos['copyleft'] then
        Copyleft = argumentos['copyleft']
    elseif esUnValor(Entidad,'P31','Q5975031') then
        Copyleft = frame:preprocess('{{sí}}')
    else
        Copyleft = ""
    end
    local UsoOtrasLicencias = argumentos['compatible GNU'] or "" -- Pendiente proponer propiedad "compatible con"
    local SitioWeb = argumentos['sitiu web'] or propiedad('P856', {['linkback']='sí'}) or ""
    local TablaFicha = {
        entidad = argumentos.id,
        titulo  = capitalizar(Titulo),
        clasetitulo = 'informática',
        estilotitulo = 'background-color: #ccccff; color:#000;',
        estiloseccion = 'background-color: #ccccff; color:#000;',
        estiloetiqueta = 'background-color: #ddddff; width:35%',
        estilodatos = 'width:65%',
        imaxe = Imaxe,
        ['tamañuimaxe'] = Tamano,
        pie = Pie,
        estilopie = 'font-size:88%',
        {tipo='sección',
            titulo = "Información",
            {'Autor', Autor},
            {'[[Versión de software|Versión]]', Version},
            {'Edición', Editorial},
            {'Fecha', Fecha},
            {'Compatible con [[Directrices de software llibre de Debian|DFSG]]', AprobadoDebian},
            {'Aprobáu pola [[Free Software Foundation|FSF]]', AprobadoFSF},
            {'[[Software llibre]]', SoftwareLibre},
            {'Aprobáu pola [[Open Source Initiative|OSI]]', AprobadoOSI},
            {'Compatible cola [[GNU General Public License|GPL]]', CompatibleGPL},
            {'[[Copyleft]]', Copyleft},
            {'Utilizable xunto con otres llicencies', UsoOtrasLicencias},
            {'Sitiu web', SitioWeb},
        }
    }
    return ModuluFicha.infobox(TablaFicha)
end

function obtenerEtiquetaWikidata()
    if Entidad and Entidad.labels and Entidad.labels.es then
        return Entidad.labels.es.value
    end
end

function obtenerImaxeWikidata()
    local imaxe, valorImaxe, piesDeImaxe, k, pieDeImaxe
    if not Entidad then
        return
    end
    --  Obtener la primera imaxe en Wikidata de la persona
    local imaxe = elementoTabla(Entidad, 'claims','P154',1)
    if not imaxe then
        return
    end
    valorImaxe =  elementoTabla(imaxe, 'mainsnak','datavalue','value')
    piesDeImaxe =  elementoTabla(imaxe, 'qualifiers','P2096')
    -- Encontrar el pie n'asturianu
    if piesDeImaxe then
        for k,pieDeImaxe in pairs(piesDeImaxe) do
            if pieDeImaxe.datavalue.value.language == 'ast' then
                return valorImaxe, pieDeImaxe.datavalue.value.text
            end
        end
    end
    -- Si nun hai pie d'imaxe n'asturianu comprueba si hay fecha especificada para la imaxe
    piesDeImaxe = elementoTabla(imaxe, 'qualifiers', 'P585')
    if piesDeImaxe and piesDeImaxe[1] then
        return valorImaxe, nombre .. ' ast ' .. require('Module:Wikidata/Data').FormateaFechaHora(piesDeImaxe[1].datavalue.value, {['formatoFecha']='añu',['enllaz']='no'})
    end
    -- Sin pie d'imaxe n'asturianu
    return valorImaxe
end

function propiedad(idPropiedad,opciones)
    if Entidad and Entidad.claims and Entidad.claims[idPropiedad] then
        if not opciones then
            opciones = {['linkback']='sí'}
        end
        opciones.entityId  = Entidad.id
        opciones.propiedad = idPropiedad
        valorPropiedad = ModuluWikidata.getPropiedad(opciones,Entidad.claims[idPropiedad])
        return valorPropiedad
    end
end

function esUnValor(entidad, idPropiedad, idaBuscar)
    if not entidad or not idPropiedad then
        return
    end
    local declaracion = elementoTabla(entidad, 'claims', idPropiedad)
    local idBuscado
    if not declaracion then
        return false
    end
    for k,v in pairs(declaracion) do
        idBuscado = elementoTabla(v,'mainsnak','datavalue','value','id')
        if idBuscado == idaBuscar then
            return true
        end
    end
    return false
end

function capitalizar(cad)
    return string.upper(string.sub(cad,1,1)) .. string.sub(cad,2)
end

return p