Ir al contenido

Módulo:Galería/pruebas

De Wikisource, la biblioteca libre.
Documentación del módulo
Por favor, añade las categorías a la subpágina de documentación.
(subpáginas - enlaces)
--[=[
Genera galerías a partir de una lista de Índices
]=]
require('strict')

local langs = {
	Titulo = 'title',
	Ano = 'pubYear',
	Autor = 'author',
	Traductor = 'translator',
	Ilustrador = 'illustrator',
	Prologuista = 'introducer',
}

local p = {} --p stands for package
local getArgs = require('Módulo:Arguments').getArgs

local loadWikidata = function(fields, work)
	for field in pairs(langs) do
		if not fields[field] or fields[field] == '' then
			local workfield = work[langs[field]]
			if type(workfield) == 'table' then
				workfield = tostring(require('Módulo:Enlace libro').renderAuthorLinks( workfield, 'wst-worklink-authors' ))
			end
			fields[field] = workfield	
		end
	end
	return fields
end

local delink = function(s)
	local m = mw.ustring.match(s, '%[%[(.+)%|.+%]%]')
	if m and m ~= '' then return m end
	
	m = mw.ustring.match(s, '%[%[(.+)%]%]')
	if m and m ~= '' then return m end
	
	return s
end

function p.galeria(frame)
	local args = getArgs(frame)
	local content = {}
	if args[1] == nil then return '' end
	for file in mw.text.gsplit(args[1], '\n') do
		if file =='' then 
			local pass = true
		else
			if mw.ustring.match(file, 'Índice:') then
				file = mw.ustring.sub(file, 8)
			end
			local index = mw.ext.proofreadPage.newIndex( file )
			if not index.title.exists then 
				local pass = true
			else
				local fields = index.fields
				local work = require('Módulo:Obra').newWork(file)
				fields = loadWikidata(fields, work)
				
				local archivo = 'Archivo:' .. file
				local page = fields.Imagen
				local titulo = fields.Titulo
				local anyo = fields.Ano
				local roles = ''
				local coma = false
				for i, role in ipairs{'Autor', 'Traductor', 'Ilustrador', 'Prologuista'} do
					local Role = fields[role]
					if Role and Role ~= '' then
						if coma then
							roles = roles..', <br>'
						end
						coma = true
						if role == 'Autor' then
							roles = roles..'por ' .. Role
						elseif role == 'Traductor' then
							roles = roles..'traducido por ' .. Role
						elseif role == 'Ilustrador' then
							roles = roles..'ilustrado por ' .. Role
						elseif role == 'Prologuista' then
							roles = roles..'prólogo por ' .. Role
						end
					end
				end
				local str = archivo .. '|page='..page..'|link=Índice:'..file..'|'
				str = str .. "'''" .. titulo .. "''' (".. anyo..")<br/> <span style=\"font-size: 83%;\">"
				
				if roles ~= '' then
					str = str..roles
				end
				str = str..'</span>'
				-- TODO: parámetro para no mostrar links de descarga
				titulo = delink(titulo)
				local dlink = frame:expandTemplate{ title = 'descarga2', args={titulo} }
				str= str..'<br/>'..dlink
				table.insert(content, str)	

			end
		end
	end
	local all = table.concat(content, '\n')
	local tag = frame:extensionTag( 'gallery', all, { heights = 200, widths = 200, mode="packed" } )
	return tag
end


return p