Module:Episode list: Difference between revisions

Content deleted Content added
Undid revision 1112400418 by Alex 21 (talk) Per talk page request
Comment out per talk page
 
(47 intermediate revisions by 11 users not shown)
Line 4:
local colorContrastModule = require('Module:Color contrast')
local htmlColor = mw.loadData('Module:Color contrast/colors')
local delinkModule = require('Module:Delink')
local langModule = require("Module:Lang")
local mathModule = require('Module:Math')
Line 33 ⟶ 32:
["tba_values"] = "[[Category:Episode lists with TBA values]]",
["nonmatching_numbered_parameters"] = "[[Category:Episode lists with a non-matching set of numbered parameters]]",
["raw_unformatted_storyteleplay"] = "[[Category:Episode lists with unformatted story or teleplay credits]]",
}
 
-- List of parameter names in this order.
local cellNameList = {
'EpisodeNumber',
'EpisodeNumber2',
'Title',
'Aux1',
'DirectedBy',
Line 61 ⟶ 63:
local parameterGroupCells = {}
local firstParameterGroupCell
local parameterGroupCellsAny = false
 
-- List of title parameter names in this order.
Line 124 ⟶ 127:
shortSummaryText = shortSummaryText .. '\n<span></span>'
end
local shortSummaryDiv = mw.html.create('div')
:addClass('shortSummaryText')
:css('max-width', '90vw')
:css('position', 'sticky')
:css('left', '0.2em')
:newline()
:wikitext(shortSummaryText)
 
local shortSummaryCell = mw.html.create('td')
Line 130 ⟶ 141:
:attr('colspan', nonNilParams)
:newline()
:wikitextnode(shortSummaryTextshortSummaryDiv)
 
return mw.html.create('tr')
Line 136 ⟶ 147:
:node(shortSummaryCell)
end
 
 
-- Local function which is used to add tracking categories for Top Color issues.
Line 169 ⟶ 181:
addTrackingCategory(trackingCategoryList["default_line_colors"])
end
end
 
-- Local function which is used to remove wiki-links from repated information in rowspans.
-- Used for Doctor Who serials, where the director and writer are the same for each part of serial.
local function removeWikilinks(args, v)
return delinkModule._delink{args[v]}
end
 
Line 180 ⟶ 186:
-- with either "TBD" or "N/A".
-- Set to N/A if viewers haven't been available for four weeks, else set it as TBD.
local function setTBDStatus(args, awaitingText, expiredText, weeks)
if args.OriginalAirDate == nil or args.OriginalAirDate == '' then
return tableEmptyCellModule._main({alt_text = awaitingText})
end
 
-- If it hasn't aired, change to "N/A".
if string.match(args.OriginalAirDate, '^Unaired') then
return tableEmptyCellModule._main({alt_text = "N/A"})
end
 
local month, day, year = args.OriginalAirDate:gsub("&nbsp;", " "):match("(%a+) (%d+), (%d+)")
 
Line 212 ⟶ 227:
local seconds = os.time() - os.time({year = year, month = monthList[month], day = day, hour = 0, min = 0, sec = 0})
 
if (seconds >= 60 * 60 * 24 * 7 * 4weeks) then
return tableEmptyCellModule._main({alt_text = "N/A"expiredText})
else
return tableEmptyCellModule._main({alt_text = "TBD"awaitingText})
end
end
Line 225 ⟶ 240:
args[v] = tableEmptyCellModule._main({alt_text = "N/A"})
elseif (v == 'Viewers' and hasValue(args.OriginalAirDate)) then
args[v] = setTBDStatus(args, "TBD", "N/A", 4)
elseif (v == 'DirectedBy' or v == 'WrittenBy') then
args[v] = setTBDStatus(args, "TBA", "Unknown", 4)
else
args[v] = tableEmptyCellModule._main({})
Line 233 ⟶ 250:
-- Air dates that don't use {{Start date}}
local function checkUsageOfDateTemplates(args, v, onInitialPage, title)
if (v == 'OriginalAirDate'
and args[v] ~= ''
and string.match(args[v], '%d%d%d%d') ~=-- nilEnsure it contains a four-digit number (likely a year)
and string.match(args[v], '2C2C2C') == nil -- Avoids this specific pattern
and not string.findmatch(args[v], 'dtstart^Unaired') ==-- Exclude anything starting with nil"Unaired"
and string.find(args[v], 'itvstart') == nil -- Avoids a {{Start date}} unique class
and onInitialPage
and title.namespace == 0)
then
addTrackingCategory(trackingCategoryList["air_dates"])
Line 251 ⟶ 269:
 
-- Local function which is used to create a Production Code cell.
local function createProductionCodeCell(args, v, numberOfParameterGroups)
local thisRowspan
if (not parameterGroupCells[v] and parameterGroupCellsAny) then
thisRowspan = numberOfParameterGroups
else
thisRowspan = 1
end
if (hasValue(args.ProdCode) and string.find(args.ProdCode, 'TBA') == nil) then
row:tag('td')
:attr('id', 'pc' .. idTrim(idTrim(args.ProdCode, ' ----'), '<'))
:attr('rowspan', thisRowspan)
:css('text-align', 'center')
:wikitext(args.ProdCode)
elseif (args.ProdCode == '' or string.find(args.ProdCode or '', 'TBA') ~= nil) then
createEmptyCell(args, v, false)
createTableData(args.ProdCode, 1thisRowspan, "center")
else
-- ProductionCode parameter not used; Do nothing.
Line 272 ⟶ 298:
use the non-numbered parameter names (Title, Aux).
 
The function returns the args as non-numbered prameterparameter names.
]]--
local function extractDataFromNumberedSerialArgs(args, i, numberOfParameterGroups, title)
Line 296 ⟶ 322:
 
