Diferencia entre revisiones de «Módulo:Enlace externo»

De Wikipedia, la enciclopedia libre
Contenido eliminado Contenido añadido
Tinker Bell (discusión · contribs.)
Revirtiendo mis cambios
Sin resumen de edición
Línea 51: Línea 51:
local Subst = Id or propiedad(Propiedad, {['linkback']='no', ['uno']='sí'}) or ''
local Subst = Id or propiedad(Propiedad, {['linkback']='no', ['uno']='sí'}) or ''
URL = PatronWikidata
URL = PatronWikidata
URL = mw.text.decode(URL)
URL = mw.ustring.gsub(URL, '%$1', Subst)
URL = mw.ustring.gsub(URL, '%$1', Subst)
else
else

Revisión del 04:43 5 sep 2017

Este módulo no tiene página de documentación[crear]
local p = {}
local ModuloArgumentos = require('Módulo:Argumentos')
local ModuloWikidata = require('Module:Wikidata')
local ModuloPaginas = require('Módulo:Páginas')
local argumentos
local Entidad

function p.Plantilla(frame)
    argumentos = ModuloArgumentos.obtenerArgumentosConValor(frame)
    Entidad = mw.wikibase.getEntityObject(argumentos.id) or {}
    local Titulo = argumentos['título'] or obtenerEtiquetaWikidata() or ModuloPaginas.nombrePagina({desambiguar='sí'})
    local Imagen
    if argumentos['imagen'] == 'no' then
        Imagen = ''
    elseif argumentos['imagen'] then
        Imagen = '[[File:' .. argumentos['imagen'] .. '|16px|link=|alt=Icono]] '
    else
        Imagen = '[[File:Internet-web-browser.svg|16px|link=|alt=Icono]] '
    end
    local Nombre
    if argumentos['nombre'] and argumentos['enlacenombre'] then
        Nombre = ' en [[' .. frame:preprocess('{{desenlazar|' .. argumentos['enlacenombre'] .. '}}') .. '|' .. frame:preprocess('{{desenlazar|' .. argumentos['nombre'] .. '}}') ..']]'
    elseif argumentos['nombre'] then
        Nombre = ' en ' .. argumentos['nombre']
    else
        Nombre = ''
    end
    -- Definición de URL
    local URL
    local Patron = argumentos['patrón']
    local Propiedad = argumentos['propiedad']
    local Id = argumentos['identificador']
    local Nota = argumentos['nota']
    if Nota then
        Nota = ' (' .. Nota .. ')'
    else
        Nota = ''
    end
    if Patron then
		if Id or Propiedad then
			local Subst = Id or propiedad(Propiedad, {['linkback']='no', ['uno']='sí'}) or ''
			URL = Patron
			URL = mw.ustring.gsub(URL, '%$1', Subst)
		else
			return '<span class="error">Error: Debe pasar al menos un identificador o una propiedad como parámetro junto al patrón.</span>'
		end
    else
        if Propiedad then
            EntidadPropiedad = mw.wikibase.getEntityObject(Propiedad) or {}
            PatronWikidata = EntidadPropiedad:formatPropertyValues('P1630').value
            local Subst = Id or propiedad(Propiedad, {['linkback']='no', ['uno']='sí'}) or ''
            URL = PatronWikidata
            URL = mw.text.decode(URL)
            URL = mw.ustring.gsub(URL, '%$1', Subst)
        else
            return '<span class="error">Error: Debe pasar una propiedad o un patrón como parámetro.</span>'
        end
    end
    return Imagen .. '['.. URL .. ' ' .. Titulo .. ']' .. Nombre .. Nota .. '.'
end

function obtenerEtiquetaWikidata()
    if Entidad and Entidad.labels and Entidad.labels.es then
        return Entidad.labels.es.value
    end
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 = ModuloWikidata.getPropiedad(opciones,Entidad.claims[idPropiedad])
        return valorPropiedad
    end
end

return p