-- This module implements .
require('strict')local yesno = require('Module:Yesno')local HTMLcolor = mw.loadData('Module:Color contrast/colors')
---------------------------------------------------------------------------------- SeriesOverview class-- The main class.--------------------------------------------------------------------------------
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' or ((string.sub(key,0,7)
'aux') and (not entry.special or entry['díly'])) or (string.sub(key,0,4)
-- Sorting functionfunction SeriesOverview.series_sort(op1, op2) local n1,s1 = string.match(op1,"(%d+)(%a*)") local n2,s2 = string.match(op2,"(%d+)(%a*)") local n1N,n2N = tonumber(n1),tonumber(n2)
if n1N
-- Function to add either text or to cellfunction SeriesOverview.season_cell(text, frame) local cell if string.find(text or , 'table-na', 0, true) ~= nil then local findpipe = string.find(text, ' | ', 0, true) if findpipe ~= nil then cell = SeriesOverview.series_attributes(frame:expandTemplate) else cell = SeriesOverview.series_attributes(frame:expandTemplate) end else cell = mw.html.create('td'):wikitext(text) end return cellend
-- Allow usages of cellsfunction SeriesOverview.series_attributes(infoParam) local entries = local infoCell = mw.html.create('td') local attrMatch = '([%a-]*)="([^"]*)"' while true do local a,b = string.match(infoParam,attrMatch) if a
nil then break end infoCell:attr(a,b) infoParam = string.gsub(infoParam,attrMatch,,1) end
infoParam = string.gsub(infoParam,'%s*|%s*',,1) infoCell:wikitext(infoParam) return infoCellend
function SeriesOverview.new(frame, args) args = args or local initialArticle = args['1'] or local categories = local title = mw.title.getCurrentTitle local allReleased = yesno(args['vydání všeho'] or args.allreleased)
-- 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 :addClass('wikitable') :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) 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 if string.sub(str2,1,1)
-- Order table by season number local SeasonEntries_ordered = for k in pairs(SeasonEntries) do table.insert(SeasonEntries_ordered, k) end 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) local numAuxCells = 0 local numInfoCells = 0 for i = string.byte('A'), string.byte('Z') do 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
'onlyinclude' and title.fullText
'noinclude' and title.fullText ~= initialArticle) then setNetwork = false end
-- Headers do if args.multiseries or not args.series then local headerRow = root:tag('tr') headerRow :css('text-align', 'center') local releasedBlurb = args['vydání'] and 'vydáno' or 'vysíláno' -- Base series/season content on the format of the first date; Series = D M Y, Season = M D, Y local matchDMY = false local thisStart = firstRow.start or firstRow.startA if thisStart then if string.match(thisStart:gsub(" "," "), '(%d+)%s(%a+)%s(%d+)') then matchDMY = true end end -- Multiple series header if args.multiseries then headerRow:tag('th') :attr('scope', 'col') :css('padding', cellPadding) :attr('rowspan', allReleased and 1 or 2) :wikitext('Series') end -- Season header headerRow:tag('th') :attr('scope', 'col') :attr('rowspan', allReleased 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 'Seriál') or 'Řada') for _a = 1, 3 do if _a
3 then -- Aux headers local auxtype = (_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('Díly') end end
-- Originally aired header local OriginallyColspan = (not allReleased and setNetwork) and 3 or 2 local countryBlurb = if args['země'] or args.country then countryBlurb = ' ' .. args['země'] or args.country .. end headerRow:tag('th') :attr('scope', 'col') :attr('colspan', OriginallyColspan) :wikitext('Původně ' .. releasedBlurb .. countryBlurb) -- Network subheader for released series if setNetwork and allReleased then headerRow:tag('th') :attr('scope', 'col') :attr('rowspan', allReleased and 1 or 2) :css('padding', cellPadding) :wikitext('Network') 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
initialArticle) or (infoTransclude
if not allReleased then -- First aired subheader subheaderRow:tag('th') :attr('scope', 'col') :wikitext('První díl')
-- Last aired subheader subheaderRow:tag('th') :attr('scope', 'col') :wikitext('Poslední díl') -- 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 end
-- Season rows do if args.multiseries then -- Multi series individual entries if args.multiseries ~= "y" then root:node(args.multiseries) end else -- One row entries, only categorized in the mainspace if title.namespace
1 then 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 = 'začátek' .. string.char(i) if entry[param] then splits = splits + 1 end end if splits
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['začátek' .. k] and root:tag('tr') or mw.html.create('tr') -- Part header if entry.part then seasonRow:node(entry.part) end local borderBottom = '2px solid #8D939A' -- Series name for group overviews if X
or k
#SeasonEntries_ordered and args.series then seasonRow:css('border-bottom', borderBottom) end -- Colored cell if not noColors then if entry['řada' .. k] ~= nil and HTMLcolor[entry['řada' .. k]]
'A' then seasonRow:tag('td') :attr('rowspan', entry['řada'] and splits or 1) :css('background', entry['řada']) :css('width','10px') end else seasonRow:tag('td') :css('background',entry['řada' .. k]) :css('width','10px') end end -- Season number link, included only in the first row if 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['díly'] and 3+numAuxCells or 1) :css('text-align', 'center') :wikitext((entry.link and '' .. (entry.linkT or season) .. '' or (entry.linkT or season)) .. (entry.linkR or )) end for _a = 1, 3 do if _a
3 then -- Aux headers local auxtype = (_a
2 then -- Episodes counts if ((splitSeason and k
'začátek') or (entry.special and not entry['konec' .. k]) or allReleased) and 2 or 1) :css('padding',basePadding) seasonRow:node(thisCell) else local infoCell = SeriesOverview.series_attributes(frame:expandTemplate) infoCell:css('padding',basePadding) seasonRow:node(infoCell) end -- End date if not allReleased and entry['konec' .. k] ~= 'začátek' and ((entry.special and entry['konec' .. k]) or not entry.special) then if entry['konec' .. k] then local thisCell = SeriesOverview.season_cell(entry['konec' .. k], frame) :css('padding',cellPadding) seasonRow:node(thisCell) else local infoCell = SeriesOverview.series_attributes(frame:expandTemplate) 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], frame) :attr('rowspan', SeriesOverview.cellspan(SeasonEntries, SeasonEntries_ordered, 'network', X, (args.series and true or false), entry['network' .. k .. 'span'] or nil)) 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
initialArticle) or (infoTransclude
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
'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) 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) 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), "", "") or tostring(root)) .. categoriesend
---------------------------------------------------------------------------------- Exports--------------------------------------------------------------------------------
local p =
function p.main(frame) local args = require('Module:Arguments').getArgs(frame,) return SeriesOverview.new(frame, args)end
return p