return args
end
 
--[[
Local function which is used to create column cells.
 
EpisodeNumber, EpisodeNumber2 and Title are created in different functions
as they require some various if checks.
 
See:
-- createEpisodeNumberCell()
-- createEpisodeNumberCellSecondary()
-- createTitleCell()
]]--
local function createCells(args, isSerial, currentRow, onInitialPage, title, numberOfParameterGroups)
for k, v in ipairs(cellNameList) do
if (v == 'ProdCode') then
createProductionCodeCell(args, v)
elseif (args[v]) then
-- Set empty cells to TBA/TBD
if (args[v] == '') then
createEmptyCell(args, v, false)
elseif (v == 'WrittenBy' and title.namespace == 0) then
if ((string.find(args[v], "''Story") ~= nil or string.find(args[v], "''Teleplay") ~= nil) and string.find(args[v], "8202") == nil) then
-- &#8202; is the hairspace added through {{StoryTeleplay}}
addTrackingCategory(trackingCategoryList["raw_unformatted_storyteleplay"])
end
end
 
-- If serial titles need to be centered and not left, then this should be removed.
local textAlign = "center"
if (v == 'Aux1' and isSerial) then
textAlign = "left"
end
 
-- Remove wikilinks from links in serial rowspans rows after the first.
-- if (currentRow > 1) then
-- args[v] = removeWikilinks(args, v)
-- end
 
local thisRowspan
if (firstParameterGroupCell and k < firstParameterGroupCell) then
thisRowspan = numberOfParameterGroups
else
thisRowspan = 1
end
 
if (currentRow == 1 or (currentRow > 1 and k >= (firstParameterGroupCell or 0))) then
createTableData(args[v], thisRowspan, textAlign)
end
nonNilParams = nonNilParams + 1
checkUsageOfDateTemplates(args, v, onInitialPage, title)
end
 
if (args[v] == "TBA") then
cellValueTBA = true
end
end
end
 
