Jump to content

Module:Television episode disambiguation description

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 22:04, 26 September 2018 (testing). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- Do not add a style which is not supported by the [[WP:NCTV]] guidelines.

local p = {}

-- Local function used to create the stylized article disambiguation.
local function getStylizedDisambiguation(disambiguation)
	local isDisambiguationExtended = string.find(disambiguation, "episode")				-- Search for the word "episode" in the article name disambiguation.
	
	if not isDisambiguationExtended then												-- Check if the article name has extended disambiguation.
		return "(''" .. disambiguation .. "'')"											-- Article does not have extended disambiguation; 
																						-- Add italics to the disambiguation which should only be the TV series name per [[MOS:ITALICTITLE]] and [[WP:NCTV]].
	else																				-- Articles has extended disambiguation;
		local tvSeries = string.gsub(disambiguation, "episode", "", 1, true)			-- Get the TV series name without the extended disambiguation.
		return "(''" .. tvSeries .. "'' episode)"										-- Add italics to the disambiguation which should only be the TV series name per [[MOS:ITALICTITLE]] and [[WP:NCTV]]; 
	end																					-- and add back the extended disambiguation.

end

-- Local function used to create the stylized article title.
local function getStylizedArticleTitle(articleName)
	local articleTitle = string.gsub(articleName, "%s+%b()$", "", 1, false)				-- Get the article title without the disambiguation.
	return "\"" .. articleTitle .. "\""													-- Add quotation marks to the title per [[MOS:QUOTETITLE]].
end

-- Local function used to get the disambiguated formatted episode link.
local function getDisambiguatedFormattedLink(articleName)
	local disambiguation = string.match(articleName, "%s%((.-)%)")						-- Get the text inside the disambiguation parentheses.
	local stylizedArticleName															-- Variable to save new stylized article name.
	
	if not disambiguation then															-- Check if the article name does not have disambiguation parentheses.
		stylizedArticleName = "\"" .. articleName .. "\""								-- Article does not have disambiguation parentheses; Add quotation marks for the title per [[MOS:QUOTETITLE]].
	else																				-- Article has disambiguation parentheses;
		local stylizedArticleTitle = getStylizedArticleTitle(articleName)				-- Call getStylizedArticleTitle() to get the stylized article title.
		local stylizedDisambiguation = getStylizedDisambiguation(disambiguation)		-- Call getStylizedDisambiguation() to get the stylized disambiguation.
		stylizedArticleName = stylizedArticleTitle .. " " .. stylizedDisambiguation		-- Recreate the article name from the title and disambiguation.
	end
	
	return "[[" .. articleName .. "|" .. stylizedArticleName .. "]]"					-- Create a pipped link and return it.
end

-- Local function used to process the value of 'parenthesesPartOfTitle'.
local function isParenthesesPartOfTitle(parenthesesPartOfTitle)
	
	if (parenthesesPartOfTitle:lower() == "yes" or										-- Check if the value equals "yes".
		parenthesesPartOfTitle:lower() == "true") then									-- Check if the value equals "true".
		return true																		-- It is; Parentheses is part of the title; Return true.
	else																				-- Anything else - empty string or "no".
		return false																	-- Parentheses is not part of the title; Return false.
	end
	
end

-- Public function used to create a formatted episode link.
function p.getFormmatedArticleLink(frame)
	local articleName = frame.args[1]													-- Get the article name.
	local parenthesesPartOfTitle = frame.args[2]										-- Get the optional "yes"/"no" value.
	
	local formattedLink																	-- Variable to save the formatted link.

	if (isParenthesesPartOfTitle(parenthesesPartOfTitle) == true) then					-- Call isParenthesesPartOfTitle() to check if the parentheses is part of the episode title.
		formattedLink = "\"[[" .. articleName .. "]]\""									-- Parentheses is part of the title; Add quotation marks for the title per [[MOS:QUOTETITLE]].
	else																				-- Parentheses is not part of the title; 
		formattedLink = getDisambiguatedFormattedLink(articleName)						-- Call getDisambiguatedFormmatedLink() to get the disambiguated formatted episode link.
	end

    return formattedLink																-- Return the formmated link.
end

function p.getShortDescription(frame)
	local articleName = frame.args[1]
	local shortDescription = string.match(mw.title.new('Abraham Lincoln'):getContent(), '{{ *short +description *| *([^}]+) *}}')
	return shortDescription
end

return p