Module:Infobox television

--- @module local p = {}

local maintenance_categories = { image_values_without_an_image = "", unnecessary_title_parameter = "", non_matching_title = "", flag_icon = "", dates_incorrectly_formatted = "", manual_display_title = "", }

--- Returns a maintenance category if the dates aren't formatted correctly with --- and  templates. --- --- @param start_date string The start date parameter. --- @param end_date string The end date parameter. --- @return string local function are_dates_formatted_correctly(start_date, end_date) if start_date and not string.find(start_date, "dtstart") then return maintenance_categories.dates_incorrectly_formatted end

if end_date and (not string.find(end_date, "dtend") and end_date ~= "present") then return maintenance_categories.dates_incorrectly_formatted end

return "" end

--- Returns a maintenance category if a DISPLAYTITLE template is used. --- ---@return string local function has_display_title local page_text = mw.title.getCurrentTitle:getContent if string.find(page_text, "DISPLAYTITLE") then return maintenance_categories.manual_display_title 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 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: --- - |name= --- --- The function currently checks if the infobox title is equal to the article title while ignoring styling such as: --- - nowrap spans. --- - line breaks. --- --- |page_title_test= is used for testing only. --- --- @param frame table --- @param args table --- @return string local function is_infobox_title_equal_to_article_title(frame, args) if not args.name then return "" end

local article_title = args.page_title_test if not args.page_title_test then article_title = mw.title.getCurrentTitle.text end

-- Remove disambiguation. local page_name, _ = string.gsub(article_title, "%s+%b$", "")

-- 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, "") then local title, _ = string.gsub(args.title, "", "") 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 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, has_display_title) 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.first_aired or args.released, args.last_aired))

return table.concat(categories, "") end

return p