Module:Infobox song: Difference between revisions

From SPCodex, The Smashing Pumpkins wiki
m (Protected "Module:Infobox song": High traffic page ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite)))
(until Cargo is fixed)
Line 59: Line 59:


function p._studio_sessions(song)
function p._studio_sessions(song)
local cargo = mw.ext.cargo
return ''
local results = cargo.query(
-- local cargo = mw.ext.cargo
'studio_sessions, recordings, songs',
-- local results = cargo.query(
'studio_sessions._pageName=page',
-- 'studio_sessions, recordings, songs',
{
-- 'studio_sessions._pageName=page',
where = 'songs._pageName = "' .. song .. '"',
-- {
join = 'recordings.song=songs.name,studio_sessions._pageName=recordings._pageName',
-- where = 'songs._pageName = "' .. song .. '"',
groupBy = 'studio_sessions._pageName',
-- join = 'recordings.song=songs.name,studio_sessions._pageName=recordings._pageName',
orderBy = 'studio_sessions.date_from ASC'
-- groupBy = 'studio_sessions._pageName',
}
-- orderBy = 'studio_sessions.date_from ASC'
)
-- }
-- )


if 0 == #results then
-- if 0 == #results then
return ''
-- return ''
elseif 1 == #results then
-- elseif 1 == #results then
return '[[' .. results[1]['page'] .. ']]'
-- return '[[' .. results[1]['page'] .. ']]'
end
-- end


local root = mw.html.create()
-- local root = mw.html.create()
local ulRoot = root:tag('ul')
-- local ulRoot = root:tag('ul')
:addClass('studio-sessions')
-- :addClass('studio-sessions')


local sessions = {}
-- local sessions = {}
for r = 1, #results do
-- for r = 1, #results do
local page = results[r]['page']
-- local page = results[r]['page']


if page ~= nil and page ~= '' then
-- if page ~= nil and page ~= '' then
ulRoot:tag('li')
-- ulRoot:tag('li')
:wikitext('[[' .. page .. ']]')
-- :wikitext('[[' .. page .. ']]')
end
-- end
end
-- end


return tostring(root)
-- return tostring(root)
-- return table.concat(sessions, ' • ')
-- return table.concat(sessions, ' • ')
end
end

Revision as of 18:24, 5 April 2023

Documentation for this module may be created at Module:Infobox song/doc

local p = {}

function p._track_listing(song, album)
	local cargo = mw.ext.cargo
	local results = cargo.query(
		'track_listings',
		'track, song, song_page_title',
		{
			where = 'work = "' .. album .. '" AND main_listing = 1',
			orderBy = 'track_listings._ID ASC'
		}
	)

	local root = mw.html.create()
	local olRoot = root:tag('ol')
	local has_match = false

	for r = 1, #results do
		local result = results[r]
		local page = mw.title.new(result['song_page_title'])

		wikitext = result['song']
		if page.exists then
			wikitext = '[[' .. result['song_page_title'] .. '|' .. result['song'] .. ']]'
		end

		olRoot:tag('li')
			:attr('value', result['track'])
			:wikitext(wikitext)

		if result['song'] == song then
			has_match = true
		end
	end
	
	if has_match then
		return tostring(root)
	end
	
	return ''

	-- local tableRoot = root:tag('table')

	-- for r = 1, #results do
	-- 	local row = tableRoot:tag('tr')
	-- 	local result = results[r]
	-- 	row:tag('td')
	-- 		:css('padding-right', '5px')
	-- 		:wikitext(result['track'] .. '.')
	-- 	row:tag('td'):wikitext('[[' .. result['song_page_title'] .. '|' .. result['song'] .. ']]')
	-- end
end

function p.track_listing(frame)
	local song = frame.args[1]
	local album = frame.args[2]
	return p._track_listing(song, album)
end

function p._studio_sessions(song)
	return ''
	-- local cargo = mw.ext.cargo
	-- local results = cargo.query(
	-- 	'studio_sessions, recordings, songs',
	-- 	'studio_sessions._pageName=page',
	-- 	{
	-- 		where = 'songs._pageName = "' .. song .. '"',
	-- 		join = 'recordings.song=songs.name,studio_sessions._pageName=recordings._pageName',
	-- 		groupBy = 'studio_sessions._pageName',
	-- 		orderBy = 'studio_sessions.date_from ASC'
	-- 	}
	-- )

	-- if 0 == #results then
	-- 	return ''
	-- elseif 1 == #results then
	-- 	return '[[' .. results[1]['page'] .. ']]'
	-- end

	-- local root = mw.html.create()
	-- local ulRoot = root:tag('ul')
	-- 	:addClass('studio-sessions')

	-- local sessions = {}
	-- for r = 1, #results do
	-- 	local page = results[r]['page']

	-- 	if page ~= nil and page ~= '' then
	-- 		ulRoot:tag('li')
	-- 			:wikitext('[[' .. page .. ']]')
	-- 	end
	-- end

	-- return tostring(root)
	-- return table.concat(sessions, ' • ')
end

function p.studio_sessions(frame)
	local album = frame.args[1]
	return p._studio_sessions(album)
end

return p