Content deleted Content added
Restoring fixes changes. See Module talk:Episode list#Sandbox version update for more info |
Comment out per talk page |
||
(80 intermediate revisions by 15 users not shown) | |||
Line 4:
local colorContrastModule = require('Module:Color contrast')
local htmlColor = mw.loadData('Module:Color contrast/colors')
local
local mathModule = require('Module:Math')
local tableEmptyCellModule = require('Module:Table empty cell')
Line 18 ⟶ 17:
-- Variable that will keep track if a TBA value was entered.
local cellValueTBA = false
-- Variable that handles the assigned tracking categories.
local trackingCategories = ""
Line 27 ⟶ 26:
["alt_air_dates"] = "[[Category:Episode lists with incorrectly formatted alternate air dates]]",
["faulty_line_colors"] = "[[Category:Episode lists with faulty line colors]]",
["
["default_line_colors"] = "[[Category:Episode list using the default LineColor]]",
["row_deviations"] = "[[Category:Episode lists with row deviations]]",
["invalid_top_colors"] = "[[Category:Episode lists with invalid top colors]]",
["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 43 ⟶ 47:
'OriginalAirDate',
'AltDate',
'Guests',
'MusicalGuests',
'ProdCode',
'Viewers',
'Aux4'
}
-- List of pairs which cannot be used together
local excludeList = {
['Guests'] = 'Aux1',
['MusicalGuests'] = 'Aux2'
}
-- List of cells that have parameter groups
local parameterGroupCells = {}
local firstParameterGroupCell
local parameterGroupCellsAny = false
-- List of title parameter names in this order.
Line 57 ⟶ 74:
'NativeTitle',
'TranslitTitle',
}
Line 72 ⟶ 80:
local function idTrim(val, search)
local valFind = string.find(val, search)
if (valFind == nil) then
return val
Line 111 ⟶ 119:
-- fix for lists in the Short Summary
local shortSummaryText = args.ShortSummary
if (shortSummaryText:match('^[*:;#]') or shortSummaryText:match('^{|')) then
shortSummaryText = '<span></span>\n' .. shortSummaryText
Line 119 ⟶ 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 125 ⟶ 141:
:attr('colspan', nonNilParams)
:newline()
:
return mw.html.create('tr')
Line 131 ⟶ 147:
:node(shortSummaryCell)
end
-- Local function which is used to add tracking categories for Top Color issues.
Line 143 ⟶ 160:
local linkContrastRatio = colorContrastModule._ratio{args.TopColor, '#0B0080', ['error'] = 0}
local visitedLinkContrastRatio = colorContrastModule._ratio{args.TopColor, '#0645AD', ['error'] = 0}
if (textContrastRatio < 7 or linkContrastRatio < 7 or visitedLinkContrastRatio < 7) then
addTrackingCategory(trackingCategoryList["invalid_top_colors"])
Line 155 ⟶ 172:
local blackContrastRatio = colorContrastModule._ratio{args.LineColor, 'black', ['error'] = 0}
local whiteContrastRatio = colorContrastModule._ratio{'white', args.LineColor, ['error'] = 0}
if (colorContrastModule._lum(args.LineColor) == '') then
addTrackingCategory(trackingCategoryList["faulty_line_colors"])
elseif (blackContrastRatio < 7 and whiteContrastRatio < 7) then
addTrackingCategory(trackingCategoryList["
end
else
addTrackingCategory(trackingCategoryList["default_line_colors"])
end
end
Line 175 ⟶ 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(" ", " "):match("(%a+) (%d+), (%d+)")
if (month == nil) then
day, month, year = args.OriginalAirDate:gsub(" ", " "):match("(%d+) (%a+) (%d+)")
end
if (day == nil) then
return tableEmptyCellModule._main({alt_text = "TBD"})
Line 200 ⟶ 220:
['December'] = 12
}
if not monthList[month] then
error('Invalid month ' .. month)
end
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 *
return tableEmptyCellModule._main({alt_text =
else
return tableEmptyCellModule._main({alt_text =
end
end
Line 212 ⟶ 236:
-- Local function which is used to create an empty cell.
local function createEmptyCell(args, v, unsetParameterGroup)
if (unsetParameterGroup) then
args[v] =
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 222 ⟶ 250:
-- Air dates that don't use {{Start date}}
local function checkUsageOfDateTemplates(args, v, onInitialPage, title)
if
and args[v] ~= ''
and string.match(args[v], '%d%d%d%d')
and string.match(args[v], '2C2C2C') == nil -- Avoids this specific pattern
and not string.
and string.find(args[v], 'itvstart') == nil -- Avoids a {{Start date}} unique class
and
and title.namespace == 0
then
addTrackingCategory(trackingCategoryList["air_dates"])
end
-- Alternate air dates that do use {{Start date}}
if (v == 'AltDate' and args[v] ~= '' and string.find(args[v], 'dtstart') ~= nil and onInitialPage and title.namespace == 0) then
Line 240 ⟶ 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,
else
-- ProductionCode parameter not used; Do nothing.
end
nonNilParams = nonNilParams + 1
end
Line 259 ⟶ 296:
Local function which is used to extract data
from the numbered serial parameters (Title1, Aux1, etc.), and then convert them to
use the non-numbered
The function returns the args as non-numbered
]]--
local function extractDataFromNumberedSerialArgs(args, i, numberOfParameterGroups, title)
for _, v in ipairs(
local parameter = v
local numberedParameter = v .. "_" .. i
local excludeParameter = excludeList[parameter] or 'NULL' .. parameter
local excludeNumberParameter = (excludeList[numberedParameter] or 'NULL' .. parameter) .. "_" .. i
if (not hasValue(args[numberedParameter]) and not hasValue(args[excludeNumberParameter])
and hasValue(parameterGroupCells[parameter]) and not hasValue(args[excludeParameter])) then
if (v ~= 'ProdCode') then
createEmptyCell(args, parameter, true)
else
args[parameter] = ''
end
if (title.namespace == 0) then
addTrackingCategory(trackingCategoryList["nonmatching_numbered_parameters"])
end
elseif (hasValue(args[numberedParameter]) and not hasValue(args[excludeNumberParameter])) then
args[parameter] = args[numberedParameter]
end
end
return args
end
Line 322 ⟶ 330:
Line 1: <Title><RTitle> (with no space between)
Line 2: <AltTitle><RAltTitle> (with no space between) OR
Line 2:
If <Title> or <RTitle> are empty,
then the values of line 2 will be placed on line 1 instead.
Line 357 ⟶ 365:
-- Surround the AltTitle/TranslitTitle with quotes; No quotes if empty.
if (args.AltTitle or args.TranslitTitle) then
isCellPresent = true
if (useSecondLine) then
titleString = titleString .. "<br />"
lineBreakUsed = true
end
if (hasValue(args.AltTitle)) then
titleString = titleString .. '"' .. args.AltTitle .. '"'
elseif (hasValue(args.TranslitTitle)) then
if (hasValue(args.NativeTitleLangCode)) then
titleString = titleString .. '
else
titleString = titleString .. '
end
end
Line 388 ⟶ 396:
if (hasValue(args.NativeTitleLangCode)) then
local languageCode = "Lang-" .. args.NativeTitleLangCode
titleString = titleString .. " (" .. langModule.
else
titleString = titleString .. " (" .. args.NativeTitle .. ")"
Line 400 ⟶ 408:
else
isCellPresent = true
if (useSecondLine and lineBreakUsed == false) then
titleString = titleString .. "<br />"
end
titleString = titleString .. args.RAltTitle
end
Line 415 ⟶ 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
The function returns two results:
Line 423 ⟶ 431:
local function extractDataFromNumberedTitleArgs(args, i)
local nextGroupValid = false
for _, v in ipairs(titleList) do
local parameter = v
local numberedParameter = v .. "_" .. i
args[parameter] = args[numberedParameter]
if (nextGroupValid == false and hasValue(args[numberedParameter])) then
nextGroupValid = true
end
end
return args, nextGroupValid
end
-- Local function which is used to create a Title cell.
local function createTitleCell(args,
local titleText
local isCellPresent
if (
return nil
end
if (args.Title_2) then
local args, nextGroupValid = extractDataFromNumberedTitleArgs(args, currentRow)
end
titleText, isCellPresent = createTitleText(args)
if (isCellPresent == false) then
Line 488 ⟶ 467:
if (hasValue(titleText) == false) then
titleText = tableEmptyCellModule._main({})
textAlign = "
end
-- If title is the first cell, create it with a !scope="row"
if (nonNilParams == 0) then
if (isSerial) then
row:tag('th')
:
:
:attr('rowspan', numberOfParameterGroups)
:css('text-align', textAlign)
:wikitext(titleText)
else
row:tag('th')
:addClass('summary')
:attr('scope', 'row')
:css('text-align', textAlign)
:wikitext(titleText)
end
else
if (isSerial) then
row:
:
:attr('rowspan', numberOfParameterGroups)
:css('text-align', textAlign)
:wikitext(titleText)
else
row:tag('td')
:addClass('summary')
:css('text-align', textAlign)
:wikitext(titleText)
end
end
Line 513 ⟶ 504:
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
--   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
local epID = string.match(episodeNumber, "^%w+")
row:tag('th')
:attr('scope', 'row')
:attr('rowspan',
:attr('id', epID and 'ep' ..
:css('text-align', 'center')
:wikitext(episodeText)
Line 543 ⟶ 596:
return tableEmptyCellModule._main({})
else
local episodeNumber1
local episodeNumber2
-- Used for double episodes that need a visual "–"" or "<hr />"" added.
local divider
Line 555 ⟶ 608:
episodeNumber1, episodeNumber2 = episodeNumber:match('^(%w+)%s*<hr */%s*>%s*(%w+)$')
divider = "<hr />"
elseif (episodeNumber:match('^(%w+)%s*<hr */%s*>.-<hr */%s*>%s*(%w+)$')) then
episodeNumber1, episodeNumber2 = episodeNumber:match('^(%w+)%s*<hr */%s*>.-<hr */%s*>%s*(%w+)$')
divider = "<hr />"
elseif (mw.ustring.match(episodeNumber, '^(%w+)%s*[%s%-–
episodeNumber1, episodeNumber2 = mw.ustring.match(episodeNumber, '^(%w+)%s*[%s%-–
divider = "–"
else
episodeNumber1, episodeNumber2 = mw.ustring.match(episodeNumber, '^(%w+)%s*[%s%-–
divider = "–"
end
if (not
return episodeNumber
elseif (not episodeNumber2) then
return string.match(episodeNumber, '%w+')
else
Line 574 ⟶ 629:
end
-- Local function which is used to create
local function _createEpisodeNumberCellSecondary(episodeValue, numberOfParameterGroups, separateEpisodeNumbers)
if (
local episodeText = getEpisodeText(
if (nonNilParams == 0) then
createTableRowEpisodeNumberHeader(
else
createTableData(episodeText,
end
nonNilParams = nonNilParams + 1
end
end
-- 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,
if (args.EpisodeNumber) then
local episodeText = getEpisodeText(args.EpisodeNumber)
createTableRowEpisodeNumberHeader(args.EpisodeNumber,
nonNilParams = nonNilParams + 1
end
end
-- Local function which is used to create a single row of cells.
-- This is the standard function called.
local function createSingleRowCells(args,
createEpisodeNumberCell(args, 1, false)
createCells(args, false, 1, onInitialPage, title, numberOfParameterGroups)
end
-- Local function which is used to create a multiple row of cells.
-- This function is called when part of the row is rowspaned.
local function createMultiRowCells(args, numberOfParameterGroups, onInitialPage, title, topColor)
local EpisodeNumberSplit = (args.EpisodeNumber_1 and true or false)
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 628 ⟶ 700:
-- Local function which is used to retrieve the NumParts value.
local function
for k, v in ipairs(cellNameList) do
local numberedParameter = v .. "_" .. 1
if (args[numberedParameter]) then
parameterGroupCells[v] = true
parameterGroupCellsAny = true
if not firstParameterGroupCell then
firstParameterGroupCell = k
end
end
end
if (hasValue(args.NumParts)) then
return args.NumParts, true
Line 645 ⟶ 728:
return '#' .. args.TopColor
end
else
return 'inherit'
Line 661 ⟶ 740:
rowColorEnabled = true
end
return rowColorEnabled
end
Line 669 ⟶ 748:
-- Default color to light blue
local lineColor = args.LineColor or 'CCCCFF'
-- Add # to color if necessary, and set to default color if invalid
if (htmlColor[lineColor] == nil) then
Line 677 ⟶ 756:
end
end
return lineColor
end
Line 688 ⟶ 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 =
-- avoid processing ghost references
if (not onInitialPage) then
Line 700 ⟶ 780:
onInitialPage = true
else
onInitialPage =
end
end
return onInitialPage
end
Line 712 ⟶ 792:
local pageTitle = title.text
local initiallistTitle = args['1'] or ''
-- Is this list on the same page as the page directly calling the template?
local onInitialPage = isOnInitialPage(args, sublist, pageTitle, initiallistTitle)
Line 726 ⟶ 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
if (
createMultiRowCells(args,
else
createSingleRowCells(args,
end
Line 744 ⟶ 831:
addTopColorTrackingCategories(args)
end
if (cellValueTBA == true and title.namespace == 0) then
addTrackingCategory(trackingCategoryList["tba_values"])
Line 761 ⟶ 848:
-- Local function which handles both module entry points.
local function main(frame, sublist)
local getArgs = require('Module:Arguments').getArgs
local args
Line 804 ⟶ 891:
-- |OriginalAirDate= — optional; This is the date the episode first aired on TV, or is scheduled to air.
-- |AltDate= — optional; The next notable air date, such as the first air date of an anime in English.
-- |Guests= — optional; List of Guests for talk shows. Cannot be used simultaneously with Aux1.
-- |MusicalGuests= — optional; List of MusicalGuests for talk shows. Cannot be used simultaneously with Aux2.
-- |ProdCode= — optional; The production code in the series. When defined, this parameter also creates a link anchor,
prefixed by "pc"; for example, List of episodes#pc01.
Line 809 ⟶ 898:
-- |Aux4= — optional; General purpose parameter. The meaning is specified by the column header.
-- |ShortSummary= — optional; A short 100–200 word plot summary of the episode.
-- |LineColor= — optional; Colors the separator line between episode entries. If not defined the color defaults to "#CCCCFF"
and the article is placed in Category:Episode list using the default LineColor.
Use of "#", or anything but a valid hex code will result in an invalid syntax.
-- |TopColor= — discouraged; Colors the main row of information (that is, not the ShortSummary row).
Articles using this parameter are placed in Category:Episode lists with row deviations.
-- |RowColor= — optional; Switch parameter that must only be defined when the EpisodeNumber= entry is not a regular number
(e.g. "12–13" for two episodes described in one table entry).
If the first episode number is even, define pass "on". If the first episode number is odd, pass "off".
--]]
|