<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://phuketer.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3ATelevision_infoboxes_disambiguation_check</id>
	<title>Module:Television infoboxes disambiguation check - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://phuketer.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3ATelevision_infoboxes_disambiguation_check"/>
	<link rel="alternate" type="text/html" href="https://phuketer.com/w/index.php?title=Module:Television_infoboxes_disambiguation_check&amp;action=history"/>
	<updated>2026-06-17T20:50:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.2</generator>
	<entry>
		<id>https://phuketer.com/w/index.php?title=Module:Television_infoboxes_disambiguation_check&amp;diff=1589&amp;oldid=prev</id>
		<title>imported&gt;Gonnym: major update to work with the TV season title change</title>
		<link rel="alternate" type="text/html" href="https://phuketer.com/w/index.php?title=Module:Television_infoboxes_disambiguation_check&amp;diff=1589&amp;oldid=prev"/>
		<updated>2025-12-22T12:01:57Z</updated>

		<summary type="html">&lt;p&gt;major update to work with the TV season title change&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require(&amp;quot;strict&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local libraryUtil = require(&amp;quot;libraryUtil&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- DisambiguationPattern &amp;quot;class&amp;quot;&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function DisambiguationPattern(o)&lt;br /&gt;
	local obj = o or { pattern = &amp;quot;&amp;quot;, type = 0 }&lt;br /&gt;
	libraryUtil.makeCheckSelfFunction(&lt;br /&gt;
		&amp;quot;Television infoboxes disambiguation check&amp;quot;,&lt;br /&gt;
		&amp;quot;DisambiguationPattern&amp;quot;,&lt;br /&gt;
		obj,&lt;br /&gt;
		&amp;quot;Television infoboxes disambiguation check object&amp;quot;&lt;br /&gt;
	)&lt;br /&gt;
	return obj&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Constants&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local DAB_VALID = {&lt;br /&gt;
	[true] = &amp;quot;valid&amp;quot;,&lt;br /&gt;
	[false] = &amp;quot;invalid&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local CATEGORY_INCORRECT = &amp;quot;[[Category:Television articles with incorrect naming style]]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
local validationTypeList = {&lt;br /&gt;
	VALIDATION_TYPE_YEAR_COUNTRY = 1,&lt;br /&gt;
	VALIDATION_TYPE_YEAR = 2,&lt;br /&gt;
	VALIDATION_TYPE_COUNTRY = 3,&lt;br /&gt;
	VALIDATION_TYPE_YEAR_SEASON_NUMBER = 4,&lt;br /&gt;
	VALIDATION_TYPE_COUNTRY_SEASON_NUMBER = 5,&lt;br /&gt;
	VALIDATION_TYPE_SEASON_NUMBER = 6,&lt;br /&gt;
	VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER = 8&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local debugMessageList = {&lt;br /&gt;
	DEBUG_EMPTY_TITLE = &amp;quot;Debug: Error: Empty title.&amp;quot;,&lt;br /&gt;
	DEBUG_NO_DAB = &amp;quot;Debug: No disambiguation.&amp;quot;,&lt;br /&gt;
	DEBUG_TITLE_ON_EXCEPTION = &amp;quot;Debug: Title on exception list.&amp;quot;,&lt;br /&gt;
	DEBUG_VALID_FORMAT = &amp;quot;Debug: Using a valid format.&amp;quot;,&lt;br /&gt;
	DEBUG_NOT_VALID_FORMAT = &amp;quot;Debug: Not a valid format.&amp;quot;,&lt;br /&gt;
	DEBUG_YEAR_COUNTRY = &amp;quot;Debug: Using a valid format with an extended Year and Country - {}.&amp;quot;,&lt;br /&gt;
	DEBUG_YEAR = &amp;quot;Debug: Using a valid format with an extended Year - {}.&amp;quot;,&lt;br /&gt;
	DEBUG_COUNTRY = &amp;quot;Debug: Using a valid format with an extended Country - {}.&amp;quot;,&lt;br /&gt;
	DEBUG_INCORRECT_STYLE = &amp;quot;Debug: Using a valid format but using an incorrect extended style.&amp;quot;,&lt;br /&gt;
	DEBUG_INCORRECT_INFOBOX = &amp;quot;Debug: Using incorrect infobox - {}.&amp;quot;,&lt;br /&gt;
	DEBUG_YEAR_SEASON_NUMBER = &amp;quot;Debug: Using a valid format with an extended Year and Season number - {}.&amp;quot;,&lt;br /&gt;
	DEBUG_COUNTRY_SEASON_NUMBER = &amp;quot;Debug: Using a valid format with an extended Country and Season number - {}.&amp;quot;,&lt;br /&gt;
	DEBUG_SEASON_NUMBER = &amp;quot;Debug: Using a valid format with a Season number - {}.&amp;quot;,&lt;br /&gt;
	DEBUG_YEAR_COUNTRY_SEASON_NUMBER = &amp;quot;Debug: Using a valid format with an extended Year, Country and Season number - {}.&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Validation helpers&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function validateTwoParameters(a, b)&lt;br /&gt;
	return not not (a and b)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function validateSeasonNumber(seasonNumber)&lt;br /&gt;
	if not seasonNumber then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	return tonumber(seasonNumber:sub(1, 1)) ~= 0&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function validateYear(year)&lt;br /&gt;
	return year and #year == 4&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function validateCountryAdjective(adj)&lt;br /&gt;
	if not adj or adj == &amp;quot;&amp;quot; then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	local data = mw.loadData(&amp;quot;Module:Country adjective&amp;quot;)&lt;br /&gt;
	return not not data.getCountryFromAdj[adj]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Pattern validation engine&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function validatePatterns(disambiguation, patternList)&lt;br /&gt;
	local year, adjective, seasonNumber&lt;br /&gt;
	local isYearValid, isAdjectiveValid, isSeasonNumberValid&lt;br /&gt;
&lt;br /&gt;
	for i = 1, #patternList do&lt;br /&gt;
		local p = patternList[i]&lt;br /&gt;
		if disambiguation:match(p.pattern) then&lt;br /&gt;
&lt;br /&gt;
			-- YEAR + COUNTRY&lt;br /&gt;
			if p.type == validationTypeList.VALIDATION_TYPE_YEAR_COUNTRY then&lt;br /&gt;
				year, adjective = disambiguation:match(p.pattern)&lt;br /&gt;
				isYearValid = validateYear(year)&lt;br /&gt;
				isAdjectiveValid = validateCountryAdjective(adjective)&lt;br /&gt;
				local ok = validateTwoParameters(isYearValid, isAdjectiveValid)&lt;br /&gt;
				return ok, debugMessageList.DEBUG_YEAR_COUNTRY:gsub(&amp;quot;{}&amp;quot;, DAB_VALID[ok])&lt;br /&gt;
&lt;br /&gt;
			-- YEAR&lt;br /&gt;
			elseif p.type == validationTypeList.VALIDATION_TYPE_YEAR then&lt;br /&gt;
				year = disambiguation&lt;br /&gt;
				isYearValid = validateYear(year)&lt;br /&gt;
				return isYearValid, debugMessageList.DEBUG_YEAR:gsub(&amp;quot;{}&amp;quot;, DAB_VALID[isYearValid])&lt;br /&gt;
&lt;br /&gt;
			-- COUNTRY&lt;br /&gt;
			elseif p.type == validationTypeList.VALIDATION_TYPE_COUNTRY then&lt;br /&gt;
				adjective = disambiguation&lt;br /&gt;
				isAdjectiveValid = validateCountryAdjective(adjective)&lt;br /&gt;
				return isAdjectiveValid, debugMessageList.DEBUG_COUNTRY:gsub(&amp;quot;{}&amp;quot;, DAB_VALID[isAdjectiveValid])&lt;br /&gt;
&lt;br /&gt;
			-- YEAR + SEASON&lt;br /&gt;
			elseif p.type == validationTypeList.VALIDATION_TYPE_YEAR_SEASON_NUMBER then&lt;br /&gt;
				year, seasonNumber = disambiguation:match(p.pattern)&lt;br /&gt;
				isYearValid = validateYear(year)&lt;br /&gt;
				isSeasonNumberValid = validateSeasonNumber(seasonNumber)&lt;br /&gt;
				local ok = validateTwoParameters(isYearValid, isSeasonNumberValid)&lt;br /&gt;
				return ok, debugMessageList.DEBUG_YEAR_SEASON_NUMBER:gsub(&amp;quot;{}&amp;quot;, DAB_VALID[ok])&lt;br /&gt;
&lt;br /&gt;
			-- COUNTRY + SEASON&lt;br /&gt;
			elseif p.type == validationTypeList.VALIDATION_TYPE_COUNTRY_SEASON_NUMBER then&lt;br /&gt;
				adjective, seasonNumber = disambiguation:match(p.pattern)&lt;br /&gt;
				isAdjectiveValid = validateCountryAdjective(mw.text.trim(adjective))&lt;br /&gt;
				isSeasonNumberValid = validateSeasonNumber(seasonNumber)&lt;br /&gt;
				local ok = validateTwoParameters(isAdjectiveValid, isSeasonNumberValid)&lt;br /&gt;
				return ok, debugMessageList.DEBUG_COUNTRY_SEASON_NUMBER:gsub(&amp;quot;{}&amp;quot;, DAB_VALID[ok])&lt;br /&gt;
&lt;br /&gt;
			-- SEASON ONLY&lt;br /&gt;
			elseif p.type == validationTypeList.VALIDATION_TYPE_SEASON_NUMBER then&lt;br /&gt;
				seasonNumber = disambiguation:match(p.pattern)&lt;br /&gt;
				isSeasonNumberValid = validateSeasonNumber(seasonNumber)&lt;br /&gt;
				return isSeasonNumberValid, debugMessageList.DEBUG_SEASON_NUMBER:gsub(&amp;quot;{}&amp;quot;, DAB_VALID[isSeasonNumberValid])&lt;br /&gt;
&lt;br /&gt;
			-- YEAR + COUNTRY + SEASON&lt;br /&gt;
			elseif p.type == validationTypeList.VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER then&lt;br /&gt;
				year, adjective, seasonNumber = disambiguation:match(p.pattern)&lt;br /&gt;
				isYearValid = validateYear(year)&lt;br /&gt;
				isAdjectiveValid = validateCountryAdjective(mw.text.trim(adjective))&lt;br /&gt;
				isSeasonNumberValid = validateSeasonNumber(seasonNumber)&lt;br /&gt;
				local ok = validateTwoParameters(isYearValid, isAdjectiveValid)&lt;br /&gt;
				ok = validateTwoParameters(ok, isSeasonNumberValid)&lt;br /&gt;
				return ok, debugMessageList.DEBUG_YEAR_COUNTRY_SEASON_NUMBER:gsub(&amp;quot;{}&amp;quot;, DAB_VALID[ok])&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return false, debugMessageList.DEBUG_INCORRECT_STYLE&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Disambiguation type validation&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function validateDisambiguationType(disambiguation, typeList)&lt;br /&gt;
	local extended = disambiguation&lt;br /&gt;
	local count = 0&lt;br /&gt;
&lt;br /&gt;
	for i = 1, #typeList do&lt;br /&gt;
		local t = typeList[i]&lt;br /&gt;
		extended, count = extended:gsub(t, &amp;quot;&amp;quot;)&lt;br /&gt;
		extended = mw.text.trim(extended)&lt;br /&gt;
		if count ~= 0 then&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return count ~= 0, extended&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function validateDisambiguation(invoker, disambiguation, typeList, patternList)&lt;br /&gt;
	if #typeList ~= 0 then&lt;br /&gt;
		local ok, extended = validateDisambiguationType(disambiguation, typeList)&lt;br /&gt;
&lt;br /&gt;
		if not ok then&lt;br /&gt;
			return false, debugMessageList.DEBUG_NOT_VALID_FORMAT&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if extended == &amp;quot;&amp;quot; then&lt;br /&gt;
			return true, debugMessageList.DEBUG_VALID_FORMAT&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if invoker ~= &amp;quot;infobox television season&amp;quot; then&lt;br /&gt;
			disambiguation = extended&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return validatePatterns(disambiguation, patternList)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Incorrect infobox detection&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function isPageUsingIncorrectInfobox(invoker, disambiguation, otherList)&lt;br /&gt;
&lt;br /&gt;
	-- Only skip incorrect-infobox detection for SEASON pages.&lt;br /&gt;
	-- Season pages often have disambiguations like:&lt;br /&gt;
	--   &amp;quot;season 1&amp;quot;, &amp;quot;series 2&amp;quot;, &amp;quot;season 1 TV series&amp;quot;&lt;br /&gt;
	-- These should NOT trigger incorrect-infobox errors.&lt;br /&gt;
	if invoker == &amp;quot;infobox television season&amp;quot; then&lt;br /&gt;
		if disambiguation:match(&amp;quot;^[Ss]eason%s+%d+&amp;quot;) &lt;br /&gt;
			or disambiguation:match(&amp;quot;^[Ss]eries%s+%d+&amp;quot;) then&lt;br /&gt;
			return false&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Normal incorrect-infobox detection&lt;br /&gt;
	for k, v in pairs(otherList) do&lt;br /&gt;
		if disambiguation:match(k) then&lt;br /&gt;
			return true, v, debugMessageList.DEBUG_INCORRECT_INFOBOX:gsub(&amp;quot;{}&amp;quot;, k)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Exception list&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function isOnExceptionList(title, list)&lt;br /&gt;
	for _, v in ipairs(list) do&lt;br /&gt;
		if v == title or title:match(v) then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Disambiguation extraction (supports new naming)&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Get the disambiguation text and support both:&lt;br /&gt;
-- - Parenthetical only: &amp;quot;Big Brother (American TV series)&amp;quot;&lt;br /&gt;
-- - Parenthetical + season: &amp;quot;Big Brother (American TV series) season 5&amp;quot;&lt;br /&gt;
-- - Season only: &amp;quot;Lost season 1&amp;quot;&lt;br /&gt;
local function getDisambiguation(title)&lt;br /&gt;
	local match = require(&amp;quot;Module:String&amp;quot;)._match&lt;br /&gt;
&lt;br /&gt;
	-- Last parenthetical chunk, if any.&lt;br /&gt;
	local paren = match(title, &amp;quot;%s%((.-)%)&amp;quot;, 1, -1, false, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	-- Trailing &amp;quot;season X&amp;quot; or &amp;quot;series X&amp;quot;, if any (X can be wrong; validation will decide).&lt;br /&gt;
	local base, seasonPart = title:match(&amp;quot;^(.-)%s+(season%s+.+)$&amp;quot;)&lt;br /&gt;
	if not base then&lt;br /&gt;
		base, seasonPart = title:match(&amp;quot;^(.-)%s+(series%s+.+)$&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if paren ~= &amp;quot;&amp;quot; and seasonPart then&lt;br /&gt;
		-- Example: &amp;quot;Big Brother (American TV series) season 5&amp;quot;&lt;br /&gt;
		-- Returns: &amp;quot;American TV series season 5&amp;quot;&lt;br /&gt;
		return paren .. &amp;quot; &amp;quot; .. seasonPart&lt;br /&gt;
	elseif paren ~= &amp;quot;&amp;quot; then&lt;br /&gt;
		-- Example: &amp;quot;Big Brother (American TV series)&amp;quot;&lt;br /&gt;
		-- Returns: &amp;quot;American TV series&amp;quot;&lt;br /&gt;
		return paren&lt;br /&gt;
	elseif seasonPart then&lt;br /&gt;
		-- Example: &amp;quot;Lost season 1&amp;quot;&lt;br /&gt;
		-- Returns: &amp;quot;season 1&amp;quot;&lt;br /&gt;
		return seasonPart&lt;br /&gt;
	else&lt;br /&gt;
		return &amp;quot;&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Utility&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function isEmpty(x)&lt;br /&gt;
	return not x or x == &amp;quot;&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Main entry point&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
local function main(title, invoker, typeList, patternList, exceptionList, otherInfoboxList, invalidTitleStyleList)&lt;br /&gt;
	if isEmpty(title) then&lt;br /&gt;
		return &amp;quot;&amp;quot;, debugMessageList.DEBUG_EMPTY_TITLE&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if isOnExceptionList(title, exceptionList) then&lt;br /&gt;
		return &amp;quot;&amp;quot;, debugMessageList.DEBUG_TITLE_ON_EXCEPTION&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if invoker == &amp;quot;infobox television season&amp;quot; then&lt;br /&gt;
		for i = 1, #invalidTitleStyleList do&lt;br /&gt;
			if title:find(invalidTitleStyleList[i]) then&lt;br /&gt;
				return CATEGORY_INCORRECT, debugMessageList.DEBUG_NOT_VALID_FORMAT&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local disambiguation = getDisambiguation(title)&lt;br /&gt;
&lt;br /&gt;
	if isEmpty(disambiguation) then&lt;br /&gt;
		return &amp;quot;&amp;quot;, debugMessageList.DEBUG_NO_DAB&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local wrong, category, dbg = isPageUsingIncorrectInfobox(invoker, disambiguation, otherInfoboxList)&lt;br /&gt;
	if wrong then&lt;br /&gt;
		return category, dbg&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local ok, dbg2 = validateDisambiguation(invoker, disambiguation, typeList, patternList)&lt;br /&gt;
&lt;br /&gt;
	if not ok then&lt;br /&gt;
		return CATEGORY_INCORRECT, dbg2&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return &amp;quot;&amp;quot;, dbg2&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
-- Export&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
return {&lt;br /&gt;
	main = main,&lt;br /&gt;
	DisambiguationPattern = DisambiguationPattern,&lt;br /&gt;
&lt;br /&gt;
	VALIDATION_TYPE_YEAR_COUNTRY = validationTypeList.VALIDATION_TYPE_YEAR_COUNTRY,&lt;br /&gt;
	VALIDATION_TYPE_YEAR = validationTypeList.VALIDATION_TYPE_YEAR,&lt;br /&gt;
	VALIDATION_TYPE_COUNTRY = validationTypeList.VALIDATION_TYPE_COUNTRY,&lt;br /&gt;
	VALIDATION_TYPE_YEAR_SEASON_NUMBER = validationTypeList.VALIDATION_TYPE_YEAR_SEASON_NUMBER,&lt;br /&gt;
	VALIDATION_TYPE_COUNTRY_SEASON_NUMBER = validationTypeList.VALIDATION_TYPE_COUNTRY_SEASON_NUMBER,&lt;br /&gt;
	VALIDATION_TYPE_SEASON_NUMBER = validationTypeList.VALIDATION_TYPE_SEASON_NUMBER,&lt;br /&gt;
	VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER = validationTypeList.VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>imported&gt;Gonnym</name></author>
	</entry>
</feed>