--------------------------
-- Module for [[Template:Infobox Virtual Live]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local utils = require('Module:Utilities')
local icons = require('Module:Icons')._main
local cargo = mw.ext.cargo
local p = {}
local categories = ""
local function formatImage(image_name)
return string.format("[[File:%s|250px]]", image_name)
end
local function formatRewardImage(image_name)
return string.format("[[File:%s|150px]]", image_name)
end
local function formatCharacters(characters)
local characterArr = utils.split(characters, ',')
local resArr = {}
for i,v in ipairs(characterArr) do
table.insert(resArr, icons({ v, size = '30px' }))
end
return table.concat(resArr, " ")
end
local function formatSongs(song_ids)
local idsArr = utils.split(song_ids, ',')
local queryArr = {}
for i,v in ipairs(idsArr) do
table.insert(queryArr, 'song_id = ' .. v)
end
local tables = 'Songs'
local fields = 'song_name, _pageName'
local args = {
where = table.concat(queryArr, " OR ")
}
local results = cargo.query( tables, fields, args )
if #results > 0 then
local resArr = {}
for i,v in ipairs(results) do
table.insert(
resArr,
string.format(
'[[%s|%s]]',
v._pageName,
v.song_name
)
)
end
return table.concat(resArr, "<br>")
end
return nil
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new()
infobox:setName('Infobox Virtual Live')
:setWidth("330px")
:setParams{
{ name = 'vlive id' },
{ name = 'vlive name', default = mw.title.getCurrentTitle().text },
{ name = 'image', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'from' },
{ name = 'until' },
{ name = 'characters', func = formatCharacters },
{ name = 'song ids', func = formatSongs },
{ name = 'stamp', func = formatRewardImage },
{ name = 'title', func = formatRewardImage },
}
:setArgs(args)
infobox
:addHeader({ tag = 'argth', content = 'vlive name' })
:addImage({
{ tag = 'argtd', content = 'image' },
})
:addRow(
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
)
:addHeader({ tag = 'th', content = 'Availability Period' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'From', colspan = 12 },
{ tag = 'argtd', content = 'from', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'Until', colspan = 12 },
{ tag = 'argtd', content = 'until', colspan = 18 }
}
)
:addHeader({ tag = 'th', content = 'Virtual Live Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Featured Characters ', colspan = 12 },
{ tag = 'argtd', content = 'characters', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'Featured Songs', colspan = 12 },
{ tag = 'argtd', content = 'song ids', colspan = 18 }
}
)
:addHeader(
{ tag = 'th', content = 'Reward Stamp' },
{ hideIfEmpty = { 'stamp' }, subheader = true }
)
:addImage(
{
{ tag = 'argtd', content = 'stamp' },
},
{ hideIfEmpty = { 'stamp' } }
)
:addHeader(
{ tag = 'th', content = 'Reward Title' },
{ hideIfEmpty = { 'title' }, subheader = true }
)
:addImage(
{
{ tag = 'argtd', content = 'title' },
},
{ hideIfEmpty = { 'title' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Virtual lives]]" .. categories
local procArgs = infobox:getArgs('processed')
local rawArgs = infobox:getArgs('raw')
end
return infobox:tostring() .. categories
end
return p