Diferencia entre revisiones de «Módulo:Enlace externo»
Apariencia
Contenido eliminado Contenido añadido
m Giovanni Alfredo Garciliano Diaz trasladó la página Módulo:Zona de pruebas/Giovanni Alfredo Garciliano Diaz/Metaplantilla de enlaces externos a Módulo:Metaplantilla de enlaces externos sin dejar una redirección: Ya está lista |
Pensándolo bien, el punto final contradice la idea de poder usarlo en otros formatos, por ejemplo listas separadas por guiones o comas |
||
Línea 56: | Línea 56: | ||
end |
end |
||
end |
end |
||
return Imagen .. '['.. URL .. ' ' .. Titulo .. ']' .. Nombre .. Nota |
return Imagen .. '['.. URL .. ' ' .. Titulo .. ']' .. Nombre .. Nota |
||
end |
end |
||
Revisión del 04:44 6 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.claims.P1630[1].mainsnak.datavalue.value
local Subst = Id or propiedad(Propiedad, {['linkback']='no', ['uno']='sí'}) or ''
URL = PatronWikidata
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