Moduuli:Kappalelista
[ muokkaa ]
|
-- This module implements [[Malline:Kappalelista]]
-- Tuotu es-wikistä
-- -------------------------------------------------------------------------- --
-- Lista de canciones
--
-- Plantilla: {{Lista de canciones}}
-- Versión: 1.0.3
-- Autor: Jose Buelvas (Usuario:Iho jose)
-- -------------------------------------------------------------------------- --
-- Variables
local p = {}
local args
local isCollapsed = 0
local hasColLyricsComposer = 0
local hasColLyrics = 0
local hasColComposer = 0
local hasColExtra = 0
-- Union
function union(t1, t2)
local vals = {}
for k, v in pairs(t1) do
vals[v] = true
end
for k, v in pairs(t2) do
vals[v] = true
end
local ret = {}
for k, v in pairs(vals) do
table.insert(ret, k)
end
return ret
end
-- Depuración de etiquetas vacías
local function depuracion(contenido)
if contenido and contenido ~= '' then
return contenido
end
end
-- Obtener números en parámetros {{{1}}}
local function obtenerNumero(prefijo)
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefijo .. '([1-9]%d*)$')
if num then
table.insert(nums, tonumber(num))
end
end
table.sort(nums)
return nums
end
-- helper for checking with mixed languages
local function isEnabled(feature)
if args[feature] and
(args[feature] == 'yes' or args[feature] == 'kyllä') then
return true
end
return false
end
-- Información previa
function informacion(parent)
local infodisco = parent:wikitext()
if args['kaikki_säv&san'] then -- {{{todas_escritas}}}
infodisco:wikitext('Kaikki kappaleet säv. ja san. ' .. args['kaikki_säv&san'] .. '. ')
else
if args['kaikki_sanat'] then -- {{{todas_letras}}}
infodisco:wikitext('Kaikki sanat ' .. args['kaikki_sanat'])
if not args['all_music'] or not args['kaikki_sävellykset'] then
infodisco:wikitext('.')
end
end
local compositor = ''
if args['all_music'] then
compositor = args['all_music']
elseif args['kaikki_sävellykset'] then
compositor = args['kaikki_sävellykset']
end
if args['all_music'] or args['kaikki_sävellykset'] then -- {{{all_music| {{{toda_la_música}}}
if args['kaikki_sanat'] then -- Unión de las dos frases con coma (,)
infodisco:wikitext(', kaikki sävellykset ' .. compositor .. '. ')
else
infodisco:wikitext('Kaikki sävellykset ' .. compositor .. '. ')
end
end
end
end
-- Agregar filas a la tabla de contenido global
local function agregarPista(parent, filaArgs)
-- Variables globales internas
local pista = parent:tag('tr')
pista
:tag('td')
:cssText('padding-right: 10px; text-align: right; cursor: default; background-color: ' .. filaArgs.bgcolor)
:wikitext(filaArgs.numero .. '.') -- Número de la pista ( 1.)
-- Título de la pista y notas
local titulopista, notaspista
if filaArgs.titulo and filaArgs.titulo ~= '' then
titulopista = filaArgs.titulo
else
titulopista = "''Kappaleen nimi''"
end
if filaArgs.notas and filaArgs.notas ~= '' then
notaspista = ' <span style="font-size: smaller; color: #555">(' .. filaArgs.notas .. ')</span> '
else
notaspista = ''
end
local nombrepista = pista:tag('td')
nombrepista
:cssText('text-align: left; background-color: ' .. filaArgs.bgcolor)
:wikitext('' .. titulopista .. '' .. notaspista)
-- Créditos letras
if hasColLyrics == true then
local letraspista = pista:tag('td')
letraspista
:cssText('background-color: ' .. filaArgs.bgcolor)
:wikitext(filaArgs.letraspor)
end
-- Créditos música
if hasColComposer == true then
local musicapista = pista:tag('td')
musicapista
:cssText('background-color: ' .. filaArgs.bgcolor)
:wikitext(filaArgs.musicapor)
end
-- Créditos escritores
if hasColLyricsComposer == true then
local escritopista = pista:tag('td')
escritopista
:cssText('background-color: ' .. filaArgs.bgcolor)
:wikitext(filaArgs.escritopor)
end
-- Columna extra
if hasColExtra == true then
local columnapista = pista:tag('td')
columnapista
:cssText('background-color: ' .. filaArgs.bgcolor)
:wikitext(filaArgs.extrapor)
end
-- Duración de la pista
local duracionpista = pista:tag('td')
duracionpista
:cssText('padding-right: 10px; text-align: right; background-color: ' .. filaArgs.bgcolor)
:wikitext(filaArgs.duracionpor)
end
-- Hacer títulos de la tabla
local function titulosContenido(parent)
local listHeading = ''
if isCollapsed == true then
listHeading = args['headline'] or args['otsake'] or 'Kappalelista'
else
listHeading = args['headline'] or args['otsake'] or ''
end
local encabezado = parent:tag('tr')
encabezado
:tag('th')
:addClass('tlheader')
:attr('colspan', 10)
:cssText('text-align: left; background-color: #fff; width: 100%;')
:wikitext(listHeading)
local estilopista, num, num2, num3, num4, totalnum, estilomore
num = 0
num2 = 0
num3 = 0
num4 = 0
if
hasColLyrics == true or
hasColComposer == true or
hasColLyricsComposer == true or
hasColExtra == true
then
if hasColLyrics == true then
num = 1
end
if hasColComposer == true then
num2 = 1
end
if hasColLyricsComposer == true then
num3 = 1
end
if hasColExtra == true then
num4 = 1
end
-- Estilizado
totalnum = num+num2+num3+num4
if totalnum == 1 then
estilopista = 'width: 60%'
estilomore = 'width: 40%'
elseif totalnum == 2 then
estilopista = 'width: 40%'
estilomore = 'width: 30%'
elseif totalnum == 3 then
estilopista = 'width: 30%'
estilomore = 'width: 20%'
elseif totalnum == 4 then
estilopista = 'width: 20%'
estilomore = 'width: 20%'
end
else
estilopista = 'width: 100%'
estilomore = ''
end
local titulares = parent:tag('tr')
titulares
:tag('th')
:cssText('width: 20px; padding-left: 10px; padding-right: 10px; text-align: center; background-color: #eee; height: 20px')
:wikitext('Nro') -- Número de la pista
local nombrepista = titulares:tag('th')
nombrepista
:cssText('text-align: left; background-color: #eee; ' .. estilopista)
:wikitext('Nimi')
if hasColLyrics == true then
local letrista = titulares:tag('th')
letrista
:cssText('text-align: left; background-color: #eee; ' .. estilomore)
:wikitext('Sanat')
end
if hasColComposer == true then
local musicapista = titulares:tag('th')
musicapista
:cssText('text-align: left; background-color: #eee; ' .. estilomore)
:wikitext('Sävel')
end
if hasColLyricsComposer == true then
local escritorespista = titulares:tag('th')
escritorespista
:cssText('text-align: left; background-color: #eee; ' .. estilomore)
:wikitext('Säv&san')
end
if hasColExtra == true then
local columnaextra = titulares:tag('th')
columnaextra
:cssText('text-align: left; background-color: #eee; ' .. estilomore)
:wikitext(args['extra_column'] or args['ylim_sarake'])
end
local duraciones = titulares:tag('th')
duraciones
:cssText('padding-right: 5px; width: 60px; text-align: center; background-color: #eee')
:wikitext('Kesto')
local cel5 = titulares:tag('td')
cel5:addClass('mbox-empty-cell')
end
-- Hacer las filas consecutivamente según sean escritas
local function hacerLista(parent)
-- Detectar idioma del parámetro (inglés/español)
local numeroPista = union(obtenerNumero('nimi'), obtenerNumero('title'))
table.sort(numeroPista)
for k, num in ipairs(numeroPista) do
-- Color de fondo de la fila (Pista)
local colorfondo
if (num % 2) == 0 then
colorfondo = '#f7f7f7'
else
colorfondo = '#fff'
end
-- Agrega los datos según el parámetro (en inglés o español)
agregarPista(parent, {
bgcolor = colorfondo,
numero = num,
titulo = depuracion(args['nimi' .. num] or args['title' .. num]),
notas = depuracion(args['huom' .. num] or args['note' .. num]),
letraspor = depuracion(args['sanat' .. num] or args['lyrics' .. num]),
musicapor = depuracion(args['sävellys' .. num] or args['music' .. num]),
escritopor = depuracion(args['säv&san' .. num] or args['writer' .. num]),
extrapor = depuracion(args['ylim' .. num] or args['extra' .. num]),
duracionpor = depuracion(args['pituus' .. num] or args['length' .. num])
})
end
end
-- Duración total
local function duracionTotal(parent)
local duraciontotal = parent:tag('tr')
if args['total_length'] or args['kokonaiskesto'] then
duraciontotal
:tag('td')
:attr('colspan', 10)
:cssText('padding-right: 10px; text-align: right; background-color: #fff; border-width: 0; font-weight: bold')
:wikitext(args['total_length'] or args['kokonaiskesto'])
local cel8 = duraciontotal:tag('td')
cel8:addClass('mbox-empty-cell')
end
end
-- Vericando que el parámetro tenga datos
function existenciaDatos(pista)
-- TRUE si tiene datos FALSE por defecto
if depuracion(pista[1]) or depuracion(pista['otsake']) then
return true
end
return false
end
-- Hacer lista de pistas en la tabla
function hacerListaTabla(parent, tabla)
for k, pista in ipairs(tabla) do
if existenciaDatos(pista) then
agregarPista(parent, {
titulo = depuracion(pista['nimi'] or pista['title']),
notas = depuracion(args['huom'] or args['note']),
letraspor = depuracion(args['sanat'] or args['lyrics']),
musicapor = depuracion(args['sävellys'] or args['music']),
escritopor = depuracion(args['säv&san'] or args['writer']),
extrapor = depuracion(args['ylim'] or args['extra']),
duracionpor = depuracion(args['pituus'] or args['length'])
})
end
end
end
-- Plantilla de lista de canciones
function _canciones()
--Variables
local listclass
local estilos
-- Condicionales en _canciones
if isEnabled('collapsed') or isEnabled('piilotettu') then
listclass = 'collapsible collapsed'
estilos = 'border: #aaa 1px solid; padding: 3px;'
isCollapsed = true
else
listclass = ''
estilos = 'padding: 4px'
end
if isEnabled('lyrics_credits') or isEnabled('sarake_sanat') then
hasColLyrics = true
end
if isEnabled('music_credits') or isEnabled('sarake_sävellys') then
hasColComposer = true
end
if isEnabled('writing_credits') or isEnabled('sarake_säv&san') then
hasColLyricsComposer = true
end
if args['extra_column'] or args['ylim_sarake'] then
hasColExtra = true
end
-- Constructor global HtmlBuilder
local rootnode = mw.html.create()
-- Información
informacion(rootnode)
local divParent = rootnode:tag('div')
divParent
:addClass('tracklist')
:css('max-width', args['leveys'] or '50em')
:cssText(estilos)
-- Tabla contenedora
local listataulu = divParent:tag('table')
listataulu
:addClass('tracklist ')
:addClass(listclass)
:attr('cellpadding', 0)
:cssText('width: 100%; border-width: 0px; border-collapse: collapse;')
-- Indexar secciones
titulosContenido(listataulu)
if not args[1] then
hacerLista(listataulu)
else
hacerListaTabla(listataulu, args)
end
duracionTotal(listataulu)
-- Indexar todo en variable global
return tostring(rootnode)
end
-- Index
function p.lista(frame)
local origArgs
-- Llamado en #invoke par uso de etiquetas de plantilla
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
-- For pairs
args = {}
for k, v in pairs(origArgs) do
if v ~= '' then
args[k] = v
end
end
-- Indexar plantilla de lista de canciones
return _canciones()
end
return p