Module:Infobox television season name
-- This module requires the use of Module:Arguments.
 local getArgs = require('Module:Arguments').getArgs
 
 local pipedLink = &quot;&quot;
 
 local p = {}
 
 -- Local function which is used to create an pipped article link.
 local function createArticleTitleWithPipedLink(article)
 	if (pipedLink == nil or pipedLink == &quot;&quot;) then
 		return &quot;&quot;
 	else
 		return &quot;[[&quot; .. article .. &quot;|&quot; .. pipedLink .. &quot;]]&quot;
 	end
 end
 
 --[[
 Local function which is used to check if the given article exists.
 The function returns &quot;true&quot; in the following cases:
 	-- A season article exists.
 	-- A redirect exists to a season section.
 
 The function returns nil in the following cases:
 	-- A season article or redirect do not exist.
 	-- A redirect exists, but it is a general redirect and not for any specific season section.
 ]]--
 local function checkArticle(articleName)
 	local article = mw.title.new(articleName)
 	if (article ~= nil and article.exists) then
 		local redirectTarget = article.redirectTarget
 		if (redirectTarget) then
 			local fullLink = redirectTarget.fullText
 			local isSection = fullLink:find(&quot;#&quot;)
 			if (isSection) then
 				return &quot;true&quot;								-- Article is a section redirect; Valid link.
 			else
 				return nil									-- Article is a general redirect; Not a valid link.
 			end
 		else
 			return &quot;true&quot;									-- Article exists and is not a redirect; Valid link.
 		end
 	else
 		return nil											-- Article or redirect do not exist; Not a valid link.
 	end
 end
 
 --[[
 Local function which is used to create a TV season link.
 
 The following are the supported season naming styles:
 	-- &lt;showName&gt; (&lt;seasonQualifier&gt; &lt;seasonType&gt;)
 		Example: Big Brother 1 (American season).
 	-- &lt;showName&gt; (&lt;seasonType&gt; &lt;seasonNumber&gt;)
 		Example: Lost (season 3).
 	-- &lt;showName&gt; (&lt;seasonQualifier&gt; &lt;seasonType&gt; &lt;seasonNumber&gt;)
 		Example: The Flash (2014 season 3).
 	-- &lt;showName&gt; &lt;preSeasonQualifier&gt; (&lt;seasonType&gt; &lt;seasonNumber&gt;)
 		Example: Dallas (1978 TV series) (season 3).
 	-- &lt;showName&gt; &lt;preSeasonQualifier&gt; (&lt;seasonQualifier&gt; &lt;seasonType&gt; &lt;seasonNumber&gt;)
 		Example: No current example.
 	-- &lt;showName&gt; (&lt;preSeasonQualifier&gt;, &lt;seasonType&gt; &lt;seasonNumber&gt;) - TODO
 		Example: Teenage Mutant Ninja Turtles (1987 TV series, season 1)
 --]]
 local function createLink(args, prevOrNextSeasonNumber)
 	local showName = args[1] or args['show_name']
 	if (showName == nil) then
 		return &quot;&quot;
 	end	
 	
 	showName = showName .. &quot; &quot;
 
 	local preSeasonQualifier = args[2] or args['pre_season_qualifier']
 	if (preSeasonQualifier == nil) then
 		preSeasonQualifier = &quot;&quot;
 	else
 		preSeasonQualifier = preSeasonQualifier .. &quot; &quot;
 	end
 	
 	local seasonQualifier = args[3] or args['season_qualifier']
 	if (seasonQualifier == nil) then
 		seasonQualifier = &quot;&quot;
 	else 
 		seasonQualifier = seasonQualifier .. &quot; &quot;
 	end
 	
 	local seasonType = args[4] or args['season_type']
 	if (seasonType == nil) then
 		seasonType = &quot;season&quot;
 	end
 
 	local realitySeriesStyle = false
 	local showNameModified
 	local seasonNumber = args[5] or args['season_number']
 	if (seasonNumber == nil) then
 		if (string.match(showName , &quot;%s+(%d+)&quot;)) then
 			_, _, showNameModified, seasonNumber = string.find(showName, &quot;(.*)%s+(%d+)&quot;)
 			realitySeriesStyle = true
 		else
 			return &quot;&quot; -- Not a valid next/prev season link
 		end
 	end
 
 	if (tonumber(seasonNumber) == nil) then
 		return &quot;&quot;
 	else
 		seasonNumber = seasonNumber + prevOrNextSeasonNumber
 		pipedLink = seasonType:gsub(&quot;^%l&quot;, string.upper) .. &quot; &quot; .. seasonNumber
 		
 		if (realitySeriesStyle) then
 			return showNameModified .. &quot; &quot; .. seasonNumber .. &quot; (&quot; .. seasonQualifier .. seasonType .. &quot;)&quot;
 		else
 			return showName .. preSeasonQualifier .. &quot;(&quot; .. seasonQualifier .. seasonType .. &quot; &quot; .. seasonNumber .. &quot;)&quot;
 		end
 	end
 end
 
 -- Local function which is called to create a TV season link for the next season.
 -- Passes the value &quot;1&quot; to increment the current season number.
 local function createNextSeasonArticle(args)
 	return createLink(args, 1)
 end
 
 -- Local function which is called to create a TV season link for the previous season.
 -- Passes the value &quot;-1&quot; to decrement the current season number.
 local function createPreviousSeasonArticle(args)
 	return createLink(args, -1)
 end
 
 --[[
 Wrapper function which handles the processing of the arguments 
 from multiple public invoked functions.
 
 Parameters:
 	-- |show_name=				— required; The title of TV program.
 	-- |pre_season_qualifier=	— optional; For cases where disambiguation before the season is required
 											(e.g. the pre-season qualifier for Dallas (1978 TV series) (season 7) is (1978 TV series)).
 	-- |season_qualifier=		— optional; For cases where disambiguation (typically of the show's origin country) before the season type is required
 											(e.g. the season qualifier for The Apprentice (American season 2) is American).
 	-- |season_type=			— optional; To determine the usage of the word &quot;season&quot; for American-based shows, or &quot;series&quot; for shows using British-English.
 	-- |season_number=			— optional; Season number. The N season of this particular show. 
 --]]
 local function makeInvokeFunc(funcName)
 	return function (frame)
 		local args = getArgs(frame)
 		return p[funcName](args)
 	end
 end
 
 p.checkNextSeason = makeInvokeFunc('_checkNextSeason')
 
 --[[
 Public function which is used to check if the next season has
 a created article or redirect.
 
 Parameters: See makeInvokeFunc() for documentation.
 --]]
 function p._checkNextSeason(args)
 	local articleName = createNextSeasonArticle(args)
 	return checkArticle(articleName)
 end
 
 p.checkPrevSeason = makeInvokeFunc('_checkPrevSeason')
 
 --[[
 Public function which is used to check if the previous season has
 a created article or redirect.
 
 Parameters: See makeInvokeFunc() for documentation.
 --]]
 function p._checkPrevSeason(args)
 	local articleName = createPreviousSeasonArticle(args)
 	return checkArticle(articleName)
 end
 
 p.checkAll = makeInvokeFunc('_checkAll')
 
 --[[
 Public function which is used to check if the next or previous season have
 a created article or redirect.
 
 Parameters: See makeInvokeFunc() for documentation.
 --]]
 function p._checkAll(args)
 	if (p._checkPrevSeason(args) == &quot;true&quot;) then
 		return &quot;true&quot;
 	else
 		return p._checkNextSeason(args)
 	end
 end
 
 p.getNextSeasonArticle = makeInvokeFunc('_getNextSeasonArticle')
 
 --[[
 Public function which is used to get the next season article title.
 
 Parameters: See makeInvokeFunc() for documentation.
 --]]
 function p._getNextSeasonArticle(args)
 	local articleTitle = createNextSeasonArticle(args)
 	return createArticleTitleWithPipedLink(articleTitle)
 end
 
 p.getPrevSeasonArticle = makeInvokeFunc('_getPrevSeasonArticle')
 
 --[[
 Public function which is used to get the previous season article title.
 
 Parameters: See makeInvokeFunc() for documentation.
 --]]
 function p._getPrevSeasonArticle(args)
 	local articleTitle = createPreviousSeasonArticle(args)
 	return createArticleTitleWithPipedLink(articleTitle)
 end