<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.filipefonseca.pt/index.php?action=history&amp;feed=atom&amp;title=Module%3AEpisode_table</id>
	<title>Module:Episode table - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.filipefonseca.pt/index.php?action=history&amp;feed=atom&amp;title=Module%3AEpisode_table"/>
	<link rel="alternate" type="text/html" href="http://wiki.filipefonseca.pt/index.php?title=Module:Episode_table&amp;action=history"/>
	<updated>2026-04-21T08:21:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>http://wiki.filipefonseca.pt/index.php?title=Module:Episode_table&amp;diff=4876&amp;oldid=prev</id>
		<title>FilipeFonseca: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://wiki.filipefonseca.pt/index.php?title=Module:Episode_table&amp;diff=4876&amp;oldid=prev"/>
		<updated>2021-07-08T14:35:39Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module implements {{Episode table}} and {{Episode table/part}}.&lt;br /&gt;
&lt;br /&gt;
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- EpisodeTable class&lt;br /&gt;
-- The main class.&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local contrast_ratio = require('Module:Color contrast')._ratio&lt;br /&gt;
local EpisodeTable = {}&lt;br /&gt;
&lt;br /&gt;
function EpisodeTable.cell(background, width, text, reference)&lt;br /&gt;
	local cell = mw.html.create('th')&lt;br /&gt;
	&lt;br /&gt;
	-- Width&lt;br /&gt;
	local cell_width&lt;br /&gt;
	if width == 'auto' then&lt;br /&gt;
		cell_width = 'auto'&lt;br /&gt;
	elseif tonumber(width) ~= nil then&lt;br /&gt;
		cell_width = width .. '%'&lt;br /&gt;
	else&lt;br /&gt;
		cell_width = nil&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Cell&lt;br /&gt;
	cell:attr('scope','col')&lt;br /&gt;
		:css('background',background or '#CCCCFF')&lt;br /&gt;
		:css('width',cell_width)&lt;br /&gt;
		:wikitext(text)&lt;br /&gt;
	&lt;br /&gt;
	-- Reference&lt;br /&gt;
	if reference and reference ~= '' then&lt;br /&gt;
		cell:wikitext(&amp;quot;&amp;amp;#8202;&amp;quot; .. EpisodeTable.reference(reference, background))&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return cell&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function EpisodeTable.reference(reference, background)&lt;br /&gt;
	local link1_cr = contrast_ratio{'#0645AD', background or '#CCCCFF', ['error'] = 0}&lt;br /&gt;
	local link2_cr = contrast_ratio{'#0B0080', background or '#CCCCFF', ['error'] = 0}&lt;br /&gt;
	&lt;br /&gt;
	local refspan = mw.html.create('span')&lt;br /&gt;
		:wikitext(reference)&lt;br /&gt;
	&lt;br /&gt;
	if link1_cr &amp;lt; 7 or link2_cr &amp;lt; 7 then&lt;br /&gt;
		refspan&lt;br /&gt;
			:css('background-color','white')&lt;br /&gt;
			:css('padding','1px')&lt;br /&gt;
			:css('display','inline-block')&lt;br /&gt;
			:css('line-height','50%')&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return tostring(refspan)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function EpisodeTable.abbr(text,title)&lt;br /&gt;
	local abbr = mw.html.create('abbr')&lt;br /&gt;
		:attr('title',title)&lt;br /&gt;
		:wikitext(text)&lt;br /&gt;
	return tostring(abbr)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function EpisodeTable.part(frame,args)&lt;br /&gt;
	local row = mw.html.create('tr')&lt;br /&gt;
	&lt;br /&gt;
	local black_cr = contrast_ratio{args.c, 'black', ['error'] = 0}&lt;br /&gt;
	local white_cr = contrast_ratio{'white', args.c, ['error'] = 0}&lt;br /&gt;
	&lt;br /&gt;
	local displaytext = (not args.nopart and 'Part ' or '') .. (args.p or '')&lt;br /&gt;
	&lt;br /&gt;
	local plainText = require('Module:Plain text')._main&lt;br /&gt;
	local displayTextAnchor = plainText(displaytext)&lt;br /&gt;
	&lt;br /&gt;
	row:tag('td')&lt;br /&gt;
		:attr('colspan', 13)&lt;br /&gt;
		:attr('id', displayTextAnchor)&lt;br /&gt;
		:css('text-align', 'center')&lt;br /&gt;
		:css('background-color', args.c)&lt;br /&gt;
		:css('color', black_cr &amp;gt; white_cr and 'black' or 'white')&lt;br /&gt;
		:wikitext(&amp;quot;'''&amp;quot; .. displaytext .. &amp;quot;'''&amp;quot; .. (args.r and &amp;quot;&amp;amp;#8202;&amp;quot; .. EpisodeTable.reference(args.r, args.c) or ''))&lt;br /&gt;
	&lt;br /&gt;
	return tostring(row)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function EpisodeTable.new(frame,args)&lt;br /&gt;
	args = args or {}&lt;br /&gt;
	local categories = ''&lt;br /&gt;
	local background = (args.background and args.background ~= '' and args.background ~= '#') and args.background or nil&lt;br /&gt;
	&lt;br /&gt;
	-- Add # to background if necessary&lt;br /&gt;
	if background ~= nil and HTMLcolor[background] == nil then&lt;br /&gt;
		background = '#'..(mw.ustring.match(background, '^[%s#]*([a-fA-F0-9]*)[%s]*$') or '')&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Default widths noted by local consensus&lt;br /&gt;
	local defaultwidths = {};&lt;br /&gt;
	defaultwidths.overall = 5;&lt;br /&gt;
	defaultwidths.overall2 = 5;&lt;br /&gt;
	defaultwidths.season = 5;&lt;br /&gt;
	defaultwidths.series = 5;&lt;br /&gt;
	defaultwidths.prodcode = 7;&lt;br /&gt;
	defaultwidths.viewers = 10;&lt;br /&gt;
	&lt;br /&gt;
	-- Create episode table&lt;br /&gt;
	local root = mw.html.create('table')&lt;br /&gt;
	&lt;br /&gt;
	-- Table width&lt;br /&gt;
	local table_width = string.gsub(args.total_width or '','%%','')&lt;br /&gt;
	if args.total_width == 'auto' or args.total_width == '' then&lt;br /&gt;
		table_width = 'auto'&lt;br /&gt;
	elseif tonumber(table_width) ~= nil then&lt;br /&gt;
		table_width = table_width .. '%'&lt;br /&gt;
	else&lt;br /&gt;
		table_width = '100%'&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	root&lt;br /&gt;
		:addClass('wikitable')&lt;br /&gt;
		:addClass('plainrowheaders')&lt;br /&gt;
		:addClass('wikiepisodetable')&lt;br /&gt;
		:css('width', table_width)&lt;br /&gt;
	&lt;br /&gt;
	-- Caption&lt;br /&gt;
	if args.show_caption then&lt;br /&gt;
		-- Visible caption option, with a tracking category&lt;br /&gt;
		root:tag('caption'):wikitext(args.caption)&lt;br /&gt;
		categories = categories .. '[[Category:Articles using Template:Episode table with a visible caption]]'&lt;br /&gt;
	elseif args.caption then&lt;br /&gt;
		-- If a visible caption isn't defined, then default to the screenreader-only caption&lt;br /&gt;
		root:tag('caption'):wikitext(frame:expandTemplate{title='Screen reader-only',args={args.caption}})&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Colour contrast; add to category only if it's in the mainspace&lt;br /&gt;
	local title = mw.title.getCurrentTitle()&lt;br /&gt;
	local black_cr = contrast_ratio{background, 'black', ['error'] = 0}&lt;br /&gt;
	local white_cr = contrast_ratio{'white', background, ['error'] = 0}&lt;br /&gt;
	&lt;br /&gt;
	if title.namespace == 0 and (args.background and args.background ~= '' and args.background ~= '#') and black_cr &amp;lt; 7 and white_cr &amp;lt; 7 then&lt;br /&gt;
		categories = categories .. '[[Category:Articles using Template:Episode table with invalid colour combination]]' &lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Main row&lt;br /&gt;
	local mainRow = root:tag('tr')&lt;br /&gt;
	mainRow&lt;br /&gt;
		:css('color', background and (black_cr &amp;gt; white_cr and 'black' or 'white') or 'black')&lt;br /&gt;
		:css('text-align', 'center')&lt;br /&gt;
	&lt;br /&gt;
	-- Cells&lt;br /&gt;
	do&lt;br /&gt;
		local used_season = false&lt;br /&gt;
		local country = args.country ~= '' and args.country ~= nil&lt;br /&gt;
		local viewers = (country and args.country or '') .. ' ' .. (country and 'v' or 'V') .. 'iewers' ..&lt;br /&gt;
			((not args.viewers_type or args.viewers_type ~= '') and '&amp;lt;br /&amp;gt;(' .. (args.viewers_type or 'millions') .. ')' or '')&lt;br /&gt;
		&lt;br /&gt;
		local cellNames = {&lt;br /&gt;
			{'overall','EpisodeNumber',EpisodeTable.abbr('No.','Number') ..&lt;br /&gt;
				((args.season or args.series or args.EpisodeNumber2 or args.EpisodeNumber2Series or args.forceoverall) and '&amp;lt;br /&amp;gt;overall' or '')},&lt;br /&gt;
			{'overall2','*',''},&lt;br /&gt;
			{'season','EpisodeNumber2',EpisodeTable.abbr('No.','Number') .. ' in&amp;lt;br /&amp;gt;season'},&lt;br /&gt;
			{'series','EpisodeNumber2Series',EpisodeTable.abbr('No.','Number') .. ' in&amp;lt;br /&amp;gt;series'},&lt;br /&gt;
			{'title','Title','Title'},&lt;br /&gt;
			{'aux1','Aux1',''},&lt;br /&gt;
			{'director','DirectedBy','Directed by'},&lt;br /&gt;
			{'writer','WrittenBy','Written by'},&lt;br /&gt;
			{'aux2','Aux2',''},&lt;br /&gt;
			{'aux3','Aux3',''},&lt;br /&gt;
			{'airdate','OriginalAirDate','Original ' .. (args.released and 'release' or 'air') .. ' date'},&lt;br /&gt;
			{'altdate','AltDate',''},&lt;br /&gt;
			{'guests','Guests','Guest(s)'},&lt;br /&gt;
			{'musicalguests','MusicalGuests','Musical/entertainment guest(s)'},&lt;br /&gt;
			{'prodcode','ProdCode',EpisodeTable.abbr('Prod.','Production') .. '&amp;lt;br /&amp;gt;code'},&lt;br /&gt;
			{'viewers','Viewers',viewers},&lt;br /&gt;
			{'aux4','Aux4',''}&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
		for k,v in pairs(cellNames) do&lt;br /&gt;
			local thisCell = args[v[1]] or args[v[2]]&lt;br /&gt;
			if thisCell and (v[1] ~= 'series' or (v[1] == 'series' and used_season == false)) then&lt;br /&gt;
				if v[1] == 'season' then used_season = true end&lt;br /&gt;
				if (k &amp;lt;= 3 and thisCell == '') then thisCell = '5' end&lt;br /&gt;
				if (thisCell == '' and defaultwidths[v[1]]) then thisCell = defaultwidths[v[1]] end&lt;br /&gt;
				&lt;br /&gt;
				local thisCellT = args[v[1] .. 'T'] or args[v[2] .. 'T']&lt;br /&gt;
				local thisCellR = args[v[1] .. 'R'] or args[v[2] .. 'R']&lt;br /&gt;
				mainRow:node(EpisodeTable.cell(background, thisCell, thisCellT or v[3], thisCellR))&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	&lt;br /&gt;
		-- Episodes&lt;br /&gt;
		if args.episodes then&lt;br /&gt;
			if args.anchor then &lt;br /&gt;
				args.episodes = string.gsub(args.episodes, &amp;quot;(id=\&amp;quot;)(ep%w+\&amp;quot;)&amp;quot;, &amp;quot;%1&amp;quot; .. args.anchor .. &amp;quot;%2&amp;quot;)&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			root:node(args.episodes)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return (args.dontclose and mw.ustring.gsub(tostring(root), &amp;quot;&amp;lt;/table&amp;gt;&amp;quot;, &amp;quot;&amp;quot;) or tostring(root)) .. categories&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Exports&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = require('Module:Arguments').getArgs(frame, {&lt;br /&gt;
		removeBlanks = false,&lt;br /&gt;
		wrappers = 'Template:Episode table'&lt;br /&gt;
	})&lt;br /&gt;
	return EpisodeTable.new(frame,args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.part(frame)&lt;br /&gt;
	local args = require('Module:Arguments').getArgs(frame, {&lt;br /&gt;
		removeBlanks = false,&lt;br /&gt;
		wrappers = 'Template:Episode table/part'&lt;br /&gt;
	})&lt;br /&gt;
	return EpisodeTable.part(frame,args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.ref(frame)&lt;br /&gt;
	local args = require('Module:Arguments').getArgs(frame, {&lt;br /&gt;
		removeBlanks = false,&lt;br /&gt;
	})&lt;br /&gt;
	return EpisodeTable.reference(args.r,args.b)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>FilipeFonseca</name></author>
	</entry>
</feed>