Line 361 ⟶ 330:
Line 1: <Title><RTitle> (with no space between)
Line 2: <AltTitle><RAltTitle> (with no space between) OR
Line 2: TranscriptionTransliteration: <TranslitTitle> (<Language>: <NativeTitle>)<RAltTitle> (with space between first two parameters)
 
If <Title> or <RTitle> are empty,
Line 408 ⟶ 377:
elseif (hasValue(args.TranslitTitle)) then
if (hasValue(args.NativeTitleLangCode)) then
titleString = titleString .. 'TranscriptionTransliteration: "' .. langModule._transl_xlit({args.NativeTitleLangCode, args.TranslitTitle, italic = 'no'}) .. '"'
else
titleString = titleString .. 'TranscriptionTransliteration: "' .. args.TranslitTitle .. '"'
end
end
Line 427 ⟶ 396:
if (hasValue(args.NativeTitleLangCode)) then
local languageCode = "Lang-" .. args.NativeTitleLangCode
titleString = titleString .. " (" .. langModule._lang_xx_inherit_langx({code = args.NativeTitleLangCode, text=args.NativeTitle}) .. ")"
else
titleString = titleString .. " (" .. args.NativeTitle .. ")"
Line 454 ⟶ 423:
Local function which is used to extract data
from the numbered title parameters (Title1, RTitle2, etc.), and then convert them to
use the non-numbered prameterparameter names (Title, RTitle).
 
The function returns two results:
Line 474 ⟶ 443:
 
return args, nextGroupValid
end
 
-- Local function which is used to process the multi title list.
local function processMultiTitleList(args, numberOfParameterGroups)
local nativeTitleLangCode = args.NativeTitleLangCode
local titleText = ""
local isCellPresent = false
local isFirstTitleGroup = true -- Making sure that the title cell is created at least once and isn't created again if other #N titles are empty.
 
for i = 1, numberOfParameterGroups do
local args, nextGroupValid = extractDataFromNumberedTitleArgs(args, i)
if (nextGroupValid) then
if (isFirstTitleGroup == false) then
titleText = titleText .. "<hr />"
end
 
local titleTextRow
titleTextRow = createTitleText(args)
titleText = titleText .. titleTextRow
isFirstTitleGroup = false
else
if (isFirstTitleGroup) then
titleText, isCellPresent = createTitleText(args)
end
 
