Module:Songs: Difference between revisions

From Umamusume Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
(One intermediate revision by the same user not shown)
Line 3: Line 3:


function p.albums(frame)
function p.albums(frame)
local songName = frame.args[1]
local songName = mw.text.decode(frame.args[1])
if not songName then return end
if not songName then return end
local escaped = string.gsub(songName, "'", "\\\\'")
local escaped = string.gsub(songName, "'", "\\'")
local query = {
local query = {
join = "Album_Songs.album=Albums.title",
join = "Album_Songs.album=Albums.title",
Line 26: Line 26:


function p.events(frame)
function p.events(frame)
local songName = frame.args[1]
local songName = mw.text.decode(frame.args[1])
if not songName then return end
if not songName then return end
local escaped = string.gsub(songName, "'", "\\\\'")
local escaped = string.gsub(songName, "'", "\\'")
local query = {
local query = {
where = "song_page='" .. escaped .. "'",
where = "song_page='" .. escaped .. "'",

Revision as of 22:29, 11 June 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"
	}
	local fields = {'Albums._pageTitle=album_page'}
	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 = {
		where = "song_page='" .. escaped .. "'",
	}
	local fields = {'event_page', 'leg_name', 'day', 'cast'}
	local events = cargo.query('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

return p