وحدة:Episode list
| صفحة وحدة لوا متضمنة في عدة صفحات ويمكن ملاحظتها على نطاق واسع. أختبر تغييرات الوحدة في /الملعب أو /المختبر أو صفحات فرعية، أو عبر ملعب الوحدة. فكر في مناقشة التغييرات في صفحة نقاش قبل تنفيذها. |
| صُنّفت هذه الوحدة على أنها في المرحلة النهائية. في هذه المرحلة تكون الوحدة وصلت لنقطة يمكن أن تستخدم في أي صفحة أو أي نطاق. كما أنها تؤدي الهدف الذي بنيت من أجله ولا توجد أي أخطاء بها. يمكن أن يشار إلى هذه الوحدة في صفحات المساعدة أو أي صفحات إرشادية على ويكيبيديا، كما يمكن أن توضع كأمثلة للجدد ليتعلموا منها. |
| صُنّفت هذه الوحدة على أنها محمية. تصل الوحدة لهذه المرحلة عندما تستخدم في صفحات كثيرة جدًا. فيجب أن تحمى بسبب أن عمليات التخريب أو الأخطاء تطال الكثير من الصفحات. كما هناك تعديلات غير مجدية تتم على هذه الوحدات تسبب تعب للخادم، إذا كنت ترى أن تعدل هذه الوحدة طبق تعديلك على الملعب أولا وبعد اختباره استدعِ أحدًا لديه صلاحية التعديل لتطبيقه . |
| هذه الوحدة تعتمد على الوحدات الأخرى التالية: |
وحدة:Episode list تُنشئ صفًا في جدول، يُستخدم في قوائم جداول الحلقات، وخاصةً في البرامج والمسلسلات التلفزيونية. يمكن استخدام هذه الوحدة مع وحدة:Episode table، التي تُنشئ جدولًا متناسقًا ومتوافقًا مع دليل الأسلوب، أو مع جدول مُنشأ يدويًا. راجع قالب:قائمة حلقات لمزيد من الشرح والتوثيق.
الاستخدام
[عدل]لإنشاء قائمة حلقات قياسية إستخدم:
{{#استدعاء:Episode list|list}}
لإنشاء قائمة فرعية تزيل ملخصات الحلقات من الصفحة المضمنة إستخدم:
{{#استدعاء:Episode list|sublist}}
تصنيفات التتبع
[عدل]- تصنيف:قالب قائمة حلقات مع ألوان افتراضية (102 صفحة)
- تصنيف:قالب قائمة حلقات تحوي مجموعة غير متطابقة من الوسائط المرقمة (1 صفحة)
- تصنيف:قالب قائمة حلقات مع ألوان خاطئة (1 صفحة)
- تصنيف:قالب قائمة حلقات مع تواريخ عرض بديلة غير منسقة (1 صفحة)
- تصنيف:قالب قائمة حلقات مع ألوان علوية غير صالحة (0 صفحة)
- تصنيف:قالب قائمة حلقات مع ألوان غير متوافقة (26 صفحة)
- تصنيف:قالب قائمة حلقات مع صفوف منحرفة (0 صفحة)
- تصنيف:قالب قائمة حلقات مع قيم تعلن لاحقا (2 صفحة)
- تصنيف:قالب قائمة حلقات مع تواريخ عرض غير منسقة (70 صفحة)
- تصنيف:قالب قائمة حلقات مع قصة أو اعتمادات تلفزيونية غير منسقة (3 صفحة)
local p = {}
-- This module requires the use of the following modules:
local aliases = require('Module:Episode list/labels')
local colorContrastModule = require('Module:Color contrast')
local htmlColor = mw.loadData('Module:Color contrast/colors')
local langModule = require("Module:Lang")
local mathModule = require('Module:Math')
local tableEmptyCellModule = require('Module:Table empty cell')
local yesNoModule = require('Module:Yesno')
-- mw.html object for the generated row.
local row
-- Variable that will decide the colspan= of the Short Summary cell.
local nonNilParams = 0
-- Variable that will keep track if a TBA value was entered.
local cellValueTBA = false
-- Variable that handles the assigned tracking categories.
local trackingCategories = ""
-- List of tracking categories.
local trackingCategoryList = {
["air_dates"] = "[[تصنيف:قالب قائمة حلقات مع تواريخ عرض غير منسقة]]",
["alt_air_dates"] = "[[تصنيف:قالب قائمة حلقات مع تواريخ عرض بديلة غير منسقة]]",
["faulty_line_colors"] = "[[تصنيف:قالب قائمة حلقات مع ألوان خاطئة]]",
["non_compliant_line_colors"] = "[[تصنيف:قالب قائمة حلقات مع ألوان غير متوافقة]]",
["default_line_colors"] = "[[تصنيف:قالب قائمة حلقات مع ألوان افتراضية]]",
["row_deviations"] = "[[تصنيف:قالب قائمة حلقات مع صفوف منحرفة]]",
["invalid_top_colors"] = "[[تصنيف:قالب قائمة حلقات مع ألوان علوية غير صالحة]]",
["tba_values"] = "[[تصنيف:قالب قائمة حلقات مع قيم تعلن لاحقا]]",
["nonmatching_numbered_parameters"] = "[[تصنيف:قالب قائمة حلقات تحوي مجموعة غير متطابقة من الوسائط المرقمة]]",
["raw_unformatted_storyteleplay"] = "[[تصنيف:قالب قائمة حلقات مع قصة أو اعتمادات تلفزيونية غير منسقة]]",
}
-- List of parameter names in this order.
local cellNameList = {
'EpisodeNumber',
'EpisodeNumber2',
'Title',
'Aux1',
'DirectedBy',
'WrittenBy',
'Aux2',
'Aux3',
'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.
-- List used for multi title lists.
local titleList = {
'Title',
'RTitle',
'AltTitle',
'RAltTitle',
'NativeTitle',
'TranslitTitle',
}
-- Local function which is used to retrieve the episode number or production code number,
-- without any additional text.
local function idTrim(val, search)
local valFind = string.find(val, search, 1, true)
if (valFind == nil) then
return val
else
return string.sub(val, 0, valFind-1)
end
end
-- Local function which is used to validate that a parameter has an actual value.
local function hasValue(param)
if (param ~= nil and param ~= "") then
return true
else
return false
end
end
-- Local function which is used to create a table data cell.
local function createTableData(text, rowSpan, textAlign)
if (rowSpan ~= nil and tonumber(rowSpan) > 1) then
row:tag('td')
:attr('rowspan', rowSpan)
:wikitext(text)
else
row:tag('td')
:css('text-align', textAlign)
:wikitext(text)
end
end
-- Local function which is used to add a tracking category to the page.
local function addTrackingCategory(category)
trackingCategories = trackingCategories .. category
end
-- Local function which is used to create a Short Summary row.
local function createShortSummaryRow(args, lineColor)
-- fix for lists in the Short Summary
local shortSummaryText = args.ShortSummary
if (shortSummaryText:match('^[*:;#]') or shortSummaryText:match('^{|')) then
shortSummaryText = '<span></span>\n' .. shortSummaryText
end
if (shortSummaryText:match('\n[*:;#]')) then
shortSummaryText = shortSummaryText .. '\n<span></span>'
end
local shortSummaryDiv = mw.html.create('div')
:addClass('shortSummaryText')
:css('max-width', '90vw')
:css('position', 'sticky')
:css('right', '0.2em')
:newline()
:wikitext(shortSummaryText)
local shortSummaryCell = mw.html.create('td')
:addClass('description')
:css('border-bottom', 'solid 3px ' .. lineColor)
:attr('colspan', nonNilParams)
:newline()
:node(shortSummaryDiv)
return mw.html.create('tr')
:addClass('expand-child')
:node(shortSummaryCell)
end
-- Local function which is used to add tracking categories for Top Color issues.
local function addTopColorTrackingCategories(args)
if (hasValue(args.TopColor)) then
addTrackingCategory(trackingCategoryList["row_deviations"])
-- Track top colors that have a color contrast rating below AAA with
-- respect to text color, link color, or visited link color. See
-- [[WP:COLOR]] for more about color contrast requirements.
local textContrastRatio = colorContrastModule._ratio{args.TopColor, 'black', ['error'] = 0}
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"])
end
end
end
-- Local function which is used to add tracking categories for Line Color issues.
local function addLineColorTrackingCategories(args)
if (hasValue(args.LineColor)) then
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["non_compliant_line_colors"])
end
else
addTrackingCategory(trackingCategoryList["default_line_colors"])
end
end
-- Local function which is used to set the text of an empty cell
-- 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, '^لم تعرض') then
return tableEmptyCellModule._main({alt_text = "غ/م"})
end
local month, day, year = args.OriginalAirDate:gsub(" ", " "):match("(%S+) (%d+), (%d+)")
if (month == nil) then
day, month, year = args.OriginalAirDate:gsub(" ", " "):match("(%d+) (%S+) (%d+)")
end
if (day == nil) then
return tableEmptyCellModule._main({alt_text = "سيُحدد"})
else
-- List of months.
local monthList = {
['يناير'] = 1,
['فبراير'] = 2,
['مارس'] = 3,
['أبريل'] = 4,
['مايو'] = 5,
['يونيو'] = 6,
['يوليو'] = 7,
['أغسطس'] = 8,
['سبتمبر'] = 9,
['أكتوبر'] = 10,
['نوفمبر'] = 11,
['ديسمبر'] = 12
}
if not monthList[month] then
error('الشهر "' .. 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 * weeks) then
return tableEmptyCellModule._main({alt_text = expiredText})
else
return tableEmptyCellModule._main({alt_text = awaitingText})
end
end
end
-- Local function which is used to create an empty cell.
local function createEmptyCell(args, v, unsetParameterGroup)
if (unsetParameterGroup) then
args[v] = tableEmptyCellModule._main({alt_text = "غ/م"})
elseif (v == 'Viewers' and hasValue(args.OriginalAirDate)) then
args[v] = setTBDStatus(args, "سيُحدد", "غ/م", 4)
elseif (v == 'DirectedBy' or v == 'WrittenBy') then
args[v] = setTBDStatus(args, "سيُعلن", "مجهول", 4)
else
args[v] = tableEmptyCellModule._main({})
end
end
-- 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') -- Ensure it contains a four-digit number (likely a year)
and string.match(args[v], '2C2C2C') == nil -- Avoids this specific pattern
and not string.match(args[v], '^لم تعرض') -- Exclude anything starting with "Unaired"
and string.find(args[v], 'dtstart') == nil -- Avoids a {{Start date}} unique class
and onInitialPage
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
addTrackingCategory(trackingCategoryList["alt_air_dates"])
end
end
-- 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, 'سيُعلن') == 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 '', 'سيُعلن') ~= nil) then
createEmptyCell(args, v, false)
createTableData(args.ProdCode, thisRowspan, "center")
else
-- ProductionCode parameter not used; Do nothing.
end
nonNilParams = nonNilParams + 1
end
--[[
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 parameter names (Title, Aux).
The function returns the args as non-numbered parameter names.
]]--
local function extractDataFromNumberedSerialArgs(args, i, numberOfParameterGroups, title)
for _, v in ipairs(cellNameList) do
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
--[[
Local function which is used to create the Title cell text.
The title text will be handled in the following way:
Line 1: <Title><RTitle> (with no space between)
Line 2: <AltTitle><RAltTitle> (with no space between) OR
Line 2: Transliteration: <TranslitTitle> (<Language>: <NativeTitle>)<RAltTitle> (with space between first two parameters)
If <Title> or <RTitle> are empty,
then the values of line 2 will be placed on line 1 instead.
--]]
local function createTitleText(args)
local titleString = ''
local isCellPresent = false
local useSecondLine = false
local lineBreakUsed = false
-- Surround the Title with quotes; No quotes if empty.
if (args.Title ~= nil) then
if (args.Title == "") then
isCellPresent = true
else
titleString = '«' .. args.Title .. '»'
useSecondLine = true
isCellPresent = true
end
end
if (args.RTitle ~= nil) then
if (args.RTitle == "") then
isCellPresent = true
else
titleString = titleString .. args.RTitle
useSecondLine = true
isCellPresent = true
end
end
-- 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 .. 'النقحرة: "' .. langModule._xlit({args.NativeTitleLangCode, args.TranslitTitle, italic = 'no'}) .. '"'
else
titleString = titleString .. 'النقحرة: "' .. args.TranslitTitle .. '"'
end
end
end
if (args.NativeTitle ~= nil) then
if (args.NativeTitle == "") then
isCellPresent = true
else
isCellPresent = true
if (useSecondLine and lineBreakUsed == false) then
titleString = titleString .. "<br />"
end
if (hasValue(args.NativeTitleLangCode)) then
local languageCode = "Lang-" .. args.NativeTitleLangCode
titleString = titleString .. " (" .. langModule._langx({code = args.NativeTitleLangCode, text=args.NativeTitle}) .. ")"
else
titleString = titleString .. " (" .. args.NativeTitle .. ")"
end
end
end
if (args.RAltTitle ~= nil) then
if (args.RAltTitle == "") then
isCellPresent = true
else
isCellPresent = true
if (useSecondLine and lineBreakUsed == false) then
titleString = titleString .. "<br />"
end
titleString = titleString .. args.RAltTitle
end
end
return titleString, isCellPresent
end
--[[
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 parameter names (Title, RTitle).
The function returns two results:
-- The args parameter table.
-- A boolean indicating if the title group has data.
]]--
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, numberOfParameterGroups, currentRow, isSerial)
local titleText
local isCellPresent
if (isSerial and args.Title and currentRow > 1) then
return nil
end
if (args.Title_2) then
local args, nextGroupValid = extractDataFromNumberedTitleArgs(args, currentRow)
end
titleText, isCellPresent = createTitleText(args)
if (isCellPresent == false) then
return nil
end
local textAlign = "right"
-- If Title is blank, then set Raw Title to TBA
if (hasValue(titleText) == false) then
titleText = tableEmptyCellModule._main({})
textAlign = "right"
end
-- If title is the first cell, create it with a !scope="row"
if (nonNilParams == 0) then
if (isSerial) then
row:tag('th')
:addClass('summary')
:attr('scope', 'row')
: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:tag('td')
:addClass('summary')
:attr('rowspan', numberOfParameterGroups)
:css('text-align', textAlign)
:wikitext(titleText)
else
row:tag('td')
:addClass('summary')
:css('text-align', textAlign)
:wikitext(titleText)
end
end
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
--   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 = "right"
-- 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] == "سيُعلن" 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')
:css('font-weight', 'normal')
:wikitext(episodeText)
end
--[[
Local function which is used to extract the text from the EpisodeNumber or EpisodeNumber2
parameters and format them into a correct MoS compliant version.
Styles supported:
-- A number range of two numbers, indicating the start and end of the range,
seperated by an en-dash (–) with no spaces in between.
Example: "1 - 2" -> "1–2"; "1-2-3" -> "1–3".
-- An alphanumeric or letter range, similar to the above.
Example: "A - B" -> "A–B"; "A-B-C" -> "A–C".
Example: "A1 - B1" -> "A1–B1"; "A1-B1-C1" -> "A1–C1".
-- A number range of two numbers, indicating the start and end of the range,
seperated by a visual <hr /> (divider line).
-- An alphanumeric or letter range, similar to the above.
]]--
local function getEpisodeText(episodeNumber)
if (episodeNumber == '') then
return tableEmptyCellModule._main({})
else
local episodeNumber1
local episodeNumber2
-- Used for double episodes that need a visual "–"" or "<hr />"" added.
local divider
episodeNumber = episodeNumber:gsub('%s*<br%s*/?%s*>%s*', '<hr />')
if (episodeNumber:match('^(%w+)%s*<hr */%s*>%s*(%w+)$')) then
episodeNumber1, episodeNumber2 = episodeNumber:match('^(%w+)%s*<hr */%s*>%s*(%w+)$')
divider = "<hr />"
elseif (episodeNumber:match('^(%w+)%s*<hr */%s*>.-<hr */%s*>%s*(%w+)$')) then -- 3 or more elements
episodeNumber1, episodeNumber2 = episodeNumber:match('^(%w+)%s*<hr */%s*>.-<hr */%s*>%s*(%w+)$')
divider = "<hr />"
elseif (mw.ustring.match(episodeNumber, '^(%w+)%s*[%s%-–/&]%s*(%w+)$')) then
episodeNumber1, episodeNumber2 = mw.ustring.match(episodeNumber, '^(%w+)%s*[%s%-–/&]%s*(%w+)$')
divider = "–"
else
episodeNumber1, episodeNumber2 = mw.ustring.match(episodeNumber, '^(%w+)%s*[%s%-–/&].-[%s%-–/&]%s*(%w+)$') -- 3 or more elements
divider = "–"
end
if (not episodeNumber1) then
return episodeNumber
elseif (not episodeNumber2) then
return string.match(episodeNumber, '%w+')
else
return episodeNumber1 .. divider .. episodeNumber2
end
end
end
-- 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
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, numberOfParameterGroups, separateEpisodeNumbers)
if (args.EpisodeNumber) then
local episodeText = getEpisodeText(args.EpisodeNumber)
createTableRowEpisodeNumberHeader(args.EpisodeNumber, numberOfParameterGroups, episodeText, separateEpisodeNumbers)
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, numberOfParameterGroups, multiTitleListEnabled, onInitialPage, title)
createEpisodeNumberCell(args, 1, false)
createEpisodeNumberCellSecondary(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
end
-- Local function which is used to retrieve the NumParts value.
local function getnumberOfParameterGroups(args)
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
else
return 1, false
end
end
-- Local function which is used to retrieve the Top Color value.
local function getTopColor(args, rowColorEnabled, onInitialPage)
local episodeNumber = mathModule._cleanNumber(args.EpisodeNumber) or 1
if (args.TopColor) then
if (string.find(args.TopColor, "#")) then
return args.TopColor
else
return '#' .. args.TopColor
end
else
return 'inherit'
end
end
-- Local function which is used to retrieve the Row Color value.
local function isRowColorEnabled(args)
local rowColorEnabled = yesNoModule(args.RowColor, false)
if (args.RowColor and string.lower(args.RowColor) == 'on') then
rowColorEnabled = true
end
return rowColorEnabled
end
-- Local function which is used to retrieve the Line Color value.
local function getLineColor(args)
-- 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
lineColor = '#' .. (mw.ustring.match(lineColor, '^[%s#]*([a-fA-F0-9]*)[%s]*$') or '')
if (lineColor == '#') then
lineColor = '#CCCCFF'
end
end
return lineColor
end
-- Local function which is used to check if the table is located on the page
-- currently viewed, or on a transcluded page instead.
-- If it is on a transcluded page, the episode summary should not be shown.
local function isOnInitialPage(args, sublist, pageTitle, initiallistTitle)
-- This should be the only check needed, however, it was previously implemented with two templates
-- 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 = onInitialPageCheck
-- avoid processing ghost references
if (not onInitialPage) then
args.ShortSummary = nil
end
else
if (initiallistTitle == "") then
onInitialPage = true
else
onInitialPage = onInitialPageCheck
end
end
return onInitialPage
end
-- Local function which does the actual main process.
local function _main(args, sublist)
local title = mw.title.getCurrentTitle()
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)
-- Need just this parameter removed if blank, no others
if (hasValue(args.ShortSummary) == false) then
args.ShortSummary = nil
end
local lineColor = getLineColor(args)
local rowColorEnabled = isRowColorEnabled(args)
local topColor = getTopColor(args, rowColorEnabled, onInitialPage)
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) then
createMultiRowCells(args, numberOfParameterGroups, onInitialPage, title, topColor)
else
createSingleRowCells(args, numberOfParameterGroups, multiTitleListEnabled, onInitialPage, title)
end
-- add these categories only in the mainspace and only if they are on the page where the template is used
if (onInitialPage and title.namespace == 0) then
addLineColorTrackingCategories(args)
addTopColorTrackingCategories(args)
end
if (cellValueTBA == true and title.namespace == 0) then
addTrackingCategory(trackingCategoryList["tba_values"])
end
-- Do not show the summary if this is being transcluded on the initial list page
-- Do include it on all other lists
if (onInitialPage and args.ShortSummary) then
local bottomWrapper = createShortSummaryRow(args, lineColor)
return tostring(root) .. tostring(bottomWrapper) .. trackingCategories
else
return tostring(root) .. trackingCategories
end
end
-- Local function which handles both module entry points.
local function main(frame, sublist)
local getArgs = require('Module:Arguments with aliases').getArgs
local args
-- Most parameters should still display when blank, so don't remove blanks
if (sublist) then
args = getArgs(frame, {
removeBlanks = false,
wrappers = 'قالب:قائمة حلقات/قائمة فرعية',
aliases = aliases.aliases
})
else
args = getArgs(frame, {
removeBlanks = false,
wrappers = 'قالب:قائمة حلقات',
aliases = aliases.aliases
})
end
-- args['1'] = mw.getCurrentFrame():getParent():getTitle()
return _main(args, sublist, frame)
end
function p.sublist(frame)
return main(frame, true)
end
function p.list(frame)
return main(frame, false)
end
return p