Module:Series overview: Difference between revisions

Created page with "-- This module implements {{Series overview}}. require('Module:No globals') local yesno = require('Module:Yesno') local HTMLcolor = mw.loadData( 'Module:Color contrast/colors..."
m (1 revision imported)
en>Andy Irons
(Created page with "-- This module implements {{Series overview}}. require('Module:No globals') local yesno = require('Module:Yesno') local HTMLcolor = mw.loadData( 'Module:Color contrast/colors...")
Line 12:
local SeriesOverview = {}
 
function SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, key, cell, multipart, setspan)
if setspan ~= nil then return setspan end
local spanlength = 1
local firstEntry = SeasonEntries[SeasonEntries_ordered[cell]]
if key == 'network' and firstEntry.networkA and not firstEntry.networkB then spanlength = 2 end
for i = cell+1, #SeasonEntries_ordered do
local entry = SeasonEntries[SeasonEntries_ordered[i]]
Line 23 ⟶ 29:
else break end
else
if not entry[key] and (key == 'network' or ((string.sub(key,0,7) == 'postaux' or string.sub(key,0,3) == 'aux') and (not entry.special or entry.episodes)) or (string.sub(key,0,4) == 'info') and multipart) then
spanlength = spanlength + 1
else break end
Line 83 ⟶ 89:
function SeriesOverview.new(frame, args)
args = args or {}
local initialArticle = args['1'] or ''
local categories = ''
local title = mw.title.getCurrentTitle()
Line 88 ⟶ 96:
 
-- Create series overview table
local root = mw.html.create((args.multiseries or not args.series) and 'table' or '')
local cellPadding = '0 8px'
local basePadding = '0.2em 0.4em'
 
root
Line 95 ⟶ 104:
:addClass('plainrowheaders')
:css('text-align', 'center')
-- Sortable
if args.sortable then
root:addClass('sortable');
end
-- Width
if args.width then
root:css('width', args.width)
end
 
-- Caption
if args.caption then
root:tag('caption'):wikitext(frame:expandTemplate{title='Screen reader-only',args={args.caption}})
end
 
-- Extract seasons info and place into a 3D array
local SeasonEntries = {}
for k,v in pairs(args) do
local str, num, str2 = string.match(k, '([^%d]*)(%d*)(%a*)')
if tonumber(k) ~= 1 and num ~= '' then
-- Special
local special = false
Line 131 ⟶ 150:
table.sort(SeasonEntries_ordered,SeriesOverview.series_sort)
local firstRow = args.multiseries and {} or SeasonEntries[SeasonEntries_ordered[1]]
-- Colspan calculation for information cells (0 = no info set)
Line 139 ⟶ 158:
local param = 'info' .. string.char(i)
if args[param] then numInfoCells = numInfoCells + 1 end
end
-- Use of colors and network
local noColors = true
local setNetwork = false
if (args.multiseries and args.network) then setNetwork = true end
for i = 1, #SeasonEntries_ordered do
local season, entry = SeasonEntries_ordered[i], SeasonEntries[SeasonEntries_ordered[i]]
for j0 = string.byte('A')-1, string.byte('Z') do
local j = string.char(j0)
if j0 == string.byte('A')-1 then j = '' end
if entry['color' .. j] then noColors = false end
if entry['network' .. j] then setNetwork = true end
end
end
-- Top info cell
-- @ = string.char(64), A = string.char(65)
local topInfoCell = args.infoheader and (numInfoCells > 0 and string.char(numInfoCells + (string.byte('A') - 1)) or 'A') or '@'
-- Networks are included if the very first entry sets the first network
local networkTransclude = args.network_transclude
if (networkTransclude == 'onlyinclude' and title.fullText == initialArticle) or (networkTransclude == 'noinclude' and title.fullText ~= initialArticle) then
setNetwork = false
end
 
-- Headers
do
if args.multiseries or not args.series then
local headerRow = root:tag('tr')
local headerRow = root:tag('tr')
headerRow
:css('text-align', 'center')
:css('text-align', 'center')
 
