Module:Infobox song: Difference between revisions

From SPCodex, The Smashing Pumpkins wiki
No edit summary
No edit summary
Line 14: Line 14:
local root = mw.html.create()
local root = mw.html.create()
local olRoot = root:tag('ol')
local olRoot = root:tag('ol')
local has_match = false


for r = 1, #results do
for r = 1, #results do
Line 20: Line 21:
:attr('value', result['track'])
:attr('value', result['track'])
:wikitext('[[' .. result['song_page_title'] .. '|' .. result['song'] .. ']]')
:wikitext('[[' .. result['song_page_title'] .. '|' .. result['song'] .. ']]')
if result['song'] == song then
has_match = true
end
end
if has_match then
return tostring(root)
end
end
return ''
-- local tableRoot = root:tag('table')
-- local tableRoot = root:tag('table')


Line 31: Line 43:
-- row:tag('td'):wikitext('[[' .. result['song_page_title'] .. '|' .. result['song'] .. ']]')
-- row:tag('td'):wikitext('[[' .. result['song_page_title'] .. '|' .. result['song'] .. ']]')
-- end
-- end
return tostring(root)
end
end



Revision as of 22:26, 11 June 2020

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]
		olRoot:tag('li')
			:attr('value', result['track'])
			:wikitext('[[' .. result['song_page_title'] .. '|' .. result['song'] .. ']]')

		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

return p