Módulo:Imprenta/pruebas

De Wikisource, la biblioteca libre.
Documentación del módulo
Por favor, añade las categorías e interwikis a la subpágina de documentación. Subpáginas de este módulo.
local p = {}
local Wikidata = require('Módulo:Wikidata')
local Str = require('Módulo:String')
local Entidad  = mw.wikibase.getEntityObject() or ''     -- Tabla con los datos en Wikidata
local Enlaces = require('Módulo:Enlaces')

local lang = mw.language.new('es')
--parámetros reconocidos. 1 = vigente, 0 = obsoleto
local categorias = ''
local params = {['nombre']=1,['dirección']=1,['más info']=1,
	['wikipedia'] =1 , ['commons'] =1 , ['commonscat'] =1 , ['wikiquote'] =1 , 
	['wikinoticias'] =1 , ['wikcionario'] =1 , ['wikilibros'] =1 , ['wikiversidad'] =1, 
	['wikispecies'] =1 , ['meta'] =1 , ['wikidata'] =1}

local altparams= {['direccion']='dirección', ['mas info']='más info'
	}

function errorMessage(text)
	-- Función que entrega un mensaje de error formateado como tal
	local html = mw.html.create('div')
	html:addClass('error')
		:wikitext(text)
	categorias=categorias..'[[Categoría:Wikisource:Páginas con errores en la plantilla Imprenta]]'
	return tostring(html)
end

local function enlaceMicroformato(param, valor)
	if valor~= nil and valor ~= '' then
		return mw.html.create('span')
        :addClass('ws-' .. param)
        :wikitext(delink(valor))	
	else 
		return ''
	end
end
function p.encabe( frame ) 
    local argus = {}
    local titulo = mw.title.getCurrentTitle()
	local essub = titulo.isSubpage
	
	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
		if v ~= '' and type(k) ~= 'number' then
			argus[mw.ustring.lower(k)] = v -- todos los parámetros en minúsculas por defecto: 
		end
	end
	-- HTML
    local html = mw.html.create()
    
	-- corregir parámetros con nombres alternativos

	for k,v in pairs(altparams) do
		if argus[k] and not argus[v] then
			argus[v] = argus[k]
		elseif argus[k] and argus[v] then
			html:wikitext(errorMessage('Error: los parámetros '..k..' y '..v..' son redundantes.'))
			categorias=categorias..'[[Categoría:Wikisource:Páginas que usan parámetros redundantes en la plantilla Imprenta]]'
		end
	end

    
    local divgrande = html:tag('div'):attr('id','headertemplate'):addClass('noprint ws-noexport'):cssText('text-align: center; padding: 1em; background-color:#F1F1DE; overflow:auto; border-radius:0.7em; box-shadow:0.2em 0.3em 0.2em #B7B7B7; display:table;width:95%')  -- div principal que contiene al resto
	local anterior = divgrande:tag('div'):attr('id','headerprevious'):cssText('padding:0;display:table-cell;vertical-align:middle;width:16%')
    --if argus['anterior'] and argus['anterior'] ~= '' then
    	local anteriorspan = anterior:tag('span'):cssText('float: left; display: block;font-size:smaller')
    	anteriorspan:tag('span'):cssText(';margin-right: 0.5em; position: relative; top: 1.5px'):wikitext('← ')
    	anteriorspan:wikitext(' '..'[[:Categoría:Imprentas y editoriales|Imprentas y editoriales]]')
    	--if argus['enlaces'] and mw.ustring.lower(argus['enlaces']) == 'no' then
    	--	anteriorspan:cssText('display:none')
    	--end
    --end
    
    local medio = divgrande:tag('div'):cssText('width:68%;display:table-cell;vertical-align:middle;')
    if argus['nombre'] then
    	medio:wikitext("'''''"..argus['nombre'].."'''''")
    end

	medio:tag('br')

    if argus['dirección'] then
    	medio:wikitext("''"..argus['dirección'].."''")
   		if argus['más info'] then
   			medio:tag('br')
   			medio:tag('span'):cssText('font-size: 83%;'):wikitext(argus['más info'])
   		end
    end

	local proximo = divgrande:tag('div'):attr('id','headernext'):cssText('padding:0;display:table-cell;vertical-align:middle;width:16%')
    local logotipo=''
    if  propiedad('p154') ~= '' then --categoría en commons
			logotipo =  '[[File:'..propiedad('p154',{['uno']='sí'})..'|100px]]'	
	
	local proximospan = proximo:tag('span'):cssText('float: right; display: block;font-size:smaller')
    		:wikitext(logotipo)
    		
    	--proximospan:tag('span'):cssText('margin-left: 0.5em; position: relative; top: 1.5px'):wikitext(' →')
    end
    if argus['próximo'] and argus['próximo']~= '' then
    	local proximospan = proximo:tag('span'):cssText('float: right; display: block;font-size:smaller')
    		:wikitext(' '..argus['próximo'])
    		
    	proximospan:tag('span'):cssText('margin-left: 0.5em; position: relative; top: 1.5px'):wikitext(' →')
    	if argus['enlaces'] and mw.ustring.lower(argus['enlaces']) == 'no' then
    		proximospan:cssText('display:none')
    	end
	end
	--enlaces pequeños en la parte inferior
	
    inferior = medio:tag('div'):addClass('noprint plainlinks'):cssText('clear: both; padding: 0.5em; text-align: center; margin:0 auto; font-size: 80%')
    
	--enlaces parte inferior
	listaenlaces = Enlaces.all(frame)
	textoenlaces = Enlaces.formattedlinks(listaenlaces)
	
	inferior:wikitext(textoenlaces)
	
	if argus['notas'] and argus['notas'] ~= '' then
		html:tag('div'):cssText('font-size:90%;width:95%;margin:auto'):wikitext("'''Nota:''' "..argus['notas']):tag('hr')
	end
	--categorías automáticas
	
	categorias = categorias..'[[Categoría:Imprentas y editoriales]]'


	
    for k,v in pairs(argus) do
		if params[k] or altparams[k] then
			if params[k] == 0 then
				categorias = categorias..'[[Categoría:Wikisource:Páginas que usan parámetros obsoletos en la plantilla Imprenta]]' --añade categoría de seguimiento a parámetros obsoletos (declarados arriba)
			end
		else
			html:wikitext(errorMessage('Error: parámetro '..k..' no reconocido'))
			categorias=categorias..'[[Categoría:Wikisource:Páginas que usan parámetros no reconocidos en la plantilla Imprenta]]'
		end
	end
	if titulo.namespace ~= 100 then --solo categorías en el espacio portal
		categorias = ''	
	end
	
	divgrande:wikitext(categorias)

	
    


    return tostring(html)

end

-- 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

return p