-- Networks are included if the very first entry sets the first network
local setNetworkreleasedBlurb = firstRowargs.networkreleased and 'released' or firstRow.networkA'aired'
local releasedBlurb = args.released and 'released' or 'aired'
-- Base series/season content on the format of the first date; Series = D M Y, Season = M D, Y
local matchDMY = false
-- Base series/season content on the format of the first date; Series = D M Y, Season = M D, Y
local matchDMYthisStart = falsefirstRow.start or firstRow.startA
local if thisStart = firstRow.start or firstRow.startAthen
if string.match(thisStart:gsub(" "," "), '(%d+)%s(%a+)%s(%d+)') then
matchDMY = true
if string.match(thisStart:gsub(" "," "), '(%d+)%s(%a+)%s(%d+)') then
matchDMY = trueend
end
end
-- Multiple series header
if args.multiseries then
-- Season header
headerRow:tag('th')
:attr('scope', 'col')
:attr('rowspan', allReleased and numInfoCells == 0 and 1 or 2)
:attr('colspan', 2)
:css('padding', cellPadding)
:wikitext(args.seriesT or args.seasonT or (matchDMY and 'Series') or 'Season')
-- Aux headers
for i = string.byte('A'), string.byte('Z') do
local param = 'aux' .. string.char(i)
if args[param] then
numAuxCells = numAuxCells + 1
headerRow:tag('th')
:attr('scope', 'col')
:css('padding', cellPadding)
:attr('rowspan', allReleased and numInfoCells == 0 and 1 or 2)
:wikitext(args[param]'Series')
end
end
-- Season header
 
-- Episodes header
headerRow:tag('th')
:attr('scope', 'col')
:attr('rowspan', allReleased and numInfoCells == 0 and 1 or 2)
:attr('colspan', 2)
:css('padding', cellPadding)
:wikitext('Episodes')
 
-- Originally aired header
headerRow:tag('th')
:attr('scope', 'col')
:attr('rowspan', allReleased and numInfoCells > 0 and 2 or 1)
:attr('colspan', setNetwork and 3 or 2)
:wikitext('Originally ' .. releasedBlurb)
-- Network subheader for released series
if setNetwork and allReleased then
headerRow:tag('th')
:attr('scope', 'col')
:attr('rowspan', allReleased and numInfoCells == 0 and 1 or 2)
:attr('colspan', ((args.multiseries and args.no_colors) or (not args.multiseries and noColors)) and 1 or 2)
:css('min-width', '50px')
:css('padding', cellPadding)
:wikitext(args.seriesT or args.seasonT or (matchDMY and 'NetworkSeries') or 'Season')
end
for _a = 1, 3 do
if _a == 1 or _a == 3 then
-- Subheader row
-- Aux headers
local subheaderRow = mw.html.create('tr')
local auxtype = (_a == 3 and 'post' or '') .. 'aux'
for i = string.byte('A'), string.byte('Z') do
local param = auxtype .. string.char(i)
if args[param] then
numAuxCells = numAuxCells + 1
headerRow:tag('th')
:attr('scope', 'col')
:css('padding', cellPadding)
:attr('rowspan', allReleased and 1 or 2)
:wikitext(args[param])
end
end
end
if _a == 2 then
-- Episodes header
headerRow:tag('th')
:attr('scope', 'col')
:attr('rowspan', allReleased and 1 or 2)
:attr('colspan', 2)
:css('padding', cellPadding)
:wikitext('Episodes')
end
end
 
-- InfoOriginally aired header
local OriginallyColspan = (not allReleased and setNetwork) and 3 or 2
if args.infoheader then
local countryBlurb = ''
if args.country then
countryBlurb = ' (' .. args.country .. ')'
end
headerRow:tag('th')
:attr('scope', 'col')
:attr('colspan', numInfoCells > 0 and numInfoCells or nilOriginallyColspan)
:wikitext('Originally ' .. releasedBlurb .. countryBlurb)
:attr('rowspan', (allReleased and 1) or (numInfoCells > 0 and 1) or 2)
:css('padding', cellPadding)
:wikitext(args.infoheader)
end
 
