Module:Infobox television episode
![]() | This Lua module is used on approximately 13,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Module:Infobox television episode is used to validate parameter values for Template:Infobox television episode and Template:Infobox television crossover episode.
Functions
above_title
{{#invoke:Infobox television episode|above_title}}
Returns the text used for the |above=
field of the infobox.
episode_list
{{#invoke:Infobox television episode|episode_list}}
Returns the text used for the |episode_list=
field of the infobox.
italic_title
{{#invoke:Infobox television episode|italic_title}}
Returns an {{Italic dab2}} instance if title qualifies. Also returns a maintenance category if conditions are met.
The article's title is italicized if the series name is included in the article's title disambiguation. No italicization happens if one of the following conditions is met:
|italic_title=no
is set.- The article's title does not use disambiguation.
- No
|series=
value is set. - The article's disambiguation is not equal or does not include the series name.
The page is added to a maintenance category if the title is italicized and there is already an {{Italic dab}}, {{Italic title}} or {{DISPLAYTITLE}} template.
Infobox parameters checked:
|series=
|italic_title=
validate_values
{{#invoke:Infobox television episode|validate_values}}
Returns the relevant maintenance categories based on the {{Infobox television episode}} values validated.
Infobox television crossover episode function
validate_values_crossover
{{#invoke:Infobox television episode|validate_values_crossover}}
Returns the relevant maintenance categories based on the {{Infobox television crossover episode}} values validated.
See also
Maintenance categories
The module places relevant pages in the following maintenance categories:
- Category:Pages using infobox television with flag icon (0)
- Category:Pages using infobox television episode with image-related values without an image (5)
- Category:Pages using infobox television episode with incorrectly formatted values (50)
- Category:Pages using infobox television episode with non-matching title (9)
- Category:Pages using infobox television episode with nonstandard dates (14)
- Category:Pages using infobox television episode with unlinked values (1,085)
- Category:Pages using infobox television episode with unnecessary list markup (3,601)
- Category:Pages using infobox television episode with unnecessary manual displaytitle (11)
- Category:Pages using infobox television episode with unnecessary title parameter (9)
--- @module
local p = {}
local maintenance_categories = {
incorrectly_formatted = "[[Category:Pages using infobox television episode with incorrectly formatted values]]",
unlinked_values = "[[Category:Pages using infobox television episode with unlinked values]]",
image_values_without_an_image = "[[Category:Pages using infobox television episode with image-related values without an image]]",
unnecessary_title_parameter = "[[Category:Pages using infobox television episode with unnecessary title parameter]]",
non_matching_title = "[[Category:Pages using infobox television episode with non-matching title]]",
flag_icon = "[[Category:Pages using infobox television with flag icon]]",
dates_incorrectly_formatted = "[[Category:Pages using infobox television with nonstandard dates]]",
manual_display_title = "[[Category:Pages using infobox television episode with unnecessary manual displaytitle]]",
}
--- Returns a maintenance category if the italic_title value is not "no".
---
--- Infobox parameters checked:
--- - |italic_title=
---
--- @param args table
--- @return string
local function is_italic_title_valid_value(args)
if args.italic_title and args.italic_title ~= "no" then
return maintenance_categories.incorrectly_formatted
end
return ""
end
--- Returns a maintenance category if the date is not formatted correctly with a {{Start date}} template.
---
--- Infobox parameters checked:
--- - |airdate=
--- - |released=
--- - |airdate_overall=
---
--- @param start_date string The start date value.
--- @return string
local function are_dates_formatted_correctly(start_date)
if start_date and not string.find(start_date, "dtstart") then
return maintenance_categories.dates_incorrectly_formatted
end
return ""
end
--- Returns a maintenance category if a flag icon is used.
---
--- All the infobox values are checked.
---
--- @param args table
--- @return string
local function has_flag_icon(args)
for _, v in pairs(args) do
if string.find(v, "flagicon") then
return maintenance_categories.flag_icon
end
end
return ""
end
--- Returns a maintenance category if the values are linked or formatted.
---
--- Infobox parameters checked:
--- - |episode=
--- - |season=
--- - |series_no=
--- - |episode_list=
---
--- The function currently checks if the following values are present:
--- - ]] - links.
--- - '' - italics or bold.
---
--- @param args table
--- @return string
local function are_values_linked_or_formatted(args)
for _, parameter in pairs({args.episode, args.season, args.series_no, args.episode_list}) do
for _, bad_value in pairs({"]]", "''"}) do
if string.find(parameter, bad_value, 1, true) then
return maintenance_categories.incorrectly_formatted
end
end
end
return ""
end
--- Returns a maintenance category if the values use additional overall numbering.
---
--- Infobox parameters checked:
--- - |episode=
--- - |season=
--- - |series_no=
---
--- The function currently checks if the following values are present:
--- - overall - unsupported series overall numbering.
---
--- @param args table
--- @return string
local function are_values_using_overall(args)
for _, parameter in pairs({args.episode, args.season, args.series_no}) do
if string.find(parameter, "overall") then
return maintenance_categories.incorrectly_formatted
end
end
return ""
end
--- Returns a maintenance category if the values are unlinked and if additional characters are found in the text.
---
--- Infobox parameters checked:
--- - |series=
--- - |prev=
--- - |next=
---
--- The function currently checks if a value is unlinked or if there is any additional character
--- before or after the linked text.
---
--- @param args table
--- @return string
local function are_values_links_only(args)
for _, v in pairs({args.series, args.prev, args.next}) do
-- Check whether the values are linked.
if not string.find(v, "%[%[.*%]%]") then
return maintenance_categories.unlinked_values
end
-- Check whether the values have anything before or after link brackets.
if string.gsub(v, "(%[%[.*%]%])", "") ~= "" then
return maintenance_categories.incorrectly_formatted
end
end
return ""
end
--- Returns a maintenance category if there is no image file while image auxiliary values are present.
---
--- Infobox parameters checked:
--- - |image=
--- - |image_size=
--- - |image_upright=
--- - |image_alt=
--- - |alt=
--- - |caption=
---
--- @param args table
--- @return string
local function are_image_auxiliary_values_used_for_no_image(args)
if args.image then
return ""
end
if args.image_size or args.image_upright or args.image_alt or args.alt or args.caption then
return maintenance_categories.image_values_without_an_image
end
return ""
end
--- Returns a maintenance category if the infobox title is equal to the article title.
---
--- Infobox parameters checked:
--- - |title=
--- - |series=
---
--- The function currently checks if the infobox title is equal to the article title while ignoring styling such as:
--- - nowrap spans.
--- - line breaks.
--- - Leading and trailing apostrophe spaces.
---
--- Testing parameters:
--- - |page_title_test= - the title of the page being checked.
---
--- @param frame table
--- @param args table
--- @return string
local function is_infobox_title_equal_to_article_title(frame, args)
if not args.title then
return ""
end
local article_title = args.page_title_test
if not args.page_title_test then
article_title = mw.title.getCurrentTitle().text
end
local match = require("Module:String")._match
local disambiguation = match(article_title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation ~= "" then
local delink = require("Module:Delink")._delink
local series_name = delink({args.series})
if series_name and disambiguation == series_name then
-- Remove disambiguation.
local _
article_title, _ = string.gsub(article_title, "%s+%b()$", "")
end
end
local space_single = frame:expandTemplate{title = "Space+single"}
local single_space = frame:expandTemplate{title = "Single+space"}
-- Convert the page name to use the {{Space+single}} and {{Single+space}} templates if a leading or trailing apostrophe is used.
local page_name, _
-- In template space the value is encoded while in the module it isn't. The encoded version might not be needed.
if string.find(article_title, "'") then
page_name, _ = string.gsub(string.gsub(article_title, "^'", space_single), "'$", single_space)
else
page_name, _ = string.gsub(string.gsub(article_title, "^'", space_single), "'$", single_space)
end
-- Remove nowrap span.
if string.find(args.title, "nowrap") then
local title = frame:expandTemplate{title = "Strip tags", args = {args.title}}
if title == page_name then
return ""
end
return maintenance_categories.non_matching_title
end
-- Remove line breaks and additional spaces as a result.
if string.find(args.title, "<br%s?/?>") then
local title, _ = string.gsub(args.title, "<br%s?/?>", "")
title, _ = string.gsub(title, " ", " ")
if title == page_name then
return ""
end
return maintenance_categories.non_matching_title
end
if args.title == page_name then
return maintenance_categories.unnecessary_title_parameter
end
-- Article and infobox titles do not match.
return maintenance_categories.non_matching_title
end
--- Returns the relevant maintenance categories based on the {{Infobox television episode}} values validated.
---
--- @param frame table
--- @return string
function p.validate_values(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local categories = {}
table.insert(categories, is_infobox_title_equal_to_article_title(frame, args))
table.insert(categories, are_image_auxiliary_values_used_for_no_image(args))
table.insert(categories, are_values_links_only(args))
table.insert(categories, are_values_using_overall(args))
table.insert(categories, are_values_linked_or_formatted(args))
table.insert(categories, has_flag_icon(args))
table.insert(categories, are_dates_formatted_correctly(args.airdate or args.released))
table.insert(categories, is_italic_title_valid_value(args))
return table.concat(categories, "")
end
--- Returns an {{Italic dab2}} instance if title qualifies. Also returns a maintenance category if conditions are met.
---
--- The article's title is italicized if the series name is included in the article's title disambiguation.
--- No italicization happens if one of the following conditions is met:
---
--- - |italic_title= is set to "no".
--- - The article's title does not use disambiguation.
--- - No |series= value is set.
--- - The article's disambiguation is not equal or does not include the series name.
---
--- The page is added to a maintenance category if the title is italicized and there is already an
--- {{Italic dab}}, {{Italic title}} or {{DISPLAYTITLE}} template.
---
--- Infobox parameters checked:
--- - |series=
--- - |italic_title=
---
--- Testing parameters:
--- - |page_test= - a real Wikipedia page.
--- - |page_title_test= - the title of the page being checked.
---
--- @param frame table
--- @return string, string
function p.italic_title(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local page_text
if args.page_test then
page_text = mw.title.new(args.page_test):getContent()
else
page_text = mw.title.getCurrentTitle():getContent()
end
-- Check if the page already has an {{Italic dab}}, {{Italic title}} or {{DISPLAYTITLE}} template.
local hasItalicDab, _ = string.find(page_text, "{{[Ii]talic dab")
local hasItalicTitle, _ = string.find(page_text, "{{[Ii]talic title")
local hasDisplayTitle, _ = string.find(page_text, "{{DISPLAYTITLE")
local maintenance_category = ""
if hasItalicDab or hasItalicTitle or hasDisplayTitle then
maintenance_category = maintenance_categories.manual_display_title
end
-- In case the page does not need to be italicized, a "no" value will disable it.
if args.italic_title == "no" then
return "", maintenance_category
end
local article_title = args.page_title_test
if not args.page_title_test then
article_title = mw.title.getCurrentTitle().text
end
local match = require("Module:String")._match
local disambiguation = match(article_title, "%s%((.-)%)", 1, -1, false, "")
-- The title is not italicized if the title does not use disambiguation or if the series parameter isn't used.
if disambiguation == "" or not args.series then
return "", maintenance_category
end
local delink = require("Module:Delink")._delink
local series_name = delink({args.series})
-- Check if the disambiguation equals the series name or if the series name can be found in the disambiguation.
local italic_dab
if disambiguation == series_name then
italic_dab = frame:expandTemplate{title = "Italic dab2"}
elseif string.find(disambiguation, series_name) then
italic_dab = frame:expandTemplate{title = "Italic dab2", args = {string = series_name}}
else
return "", maintenance_category
end
if args.page_title_test and italic_dab then
italic_dab = "italic_dab"
end
return italic_dab, maintenance_category
end
--- Returns the relevant maintenance categories based on the {{Infobox television crossover episode}} values validated.
---
--- @param frame table
--- @return string
function p.validate_values_crossover(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local categories = {}
table.insert(categories, are_image_auxiliary_values_used_for_no_image(args))
table.insert(categories, has_flag_icon(args))
table.insert(categories, are_dates_formatted_correctly(args.airdate_overall))
for i = 1, 5 do
if not args["series" .. i] then
break
end
local nested_args = {
series = args["series" .. i],
episode = args["episode_no" .. i],
season = args["season" .. i],
airdate = args["airdate" .. i],
prev = args["prev" .. i],
next = args["next" .. i],
episode_list = args["episode_list" .. i],
}
table.insert(categories, are_values_links_only(nested_args))
table.insert(categories, are_values_using_overall(nested_args))
table.insert(categories, are_values_linked_or_formatted(nested_args))
table.insert(categories, are_dates_formatted_correctly(nested_args.airdate))
end
return table.concat(categories, "")
end
return p