categories = categories .. ''
end  
-- Determine number of rows in the whole overview
local SeasonEntriesRows = 0
for X = 1, #SeasonEntries_ordered do
local season, entry = SeasonEntries_ordered[X], SeasonEntries[SeasonEntries_ordered[X]]
local splits = 0
for i = string.byte('A'), string.byte('Z') do
local param = 'start' .. string.char(i)
if entry[param] then splits = splits + 1 end
end
if splits == 0 then splits = 1 end
SeasonEntriesRows = SeasonEntriesRows + splits
end  
for X = 1, #SeasonEntries_ordered do
local season, entry = SeasonEntries_ordered[X], SeasonEntries[SeasonEntries_ordered[X]]  
-- Determine number of splits in a season
local splits = 0
for i = string.byte('A'), string.byte('Z') do
local param = 'start' .. string.char(i)
if entry[param] then splits = splits + 1 end
end
local splitSeason = (splits > 1)  
-- Season rows for each season
for k0 = string.byte('A')-1, string.byte('Z') do
local k = string.char(k0)
if k0 == string.byte('A')-1 then k = '' end  
-- New season row
-- local seasonRow = (entry['color' .. k] or entry['episodes' .. k] or entry['start' .. k] or entry['end' .. k]) and root:tag('tr') or mw.html.create('tr')
local seasonRow = entry['start' .. k] and root:tag('tr') or mw.html.create('tr')  
-- Series name for group overviews
if X == 1 and (k == '' or k == 'A') and args.series then
seasonRow:tag('th')
:attr('scope', 'row')
:attr('rowspan', SeasonEntriesRows)
:wikitext(args.series)
end  
-- Coloured cell
if entry['color' .. k] ~= nil and HTMLcolor[entry['color' .. k]] == nil then
entry['color' .. k] = '#'..(mw.ustring.match(entry['color' .. k], '^[%s#]*([a-fA-F0-9]*)[%s]*$') or '')
end
if splitSeason and entry.color then
if k == 'A' then
seasonRow:tag('td')
:attr('rowspan', entry.color and splits or 1)
:css('background', entry.color)
:css('width','')
end
else
seasonRow:tag('td')
:css('background',entry['color' .. k])
:css('width','')
end  
-- Season number link, included only in the first row
if k == '' or k == 'A' then
seasonRow:tag('th')
:attr('scope', 'row')
:attr('rowspan', splitSeason and splits or nil)
:attr('colspan', entry.special and not entry.episodes and 3+numAuxCells or 1)
:css('text-align', '')
:wikitext((entry.link and * .. (entry.linkT or season) .. * or (entry.linkT or season)) .. (entry.linkR or ''))
end  
-- Aux cells
for i = string.byte('A'), string.byte('Z') do
local param = 'aux' .. string.char(i)
if entry[param .. k] then
local thisCell = SeriesOverview.season_cell(entry[param .. k], )
:attr('scope', 'col')
:attr('rowspan', SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, param, X, (args.series and true or false)))
:css('padding', cellPadding)
seasonRow:node(thisCell)
end
end  
-- Episodes counts
if ((splitSeason and k == 'A' and entry.episodes ~= 'hide') or not splitSeason) then
if entry.episodes then
local thisCell = SeriesOverview.season_cell(entry.episodes, )
:attr('colspan', splitSeason and 1 or 2)
:attr('rowspan', splitSeason and splits or nil)
seasonRow:node(thisCell)
elseif not entry.special then
local infoCell = SeriesOverview.series_attributes( :expandTemplate{title='N/A',args={'TBA'}} )
infoCell
:attr('colspan', splitSeason and 1 or 2)
:attr('rowspan', splitSeason and splits or nil)
seasonRow:node(infoCell)
end
end
if splitSeason then
if entry['episodes' .. k] then
local thisCell = SeriesOverview.season_cell(entry['episodes' .. k], )
:attr('colspan', (entry.episodes ~= 'hide') and 1 or 2)
seasonRow:node(thisCell)
else
local infoCell = SeriesOverview.series_attributes( :expandTemplate{title='N/A',args={'TBA'}} )
:attr('colspan', (entry.episodes ~= 'hide') and 1 or 2)
seasonRow:node(infoCell)
end
end  
-- Start date
if entry['start' .. k] then
local thisCell = SeriesOverview.season_cell(entry['start' .. k], )
:attr('colspan',((not entry.special and entry['end' .. k] == 'start') or (entry.special and not entry['end' .. k]) or allReleased) and 2 or 1)
:css('padding',basePadding)
seasonRow:node(thisCell)
else
local infoCell = SeriesOverview.series_attributes( :expandTemplate{title='N/A',args={'TBA'}} )
infoCell:css('padding',basePadding)
seasonRow:node(infoCell)
end  
-- End date
if not allReleased and entry['end' .. k] ~= 'start' and ((entry.special and entry['end' .. k]) or not entry.special) then
if entry['end' .. k] then
local thisCell = SeriesOverview.season_cell(entry['end' .. k], )
:css('padding',cellPadding)
seasonRow:node(thisCell)
else
local infoCell = SeriesOverview.series_attributes( :expandTemplate{title='N/A',args={'TBA'}} )
infoCell:css('padding',cellPadding)
seasonRow:node(infoCell)
end
end  
-- Network
if entry['network' .. k] and setNetwork then
local thisCell = SeriesOverview.season_cell(entry['network' .. k], )
:attr('rowspan', SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, 'network', X, (args.series and true or false)))
seasonRow:node(thisCell)
end  
-- Information
for i = string.byte('A'), string.byte(topInfoCell) do
local param0 = 'info' .. string.char(i)
local param = 'info' .. string.char(i) .. k  
local infoTransclude = args[param .. '_transclude']
if (infoTransclude == 'onlyinclude' and title.fullText == initialArticle) or (infoTransclude == 'noinclude' and title.fullText ~= initialArticle) then else
local infoParam = entry[param]  
if infoParam and splitSeason and k == '' and not entry[param .. 'A'] then
entry[param .. 'A'] = entry[param]
entry[param .. 'span'] = 'y'
end  
local rowspan = (entry[param0 .. 'span'] and splits) or
(args.series and SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, param0, X, (args.series and true or false)))
or nil  
if k == 'A' or (k ~= 'A' and not entry[param0 .. 'span']) then
-- Cells with already expanded
if infoParam then
if string.sub(infoParam,1,5) == 'style' then
local infoCell = SeriesOverview.series_attributes(infoParam)
infoCell:attr('rowspan', rowspan)
seasonRow:node(infoCell)
else
-- Unstyled content info cell
local thisCell = SeriesOverview.season_cell(infoParam, )
:attr('rowspan', rowspan)
seasonRow:node(thisCell)
end
else
if not args.series then
local infoCell = SeriesOverview.series_attributes( :expandTemplate{title='N/A',args={'TBA'}} )
infoCell:attr('rowspan', rowspan)
seasonRow:node(infoCell)
end
end
elseif not entry[param0 .. 'span'] then
if not args.series then
local infoCell = SeriesOverview.series_attributes( :expandTemplate{title='N/A',args={'TBA'}} )
infoCell:attr('rowspan', rowspan)
seasonRow:node(infoCell)
end
end
end
end  
end -- End k0 string.byte
end -- End 'for' SeasonEntries_ordered
end -- End 'if' multiseries
end -- End 'do' season rows  
return (args.dontclose and mw.ustring.gsub(tostring(root), "</table>", "") or tostring(root)) .. categories
end  
---
-- Exports
---  
local p = {}  
function p.main
local args = require('Module:Arguments').getArgs(, {
wrappers = 'Template:Series overview'
})
return SeriesOverview.new(, args)
end  
return p