if not allReleased then
-- First aired subheader
subheaderRow:tag('th')
:attr('scope', 'col')
:wikitext('First ' .. releasedBlurb)
 
-- Last aired subheader
subheaderRow:tag('th')
:attr('scope', 'col')
:wikitext('Last ' .. releasedBlurb)
-- Network subheader for airedreleased series
if setNetwork and allReleased then
subheaderRowheaderRow:tag('th')
:attr('scope', 'col')
:attr('rowspan', allReleased and 1 or 2)
:css('padding', cellPadding)
:wikitext('Network')
end
end
-- Information headers
if topInfoCell ~= '@' then
for i = string.byte('A'), string.byte(topInfoCell) do
local param = 'info' .. string.char(i)
local infoTransclude = args[param .. '_transclude']
if (infoTransclude == 'onlyinclude' and title.fullText == initialArticle) or (infoTransclude == 'noinclude' and title.fullText ~= initialArticle) then else
headerRow:tag('th')
:attr('scope', 'col')
:attr('rowspan', allReleased and 1 or 2)
:css('padding', cellPadding)
:wikitext(args[param])
end
end
end
-- Subheader row
local subheaderRow = mw.html.create('tr')
 
if not allReleased then
-- Information subheaders, only if the infoheader doesn't span down (i.e. 2+ info cells set)
-- First aired subheader
if topInfoCell ~= 'A' then
for i = string.byte('A'), string.byte(topInfoCell) do
local param = 'info' .. string.char(i)
subheaderRow:tag('th')
:attr('scope', 'col')
:csswikitext('paddingFirst ', cellPadding.. releasedBlurb)
 
