Module:Songs: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 21: | Line 21: | ||
local text = '' | local text = '' | ||
for _, ev in ipairs(events) do | for _, ev in ipairs(events) do | ||
text = text .. frame:expandTemplate{ | text = text .. frame:expandTemplate { | ||
title='Song Albums/Entry', | title = 'Song Albums/Entry', | ||
args=ev | args = ev | ||
} .. '\n' | } .. '\n' | ||
end | end | ||
Line 38: | Line 38: | ||
orderBy = "event_order ASC, leg_order ASC, day ASC", | orderBy = "event_order ASC, leg_order ASC, day ASC", | ||
} | } | ||
local fields = {'event_page', 'leg_name', 'day', 'cast'} | local fields = { 'event_page', 'leg_name', 'day', 'cast' } | ||
local events = cargo.query('Setlist_Event, Setlist_Songs', | local events = cargo.query('Setlist_Event, Setlist_Songs', | ||
table.concat(fields, ','), query) | table.concat(fields, ','), query) | ||
Line 44: | Line 44: | ||
local text = '' | local text = '' | ||
for _, ev in ipairs(events) do | for _, ev in ipairs(events) do | ||
text = text .. frame:expandTemplate{ | text = text .. frame:expandTemplate { | ||
title='Song Events/Entry', | title = 'Song Events/Entry', | ||
args=ev | args = ev | ||
} .. '\n' | } .. '\n' | ||
end | end | ||
Line 52: | Line 52: | ||
end | end | ||
function p.characterSongs(frame) | |||
function p. | |||
local horseName = mw.text.decode(frame.args[1]) | local horseName = mw.text.decode(frame.args[1]) | ||
if not horseName then return end | if not horseName then return end | ||
Line 71: | Line 61: | ||
orderBy = "Album_Songs.song_title ASC" | orderBy = "Album_Songs.song_title ASC" | ||
} | } | ||
local fields = {'song_title', 'album', 'type', 'singers'} | local fields = { 'song_title', 'album', 'type', 'singers' } | ||
local results = cargo.query('Album_Songs', table.concat(fields, ','), query) | local results = cargo.query('Album_Songs', table.concat(fields, ','), query) | ||
local rows = {} | |||
local rowspans = {} | |||
local | |||
local | |||
for _, row in ipairs(results) do | for _, row in ipairs(results) do | ||
local singers = mw.text.split(row.singers, ", ") | local singers = mw.text.split(row.singers, ",") | ||
local type | |||
if row.type == "solover" then | |||
type = "'''" .. horseName .. " ver.'''" | |||
elseif #singers == 1 then | |||
type = "'''Solo'''" | |||
elseif not row.type then | |||
type = "Group" | |||
end | |||
if type then | |||
table.insert(rows, { song = row.song_title, album = row.album, type = row.type }) | |||
rowspans[row.song_title] = (rowspans[row.song_title] or 0) + 1 | |||
end | |||
end | end | ||
local text = '{| class="wikitable sortable mw-collapsible"\n! Song !! Album !! Type\n' | |||
for row in rows do | |||
text = text .. | |||
string.format('|-\n| rowspan=%d|[[%s]] || [[%s]] || %s\n', rowspans[row.song], row.song, row.album, row.type) | |||
end | |||
text = text .. '|}' | |||
return text | |||
end | end | ||
return p | return p |
Revision as of 00:56, 3 October 2024
Documentation for this module may be created at Module:Songs/doc
local p = {}
local cargo = mw.ext.cargo
function p.albums(frame)
local songName = mw.text.decode(frame.args[1])
if not songName then return end
local escaped = string.gsub(songName, "'", "\\'")
local query = {
join = "Album_Songs.album=Albums.title",
where = "Album_Songs.song_page='" .. escaped .. "'",
groupBy = "Albums.title",
orderBy = "Albums.release_date ASC"
}
local fields = {
'Albums._pageTitle=album_page',
'Album_Songs.singers=singers'
}
local events = cargo.query('Albums, Album_Songs',
table.concat(fields, ','), query)
local text = ''
for _, ev in ipairs(events) do
text = text .. frame:expandTemplate {
title = 'Song Albums/Entry',
args = ev
} .. '\n'
end
return text
end
function p.events(frame)
local songName = mw.text.decode(frame.args[1])
if not songName then return end
local escaped = string.gsub(songName, "'", "\\'")
local query = {
join = "Setlist_Event._pageID=Setlist_Songs._pageID",
where = "song_page='" .. escaped .. "'",
orderBy = "event_order ASC, leg_order ASC, day ASC",
}
local fields = { 'event_page', 'leg_name', 'day', 'cast' }
local events = cargo.query('Setlist_Event, Setlist_Songs',
table.concat(fields, ','), query)
local text = ''
for _, ev in ipairs(events) do
text = text .. frame:expandTemplate {
title = 'Song Events/Entry',
args = ev
} .. '\n'
end
return text
end
function p.characterSongs(frame)
local horseName = mw.text.decode(frame.args[1])
if not horseName then return end
local escaped = string.gsub(horseName, "'", "\\'")
local query = {
limit = '1000',
where = 'Album_Songs.singers HOLDS "' .. escaped .. '"',
orderBy = "Album_Songs.song_title ASC"
}
local fields = { 'song_title', 'album', 'type', 'singers' }
local results = cargo.query('Album_Songs', table.concat(fields, ','), query)
local rows = {}
local rowspans = {}
for _, row in ipairs(results) do
local singers = mw.text.split(row.singers, ",")
local type
if row.type == "solover" then
type = "'''" .. horseName .. " ver.'''"
elseif #singers == 1 then
type = "'''Solo'''"
elseif not row.type then
type = "Group"
end
if type then
table.insert(rows, { song = row.song_title, album = row.album, type = row.type })
rowspans[row.song_title] = (rowspans[row.song_title] or 0) + 1
end
end
local text = '{| class="wikitable sortable mw-collapsible"\n! Song !! Album !! Type\n'
for row in rows do
text = text ..
string.format('|-\n| rowspan=%d|[[%s]] || [[%s]] || %s\n', rowspans[row.song], row.song, row.album, row.type)
end
text = text .. '|}'
return text
end
return p