Documentation for this module may be created at Module:Character Discography/doc
local getArgs = require('Module:Arguments').getArgs
local navbar = require('Module:Navbar')._navbar
local utils = require('Module:Utilities')
local constants = require('Module:Constants')
local cargo = mw.ext.cargo
local p = {}
local function cargoQuery(character)
if character and character ~= '' then
local tables = 'Song_Vocal_Versions, Songs'
local fields = [[
Songs._pageName = page_name,
Songs.song_name = song_name,
Song_Vocal_Versions.version = version,
Song_Vocal_Versions.singers = singers
]]
local args = {
where = "Song_Vocal_Versions.singers HOLDS '" .. character .. "' AND Songs.song_id > 0",
join = 'Song_Vocal_Versions._pageID = Songs._pageID',
orderBy = 'Songs.song_id ASC',
limit = 200
}
return cargo.query( tables, fields, args )
end
return {}
end
local function formatSingers(arg)
if arg and arg ~= '' then
local splits = utils.split(arg, ",")
for i=1,#splits do
splits[i] = utils.trim(splits[i])
if constants.get_character(splits[i]) ~= nil then
splits[i] = '[[' .. splits[i] .. ']]'
end
end
return mw.text.listToText(splits)
end
return nil
end
function p.main(frame)
local args = getArgs(frame)
local results = cargoQuery(args[1])
local root = mw.html.create()
local root_table = root:tag('table')
:addClass('wikitable'):addClass('sortable')
:css({
['margin-bottom'] = '0'
})
:tag('tr')
:tag('th'):attr('width', '250px'):wikitext('Song'):done()
:tag('th'):attr('width', '150px'):wikitext('Version'):done()
:tag('th'):wikitext('Singers'):done()
:done()
if #results > 0 then
for k,v in ipairs(results) do
root_table:tag('tr')
:tag('td'):wikitext(string.format('[[%s|%s]]', v.page_name, v.song_name)):done()
:tag('td'):wikitext(v.version):done()
:tag('td'):wikitext(formatSingers(v.singers)):done()
:done()
end
else
root_table:tag('tr')
:tag('td'):attr('colspan', 3):wikitext(args[1] .. ' has no associated songs')
:done()
:done()
end
return tostring(root) .. tostring(navbar({ 'Character Discography', plain = 1, noedit = 1, brackets = 1 }))
end
return p