:wikitext(args[param])
-- Last aired subheader
subheaderRow:tag('th')
:attr('scope', 'col')
:wikitext('Last ' .. releasedBlurb)
-- Network subheader for aired series
if setNetwork then
subheaderRow:tag('th')
:attr('scope', 'col')
:css('padding', cellPadding)
:wikitext('Network')
end
end
-- Check for scenarios with an empty subheaderRow
if not allReleased or numInfoCells > 0 then
root:node(subheaderRow)
end
end
-- Check for scenarios with an empty subheaderRow
if not allReleased or numInfoCells > 0 then
root:node(subheaderRow)
end
end
Line 261 ⟶ 315:
-- Season rows
do
if args.multiseries then
-- One row entries, only categorized in the mainspace
-- Multi series individual entries
if title.namespace == 0 and #SeasonEntries == 1 then
if args.multiseries ~= "y" then
categories = categories .. '[[Category:Articles using Template:Series overview with only one row]]'
root:node(args.multiseries)
end
end
else
for X = 1, #SeasonEntries_ordered do
-- One row entries, only categorized in the mainspace
local season, entry = SeasonEntries_ordered[X], SeasonEntries[SeasonEntries_ordered[X]]
if title.namespace == 0 and #SeasonEntries == 1 then
categories = categories .. '[[Category:Articles using Template:Series overview with only one row]]'
-- Determine number of splits in a season
end
local splits = 0
for i = string.byte('A'), string.byte('Z') do
-- Determine number of rows in the whole overview
local param = 'start' .. string.char(i)
local SeasonEntriesRows = 0
if entry[param] then splits = splits + 1 end
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
local splitSeason = (splits > 1)
for X = 1, #SeasonEntries_ordered do
-- Season rows for each season
local season, entry = SeasonEntries_ordered[X], SeasonEntries[SeasonEntries_ordered[X]]
for k0 = string.byte('A')-1, string.byte('Z') do
local k = string.char(k0)
if k0 == string.byte('A')-1 then k = '' end
-- Determine number of splits in a season
-- New season row
local splits = 0
local seasonRow = entry['start' .. k] and root:tag('tr') or mw.html.create('tr')
for i = string.byte('A'), string.byte('Z') do
local param = 'start' .. string.char(i)
-- Coloured cell
if entry['color'param] ..then k]splits ~= nilsplits and+ HTMLcolor[entry['color' .. k]] == nil then1 end
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('scope','row')
:attr('rowspan', entry.color and splits or 1)
:css('background', entry.color)
:css('width','10px')
end
else
seasonRow:tag('td')
:attr('scope','row')
:css('background',entry['color' .. k])
:css('width','10px')
end
local splitSeason = (splits > 1)
-- Season numberrows link,for includedeach only in the first rowseason
iffor kk0 == string.byte('A')-1, or k == string.byte('AZ') thendo
seasonRow:taglocal k = string.char('td'k0)
if k0 == string.byte('A')-1 then k = '' end
:attr('rowspan', splitSeason and splits or nil)
:attr('colspan', entry.special and not entry.episodes and 3+numAuxCells or 1)
-- New season row
:wikitext((entry.link and '[[' .. entry.link .. '|' .. (entry.linkT or season) .. ']]' or (entry.linkT or season)) .. (entry.linkR or ''))
-- 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')
end
local seasonRow = entry['start' .. k] and root:tag('tr') or mw.html.create('tr')
-- Aux cells
-- Part header
for i = string.byte('A'), string.byte('Z') do
if entry.part then
local param = 'aux' .. string.char(i)
if seasonRow:node(entry[param .. k] thenpart)
local thisCell = SeriesOverview.season_cell(entry[param .. k], frame)
:attr('scope', 'col')
:attr('rowspan', SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, param, X))
:css('padding', cellPadding)
seasonRow:node(thisCell)
end
end
local borderBottom = '2px solid #8D939A'
-- Episodes counts
-- Series name for group overviews
if (splitSeason and k == 'A') or not splitSeason then
if entryX == 1 and (k == '' or k == 'A') and args.episodesseries then
seasonRow:tag('th')
local thisCell = SeriesOverview.season_cell(entry.episodes, frame)
:attr('colspanscope', splitSeason and 1 or 2'row')
:attr('rowspan', SeasonEntriesRows)
:wikitext(args.series)
:css('border-bottom', borderBottom)
end
if X == #SeasonEntries_ordered and args.series then
seasonRow:css('border-bottom', borderBottom)
end
-- Colored cell
if not noColors then
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','10px')
end
else
seasonRow:tag('td')
:css('background',entry['color' .. k])
:css('width','10px')
end
end
-- Season number link, included only in the first row
if k == '' or k == 'A' then
seasonRow:tag(args.series and 'td' or 'th')
:attr('scope', 'row')
:attr('rowspan', splitSeason and splits or nil)
:attr('colspan', entry.special and not entry.episodes and 3+numAuxCells or 1)
seasonRow:node(thisCell)
:css('text-align', 'center')
elseif not entry.special then
:wikitext((entry.link and '[[' .. entry.link .. '|' .. (entry.linkT or season) .. ']]' or (entry.linkT or season)) .. (entry.linkR or ''))
local infoCell = SeriesOverview.series_attributes( frame: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
for _a = 1, 3 do
if splitSeason then
if entry['episodes'_a ..== k]1 or _a == 3 then
-- Aux headers
local thisCell = SeriesOverview.season_cell(entry['episodes' .. k], frame)
local auxtype = (_a == 3 and 'post' or '') .. 'aux'
seasonRow:node(thisCell)
else -- Aux cells
for i = string.byte('A'), string.byte('Z') do
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
local param = auxtype .. string.char(i)
infoCell:css('padding',cellPadding)
if entry[param .. k] then
seasonRow:node(infoCell)
local thisCell = SeriesOverview.season_cell(entry[param .. k], frame)
:attr('scope', 'col')
:attr('rowspan', SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, param, X, (args.series and true or false), entry[param .. k .. 'span'] or nil))
:css('padding', cellPadding)
seasonRow:node(thisCell)
end
end
end
if _a == 2 then
-- 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, frame)
: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( frame: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], frame)
:attr('colspan', (entry.episodes ~= 'hide') and 1 or 2)
seasonRow:node(thisCell)
else
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
:attr('colspan', (entry.episodes ~= 'hide') and 1 or 2)
seasonRow:node(infoCell)
end
end
end
end
end
-- Start date
if entry['start' .. k] then
local thisCell = SeriesOverview.season_cell(entry['start' .. k], frame)
:attr('colspan',((not entry.special and entry['end' .. k] == 'start') or (entry.special and not entry['end' .. k])) and 2 or 1)
:css('padding',cellPadding)
seasonRow:node(thisCell)
else
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
infoCell:css('padding',cellPadding)
seasonRow:node(infoCell)
end
-- EndStart date
if not allReleased and entry['end' .. k] ~= 'start' and ((entry.special and entry['end' .. k]) or not entry.special) then
if local thisCell = SeriesOverview.season_cell(entry['endstart' .. k], thenframe)
:attr('colspan',((not entry.special and entry['end' .. k] == 'start') or (entry.special and not entry['end' .. k]) or allReleased) and 2 or 1)
local thisCell = SeriesOverview.season_cell(entry['end' .. k], frame)
:css('padding',cellPaddingbasePadding)
seasonRow:node(thisCell)
else
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
infoCell:css('padding',cellPaddingbasePadding)
seasonRow:node(infoCell)
end
end
-- Network
if entry['network' .. k] then
local thisCell = SeriesOverview.season_cell(entry['network' .. k], frame)
:attr('rowspan', SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, 'network', X))
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
-- End date
if splitSeason and k == '' and not entry[param .. 'A'] then
if not allReleased and entry[param'end' .. 'A'k] ~= 'start' and ((entry.special and entry[param'end' .. k]) or not entry.special) then
if entry[param'end' .. 'span'k] = 'y'then
local thisCell = SeriesOverview.season_cell(entry['end' .. k], frame)
:css('padding',cellPadding)
seasonRow:node(thisCell)
else
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
infoCell:css('padding',cellPadding)
seasonRow:node(infoCell)
end
end
-- Network
local infoParam = entry[param]
if infoParam and (k == entry['Anetwork' or.. (k ~= 'A'] and not entry[param0 .. 'span']))setNetwork then
local thisCell = SeriesOverview.season_cell(entry['network' .. k], frame)
-- Cells with {{N/A|...}} already expanded
:attr('rowspan', SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, 'network', X, (args.series and true or false), entry['network' .. k .. 'span'] or nil))
if string.sub(infoParam,1,5) == 'style' then
seasonRow:node(thisCell)
local infoCell = SeriesOverview.series_attributes(infoParam)
end
infoCell:attr('rowspan', entry[param0 .. 'span'] and splits or nil)
seasonRow:node(infoCell)
else-- Information
for i = string.byte('A'), string.byte(topInfoCell) do
-- Unstyled content info cell
local thisCellparam0 = SeriesOverview'info' ..season_cell(infoParam, framestring.char(i)
local param = 'info' .. string.char(i) .. k
:attr('rowspan', entry[param0 .. 'span'] and splits or nil)
seasonRow:node(thisCell)
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 .. 'spanning'] = 'y'
end
local rowspan = (entry[param0 .. 'spanning'] and splits) or
(args.series and SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, param0, X, (args.series and true or false), entry[param0 .. 'span'] or nil))
or nil
if k == 'A' or (k ~= 'A' and not entry[param0 .. 'spanning']) then
-- Cells with {{N/A|...}} 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, frame)
:attr('rowspan', rowspan)
seasonRow:node(thisCell)
end
else
if not args.series then
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
infoCell:attr('rowspan', rowspan)
seasonRow:node(infoCell)
end
end
elseif not entry[param0 .. 'spanning'] then
if not args.series then
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
infoCell:attr('rowspan', rowspan)
seasonRow:node(infoCell)
end
end
end
elseif not entry[param0 .. 'span'] then
local infoCell = SeriesOverview.series_attributes( frame:expandTemplate{title='N/A',args={'TBA'}} )
infoCell:attr('rowspan', entry[param0 .. 'span'] and splits or nil)
seasonRow:node(infoCell)
end
end
end -- End k0 string.byte
end -- End k0'for' string.byteSeasonEntries_ordered
end -- End 'forif' SeasonEntries_orderedmultiseries
end -- End 'do' season rows
 
return (args.dontclose and mw.ustring.gsub(tostring(root), "</table>", "") or tostring(root)) .. categories
end
 
Anonymous user