Módulo:Obra

De Wikisource, la biblioteca libre.
Documentación del módulo
Los editores pueden experimentar en la zona de pruebas de este módulo.
Por favor, añade las categorías e interwikis a la subpágina de documentación. Subpáginas de este módulo.
-- Modulo para obras

local p = {}
local Wikidata = require('Módulo:Wikidata')
local Enlaces = require('Módulo:Enlaces')
local Entidad  = mw.wikibase.getEntityObject() or ''  -- Para obtener los datos de Wikidata

-- Función que devuelve la lista de los valores de una propiedad en Wikidata formateados
function propiedad(idPropiedad,opciones)
	
    if Entidad and Entidad.claims   then --and Entidad.claims[idPropiedad] then
    	if not opciones then
    		opciones = {}
    	end
    	opciones['propiedad'] = idPropiedad

        valorPropiedad = Wikidata.getPropiedad(opciones,Entidad.claims[idPropiedad])
        if not valorPropiedad or valorPropiedad == '' then
        	return ''
        end
        return valorPropiedad
    else return ''
    end
end

function p.obra( frame )
	frame = frame
	argus = {}
	for k,v in pairs(frame.args) do
		argus[k] = v 
	end
	for k,v in pairs(frame:getParent().args) do -- crea una tabla con los parámetros incluídos en la plantilla, y elimina parámetros vacíos
		argus[k] = v 
	end
	
	local nombre = frame:preprocess("{{PAGENAME}}")
	local html = mw.html.create() -- cuerpo principal de la plantilla
	local div=html:tag('table'):addClass('encabezado')


	local fila1=div:tag('tr')
	local bloque1=fila1:tag('td'):addClass('bloque1')
	local bloque2=fila1:tag('td'):addClass('bloque2')
	local bloque3=fila1:tag('td'):addClass('bloque3')

	bloque2:wikitext('Ediciones '.. (argus['preposición'] or 'de')..
		'<br>'.."'''''"..(argus['titulo'] or nombre).."'''''")
	
	local divautor=bloque2:tag('div'):addClass('autor')
	autor = argus['autor'] or propiedad('P50')
	mw.log(autor)
	if autor and autor ~= '' then
		divautor:wikitext('por ')
		divautor:wikitext(autor)
	end
	if argus['más info'] and argus['más info']~= ''then
		local info=bloque2:tag('div')
		info:wikitext(argus['más info'])
	end
	local imagender=bloque3:tag('div'):addClass('imagen')
	if argus['imagen2'] and argus['imagen2'] ~= ''  then
		imagender:wikitext("[[File:"..argus['imagen2'].."|frameless|99999x100px|center]]")
	elseif propiedad('p18') ~= '' then
		imagender:wikitext("[[File:"..propiedad('p18',{['uno']='sí'}).."|frameless|99999x100px|"..propiedad('p18',{['calificador']='P2096',['idioma']='es'}).."|center]]")
	end
	local imagenizq=bloque1:tag('div')
	if argus['imagen1'] and argus['imagen1'] ~= ''  then
		imagenizq:wikitext("[[File:"..argus['imagen1'].."|frameless|99999x100px|center]]")
	end
	---- Enlaces ---
	local fila2=div:tag('tr')
	local enlaces=fila2:tag('td'):attr('colspan', 3):addClass('enlaces')
	listaenlaces = Enlaces.all(frame)
	-- orden = {'eswiki', 'eswikiquote', 'eswikinews', 'commonswiki', 'specieswiki', 'wikidata'}
	textoenlaces = Enlaces.formattedlinks(listaenlaces)
	enlaces:wikitext(textoenlaces)
	
	return tostring(html)
end

return p