-- Valid titles have to be in succession (#1, #2, #3 and not #1, #4 #5), so exit for loop if next group is empty.
return titleText, isCellPresent
end
end
 
return titleText
end
 
-- Local function which is used to create a Title cell.
local function createTitleCell(args, numberOfParameterGroups, multiTitleListEnabledcurrentRow, isSerial)
local titleText
local isCellPresent
 
if (multiTitleListEnabledisSerial and args.Title and currentRow > 1) then
return nil
titleText, isCellPresent = processMultiTitleList(args, numberOfParameterGroups)
end
else
if (args.Title_2) then
titleText, isCellPresent = createTitleText(args)
local args, nextGroupValid = extractDataFromNumberedTitleArgs(args, currentRow)
end
titleText, isCellPresent = createTitleText(args)
 
if (isCellPresent == false) then
Line 562 ⟶ 502:
 
nonNilParams = nonNilParams + 1
end
 
--[[
Local function which is used to create column cells.
 
EpisodeNumber, EpisodeNumber2 are created in different functions
as they require some various if checks.
 
See:
-- createEpisodeNumberCell()
-- createEpisodeNumberCellSecondary()
]]--
local function createCells(args, isSerial, currentRow, onInitialPage, title, numberOfParameterGroups)
for k, v in ipairs(cellNameList) do
if (v == 'ProdCode') then
if (currentRow == 1 or (currentRow > 1 and parameterGroupCells[v])) then
createProductionCodeCell(args, v, numberOfParameterGroups)
end
elseif (v == 'Title') then
if (currentRow == 1 or (currentRow > 1 and parameterGroupCells[v])) then
local isSerial = not args.Title_2 and true or false
createTitleCell(args, numberOfParameterGroups, currentRow, isSerial)
end
elseif excludeList[v] and args[excludeList[v]] then
-- Ignore this parameter set as multiple conflicting parameters were used
elseif (args[v] and (v ~= 'EpisodeNumber' and v ~= 'EpisodeNumber2')) then
-- Set empty cells to TBA/TBD
if (args[v] == '') then
createEmptyCell(args, v, false)
elseif (v == 'WrittenBy' and title.namespace == 0) then
if ((string.find(args[v], "''Story") ~= nil or string.find(args[v], "''Teleplay") ~= nil) and string.find(args[v], "8202") == nil) then
-- &#8202; is the hairspace added through {{StoryTeleplay}}
addTrackingCategory(trackingCategoryList["raw_unformatted_storyteleplay"])
end
end
 
-- If serial titles need to be centered and not left, then this should be removed.
local textAlign = "center"
-- if (v == 'Aux1' and isSerial) then
-- textAlign = "left"
-- end
 
local thisRowspan
if (not parameterGroupCells[v] and parameterGroupCellsAny) then
thisRowspan = numberOfParameterGroups
else
thisRowspan = 1
end
 
if (currentRow == 1 or (currentRow > 1 and parameterGroupCells[v])) then
createTableData(args[v], thisRowspan, textAlign)
end
nonNilParams = nonNilParams + 1
checkUsageOfDateTemplates(args, v, onInitialPage, title)
end
-- Usages of TBA via [[Template:TableTBA]] can be found with the "tv-tba" class.
if args[v] and (args[v] == "TBA" or string.find(args[v], "tv%-tba")) then
cellValueTBA = true
end
end
end
 
-- Local function which is used to create a table row header for either the
-- EpisodeNumber or EpisodeNumber2 column cells.
local function createTableRowEpisodeNumberHeader(episodeNumber, numberOfParameterGroups, episodeText, separateEpisodeNumbers)
local epID = string.match(episodeNumber, "^%w+")
row:tag('th')
:attr('scope', 'row')
:attr('rowspan', not separateEpisodeNumbers and numberOfParameterGroups or 1)
:attr('id', epID and 'ep' .. epID or '')
:css('text-align', 'center')
Line 629 ⟶ 630:
 
-- Local function which is used to create EpisodeNumber2 and EpisodeNumber3 cells.
local function _createEpisodeNumberCellSecondary(episodeValue, numberOfParameterGroups, separateEpisodeNumbers)
if (episodeValue) then
local episodeText = getEpisodeText(episodeValue)
 
if (nonNilParams == 0) then
createTableRowEpisodeNumberHeader(episodeValue, numberOfParameterGroups, episodeText, separateEpisodeNumbers)
else
createTableData(episodeText, not separateEpisodeNumbers and numberOfParameterGroups or 1, "center")
end
 
Line 645 ⟶ 646:
 
-- Local function which is used to create seconday episode number cells.
local function createEpisodeNumberCellSecondary(args, numberOfParameterGroups, separateEpisodeNumbers)
_createEpisodeNumberCellSecondary(args.EpisodeNumber2, numberOfParameterGroups, separateEpisodeNumbers)
_createEpisodeNumberCellSecondary(args.EpisodeNumber3, numberOfParameterGroups, separateEpisodeNumbers)
end
 
-- Local function which is used to create an EpisodeNumber cell.
local function createEpisodeNumberCell(args, numberOfParameterGroups, separateEpisodeNumbers)
if (args.EpisodeNumber) then
local episodeText = getEpisodeText(args.EpisodeNumber)
createTableRowEpisodeNumberHeader(args.EpisodeNumber, numberOfParameterGroups, episodeText, separateEpisodeNumbers)
nonNilParams = nonNilParams + 1
end
Line 662 ⟶ 663:
-- This is the standard function called.
local function createSingleRowCells(args, numberOfParameterGroups, multiTitleListEnabled, onInitialPage, title)
createEpisodeNumberCell(args, 1, false)
createEpisodeNumberCellSecondary(args, 1, false)
createTitleCell(args, numberOfParameterGroups, multiTitleListEnabled, false)
createCells(args, false, 1, onInitialPage, title, numberOfParameterGroups)
end
Line 670:
-- Local function which is used to create a multiple row of cells.
-- This function is called when part of the row is rowspaned.
-- Current use is for Doctor Who serials.
local function createMultiRowCells(args, numberOfParameterGroups, onInitialPage, title, topColor)
local EpisodeNumberSplit = (args.EpisodeNumber_1 and true or false)
createEpisodeNumberCell(args, numberOfParameterGroups)
createEpisodeNumberCellSecondary(args, numberOfParameterGroups)
createTitleCell(args, numberOfParameterGroups, false, true)
 
for i = 1, numberOfParameterGroups do
args = extractDataFromNumberedSerialArgs(args, i, numberOfParameterGroups, title)
if (EpisodeNumberSplit or (not EpisodeNumberSplit and i == 1)) then
createEpisodeNumberCell(args, numberOfParameterGroups, EpisodeNumberSplit)
createEpisodeNumberCellSecondary(args, numberOfParameterGroups, EpisodeNumberSplit)
end
createCells(args, true, i, onInitialPage, title, numberOfParameterGroups)
if (i ~= numberOfParameterGroups) then
local textColor = '#333'
if topColor == 'inherit' then
textColor = 'inherit'
end
row = row:done() -- Use done() to close the 'tr' tag in rowspaned rows.
:tag('tr')
:addClass('vevent')
:addClass('module-episode-list-row')
:css('text-align', 'center')
:css('background', topColor)
:css('color', textColor)
end
end
Line 693 ⟶ 705:
if (args[numberedParameter]) then
parameterGroupCells[v] = true
parameterGroupCellsAny = true
if not firstParameterGroupCell then
firstParameterGroupCell = k
Line 715 ⟶ 728:
return '#' .. args.TopColor
end
elseif (rowColorEnabled and onInitialPage and mathModule._mod(episodeNumber, 2) == 0) then
return '#E9E9E9'
elseif (onInitialPage and args.ShortSummary) then
return '#F2F2F2'
else
return 'inherit'
Line 758 ⟶ 767:
-- with one of them not requiring an article name, so for backward compatability, the whole sequence is kept.
local onInitialPage
local onInitialPageCheck = (mw.uri.anchorEncode(pageTitle) == mw.uri.anchorEncode(initiallistTitle))
 
-- Only sublist had anything about hiding, so only it needs to even check
if (sublist) then
onInitialPage = mw.uri.anchorEncode(pageTitle) == mw.uri.anchorEncode(initiallistTitle)onInitialPageCheck
-- avoid processing ghost references
if (not onInitialPage) then
Line 770 ⟶ 780:
onInitialPage = true
else
onInitialPage = mw.uri.anchorEncode(pageTitle) == mw.uri.anchorEncode(initiallistTitle)onInitialPageCheck
end
end
Line 796 ⟶ 806:
 
local root = mw.html.create() -- Create the root mw.html object to return
local textColor = '#333'
if topColor == 'inherit' then
textColor = 'inherit'
end
 
row = root:tag('tr') -- Create the table row and store it globally
:addClass('vevent')
:addClass('module-episode-list-row')
:css('text-align', 'center')
:css('background', topColor)
:css('color', textColor)
 
local numberOfParameterGroups, multiTitleListEnabled = getnumberOfParameterGroups(args)
 
if (multiTitleListEnabled and not args.Title_2) then
createMultiRowCells(args, numberOfParameterGroups, onInitialPage, title, topColor)
else