<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ATelevision_episode_disambiguation_description%2Fsandbox</id>
	<title>Module:Television episode disambiguation description/sandbox - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ATelevision_episode_disambiguation_description%2Fsandbox"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Television_episode_disambiguation_description/sandbox&amp;action=history"/>
	<updated>2026-05-24T17:07:37Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Television_episode_disambiguation_description/sandbox&amp;diff=147200&amp;oldid=prev</id>
		<title>imported&gt;Gonnym at 19:38, 17 January 2020</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Television_episode_disambiguation_description/sandbox&amp;diff=147200&amp;oldid=prev"/>
		<updated>2020-01-17T19:38:43Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Do not add a style which is not supported by the [[WP:NCTV]] guidelines.&lt;br /&gt;
&lt;br /&gt;
-- This module requires the use of Module:Extract short description.&lt;br /&gt;
local extract = require(&amp;#039;Module:Extract short description&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
-- Release version template list.&lt;br /&gt;
local releaseTemplates = {&lt;br /&gt;
	&amp;#039;Infobox television episode&amp;#039;,&lt;br /&gt;
	&amp;#039;Infobox Television episode&amp;#039;,&lt;br /&gt;
	&amp;#039;Television episode short description&amp;#039;,&lt;br /&gt;
	&amp;#039;Short description&amp;#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Disambiugation template list.&lt;br /&gt;
local disambiguationTemplateNameList = {&lt;br /&gt;
	&amp;#039;Disambiguation&amp;#039;,&lt;br /&gt;
	&amp;#039;Disambig&amp;#039;,&lt;br /&gt;
	&amp;#039;Dab&amp;#039;,	&lt;br /&gt;
	&amp;#039;Disamb&amp;#039;,&lt;br /&gt;
	&amp;#039;Disambiguation page&amp;#039;, -- 78, these should be converted.&lt;br /&gt;
	&amp;#039;DAB&amp;#039;, -- 55, these should be converted.&lt;br /&gt;
	&amp;#039;Disam&amp;#039;, -- 35, these should be converted.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Tracking category list. &lt;br /&gt;
local trackingCategoryList = {&lt;br /&gt;
	[1] = &amp;#039;[[Category:Television episode articles listed in disambiguation pages]]&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Local function used to check if the invoking page is a disambiguation page.&lt;br /&gt;
local function isInvokedFromDisambiguationPage(articleTitle)&lt;br /&gt;
	local content = mw.title.new(articleTitle):getContent();							-- Read the unparsed article source.&lt;br /&gt;
	&lt;br /&gt;
	for _, templateName in ipairs(disambiguationTemplateNameList) do					-- Loop through the template names in the list.&lt;br /&gt;
		local templateNamePattern&lt;br /&gt;
		templateNamePattern = templateName:gsub(&amp;#039;^%a&amp;#039;, string.lower)					-- If the first character of the template is an alpha character, make it lowercase: B → b.&lt;br /&gt;
		templateNamePattern = templateNamePattern:gsub(&amp;#039;^%a&amp;#039;, &amp;#039;%[%1%1%]&amp;#039;) 				-- If the first character of the template is an alpha character, make it a pair: b → bb and wrap the pair in set markup: bb → [bb].&lt;br /&gt;
		templateNamePattern = templateNamePattern:gsub(&amp;#039;%[%a&amp;#039;, string.upper)			-- If the first character of the template is &amp;quot;[&amp;quot; followed by an alpha character, make the alpha character uppercase: [bb] → [Bb].&lt;br /&gt;
&lt;br /&gt;
		local templateFound = content:find(&amp;#039;{{%s*&amp;#039; .. templateNamePattern)				-- Find the start of &amp;quot;{{template name ...&amp;quot;.&lt;br /&gt;
		if templateFound then&lt;br /&gt;
			return true																	-- A matching template was found; Return true.&lt;br /&gt;
		else&lt;br /&gt;
			return false																-- A matching template was not found; Return false.&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
	&lt;br /&gt;
-- Local function used to create the stylized article disambiguation.&lt;br /&gt;
local function getStylizedDisambiguation(disambiguation)&lt;br /&gt;
	local isDisambiguationExtended = string.find(disambiguation, &amp;quot;episode&amp;quot;)				-- Search for the word &amp;quot;episode&amp;quot; in the article name disambiguation (disambiguation is extended).&lt;br /&gt;
	&lt;br /&gt;
	if not isDisambiguationExtended then												-- Check if the article name has extended disambiguation.&lt;br /&gt;
		return &amp;quot;(&amp;#039;&amp;#039;&amp;quot; .. disambiguation .. &amp;quot;&amp;#039;&amp;#039;)&amp;quot;											-- Article does not have extended disambiguation; &lt;br /&gt;
																						-- Add italics to the disambiguation which should only be the TV series name per [[MOS:ITALICTITLE]] and [[WP:NCTV]].&lt;br /&gt;
	else																				-- Articles has extended disambiguation;&lt;br /&gt;
		local tvSeries = string.gsub(disambiguation, &amp;quot;episode&amp;quot;, &amp;quot;&amp;quot;, 1, true)			-- Get the TV series name without the extended disambiguation.&lt;br /&gt;
		tvSeries = mw.text.trim(tvSeries)												-- Remove trailing whitespaces.&lt;br /&gt;
		return &amp;quot;(&amp;#039;&amp;#039;&amp;quot; .. tvSeries .. &amp;quot;&amp;#039;&amp;#039; episode)&amp;quot;										-- Add italics to the disambiguation which should only be the TV series name per [[MOS:ITALICTITLE]] and [[WP:NCTV]]; &lt;br /&gt;
	end																					-- and add back the extended disambiguation.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Local function used to create the stylized article title.&lt;br /&gt;
local function getStylizedArticleTitle(articleName)&lt;br /&gt;
	local articleTitle = string.gsub(articleName, &amp;quot;%s+%b()$&amp;quot;, &amp;quot;&amp;quot;, 1, false)				-- Get the article title without the disambiguation.&lt;br /&gt;
	return &amp;quot;\&amp;quot;&amp;quot; .. articleTitle .. &amp;quot;\&amp;quot;&amp;quot;													-- Add quotation marks to the title per [[MOS:QUOTETITLE]].&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Local function used to get the disambiguated formatted episode link.&lt;br /&gt;
local function getDisambiguatedFormattedLink(articleName)&lt;br /&gt;
	local disambiguation = string.match(articleName, &amp;quot;%s%((.-)%)&amp;quot;)						-- Get the text inside the disambiguation parentheses.&lt;br /&gt;
&lt;br /&gt;
	if not disambiguation then															-- Check if the article name does not have disambiguation parentheses.&lt;br /&gt;
		return &amp;quot;\&amp;quot;[[&amp;quot; .. articleName .. &amp;quot;]]\&amp;quot;&amp;quot;											-- Article does not have disambiguation parentheses; Add quotation marks to the title per [[MOS:QUOTETITLE]] and return it.&lt;br /&gt;
	else																				-- Article has disambiguation parentheses;&lt;br /&gt;
		local stylizedArticleTitle = getStylizedArticleTitle(articleName)				-- Call getStylizedArticleTitle() to get the stylized article title.&lt;br /&gt;
		local stylizedDisambiguation = getStylizedDisambiguation(disambiguation)		-- Call getStylizedDisambiguation() to get the stylized disambiguation.&lt;br /&gt;
		local stylizedName = stylizedArticleTitle .. &amp;quot; &amp;quot; .. stylizedDisambiguation		-- Recreate the article name from the title and disambiguation.&lt;br /&gt;
		return &amp;quot;[[&amp;quot; .. articleName .. &amp;quot;|&amp;quot; .. stylizedName .. &amp;quot;]]&amp;quot;						-- Create a pipped link and return it.&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Local function used to create a formatted episode link.&lt;br /&gt;
local function getFormmatedArticleLink(articleName, parenthesesPartOfTitle)&lt;br /&gt;
	local formattedLink																	-- Variable to save the formatted link.&lt;br /&gt;
&lt;br /&gt;
	if (parenthesesPartOfTitle ~= nil) then												-- Check if the parentheses is part of the episode title.&lt;br /&gt;
		formattedLink = &amp;quot;\&amp;quot;[[&amp;quot; .. articleName .. &amp;quot;]]\&amp;quot;&amp;quot;									-- Parentheses is part of the title; Add quotation marks to the title per [[MOS:QUOTETITLE]].&lt;br /&gt;
	else																				-- Parentheses is not part of the title; &lt;br /&gt;
		formattedLink = getDisambiguatedFormattedLink(articleName)						-- Call getDisambiguatedFormmatedLink() to get the disambiguated formatted episode link.&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    return formattedLink																-- Return the formatted link.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Local function used to retrieve the short description&lt;br /&gt;
-- from an episode article&amp;#039;s template - either Template:Infobox television episode or Template:Short description.&lt;br /&gt;
-- See the table list for the complete template list.&lt;br /&gt;
local function getShortDescription(frame, articleName)&lt;br /&gt;
	local templatesTable = releaseTemplates;											-- Get the release version template list by default.&lt;br /&gt;
&lt;br /&gt;
	local shortDescription																-- Create a variable to store the short description.&lt;br /&gt;
	local descriptionFound																-- Create a variable to store the success result.&lt;br /&gt;
	shortDescription, descriptionFound = &lt;br /&gt;
	extract.extract_from_template(frame, articleName, templatesTable)					-- Call extract_from_template() from Module:Extract short description to get the short description.&lt;br /&gt;
		&lt;br /&gt;
	-- Currently this is redundant as it always returns the same item,&lt;br /&gt;
	-- however this is in place for future possibilities.&lt;br /&gt;
	if descriptionFound then															-- Check if a short description was found.&lt;br /&gt;
		shortDescription = shortDescription:gsub(&amp;quot;^%a&amp;quot;, string.lower)                   -- The description should start with a lowercase letter.&lt;br /&gt;
		return shortDescription															-- A short description was found; Return it.&lt;br /&gt;
	else&lt;br /&gt;
		return shortDescription															-- A short description was not found; Return the error message.&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Local function that does the actual main process.&lt;br /&gt;
local function _main(frame, articleName, parenthesesPartOfTitle, formattedLinkOnly)&lt;br /&gt;
	if (formattedLinkOnly ~= nil) then													-- Check if only a formatted link is needed.&lt;br /&gt;
	return getFormmatedArticleLink(articleName, parenthesesPartOfTitle)					-- Only a formatted link is needed; Call getFormmatedArticleLink() and return a formatted link.&lt;br /&gt;
																						-- TODO: this might need to use the same tracking category or a different one.&lt;br /&gt;
		&lt;br /&gt;
	else																				-- A complete entry is needed.&lt;br /&gt;
		local formattedLink = getFormmatedArticleLink(&lt;br /&gt;
			articleName, parenthesesPartOfTitle)										-- Call getFormmatedArticleLink() and return a formatted link.&lt;br /&gt;
		local shortDescription = getShortDescription(frame, articleName)				-- Call getShortDescription() and return the episode&amp;#039;s short description.&lt;br /&gt;
		&lt;br /&gt;
		local articleTitle = frame:getParent():getTitle()								-- Get the invoking article&amp;#039;s title.&lt;br /&gt;
		local invokedFromDisambiugation = isInvokedFromDisambiguationPage(articleTitle)	-- Call isInvokedFromDisambiguationPage() to check if the invoking page is a disambiugation page.&lt;br /&gt;
&lt;br /&gt;
		if invokedFromDisambiugation then												-- Check if the invoking page was a disambiugation page.&lt;br /&gt;
			return formattedLink .. &amp;quot;, &amp;quot; .. shortDescription .. trackingCategoryList[1]	-- Invoking page was a disambiugation page; Return a complete entry with a tracking category.&lt;br /&gt;
		else&lt;br /&gt;
			return formattedLink .. &amp;quot;, &amp;quot; .. shortDescription							-- Invoking page was not a disambiugation page; Return a complete entry without a tracking category.&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Local function used to create an error message.&lt;br /&gt;
local function getErrorMsg(errorMsg)&lt;br /&gt;
	return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: &amp;#039; .. errorMsg .. &amp;#039;.&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Public function used to create an entry for a television episode&lt;br /&gt;
-- in a disambiguation page.&lt;br /&gt;
-- The entry is in the form of: &amp;quot;&amp;lt;article name&amp;gt;&amp;quot;, &amp;lt;short description&amp;gt;&lt;br /&gt;
-- If set to &amp;quot;link_only&amp;quot;, only a formatted episode link will be returned.&lt;br /&gt;
-- See documentation for examples.&lt;br /&gt;
--&lt;br /&gt;
-- This module function takes three parameters:&lt;br /&gt;
--	{{{1}}} or |article= — required; The name of the episode&amp;#039;s article name.&lt;br /&gt;
--	|not_disambiguated= — optional; Set if the parentheses is part of the episode name.&lt;br /&gt;
--	|link_only= — optional; Set if you are only interested in getting a formatted article link.&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs;								-- Use Module:Arguments to access module arguments.&lt;br /&gt;
	local args = getArgs(frame);														-- Get the arguments sent via the template.&lt;br /&gt;
&lt;br /&gt;
	local articleName = args[&amp;quot;name&amp;quot;]													-- Get the article name.&lt;br /&gt;
	&lt;br /&gt;
	if (articleName == nil) then														-- Check if the article name was entered.&lt;br /&gt;
		return getErrorMsg(&amp;quot;an article title is required&amp;quot;)								-- No article name was entered; Call getErrorMsg() to create an error message and return it.&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local parenthesesPartOfTitle = args[&amp;quot;not_disambiguated&amp;quot;]							-- Get the optional value.&lt;br /&gt;
	local formattedLinkOnly = args[&amp;quot;link_only&amp;quot;]											-- Get the optional value.&lt;br /&gt;
&lt;br /&gt;
	return _main(frame, articleName, parenthesesPartOfTitle, formattedLinkOnly)			-- Call _main() to perform the actual process.&lt;br /&gt;
&lt;br /&gt;
end	&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Gonnym</name></author>
	</entry>
</feed>