Module:Episode list

This is an old revision of this page, as edited by The Mol Man (talk | contribs) at 17:51, 7 July 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local getArgs
local yesno = require('Module:Yesno')
local _mod = require('Module:Math').mod()

function p.sublist(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	local args = getArgs(frame, {wrappers = 'Template:Episode list/sublist'})
	local title = mw.title.getCurrentTitle()
	local page_title = mw.title.getCurrentTitle():fullText()
	local mainlist = args.MainList or args['1'] or page_title
	
	local on_same_page = mw.uri.anchorEncode(page_title) == mw.uri.anchorEncode(mainlist)
	
	local EpisodeNumber,EpisodeNumber2,Title,Aux1,DirectedBy,WrittenBy,DirectedBy,Aux2,Aux3,OriginalAirDate,AltDate,ProdCode,Viewers,Aux4,return_table
	
	local line_color = args.LineColor or 'CCCCFF'
	local cell_names = {
		'EpisodeNumber2',
		'Title',
		'Aux1',
		'DirectedBy',
		'WrittenBy',
		'Aux2',
		'Aux3',
		'OriginalAirDate',
		'AltDate',
		'ProdCode',
		'Viewers',
		'Aux4'
	}
	
	local td_tags = {
		['EpisodeNumber2'] = EpisodeNumber2,
		['Title'] = Title,
		['Aux1'] = Aux1,
		['DirectedBy'] = DirectedBy,
		['WrittenBy'] = WrittenBy,
		['DirectedBy'] = DirectedBy,
		['Aux2'] = Aux2,
		['Aux3'] = Aux3,
		['OriginalAirDate'] = OriginalAirDate,
		['AltDate'] = AltDate,
		['ProdCode'] = ProdCode,
		['Viewers'] = Viewers,
		['Aux4'] = Aux4,
	}
	
	local nonnil_params = 1
	
	local table_row = mw.html.create('tr')
				:addClass('vevent')
				:css('text-align','center')
	
	local row_color = yesno(args.RowColor, false)
	local top_color
	local epn = args.EpisodeNumber or 1
	if args.TopColor then
		top_color = '#'..args.TopColor
	elseif row_color and on_same_page and _mod(epn) == 0 then
		top_color = '#E9E9E9'
	elseif on_same_page and args.ShortSummary then
		top_color = '#F2F2F2'
	else
		top_color = 'inherit'
	end
		
	table_row:css('background',top_color)
	
	if args.EpisodeNumber then
		EpisodeNumber = mw.html.create('th')
				:attr('scope','row')
				:attr('id','ep'..args.EpisodeNumber)
				:css('text-align','center')
				:wikitext(args.EpisodeNumber)
		table_row:css('background',top_color)
		table_row:node(EpisodeNumber)
	end
	
	local function add_title()
		if args.Title then
			local title_string = '"'..args.Title..'"'
			if args.RTitle then
				title_string = title_string..args.RTitle
			end
			
			if args.AltTitle then
				title_string = title_string..'<br>"'..args.AltTitle..'"'
			end
			
			if args.RAltTitle then
				title_string = title_string..args.RAltTitle
			end
			return title_string
		end
	end

	for _,v in ipairs(cell_names) do
		if args[v] then
			nonnil_params = nonnil_params + 1
			td_tags[v] = mw.html.create('td')
			
			if v == 'Title' then
				local title_text = add_title()
				td_tags[v]:wikitext(title_text)
						:addClass('summary')
						:css('text-align','left')
			else
				td_tags[v]:wikitext(args[v])
			end
			table_row:node(td_tags[v])
		end
	end
	if ProdCode and args.ProdCode then
		ProdCode:attr('id','pc'..args.ProdCode)
	end
	
	local categories = ''
	
	if not args.LineColor and on_same_page and title.nsText == '' then
		categories = categories..'[[Category:Episode list using the default LineColor]]'
	end
	
	if args.TopColor and on_same_page and title.nsText == '' then
		categories = categories..'[[Category:Episode lists with row deviations]]'
	end
	
	if on_same_page and args.ShortSummary then
		local bottom_wrapper = mw.html.create('tr')
		local ShortSummary = mw.html.create('td')
					:addClass('description')
					:css('border-bottom','solid 3px #'..line_color)
					:attr('colspan',nonnil_params)
					:wikitext(args.ShortSummary)
		bottom_wrapper:node(ShortSummary)
		return tostring(table_row)..tostring(bottom_wrapper)..categories
	else
		return tostring(table_row)..categories
	end
end

return p