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 17:26, 20 September 2018. 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 = {}

function p.getFormmatedArticleLink(frame)
	local articleName = frame.args[1]													-- Get the article name.
	local isParenthesesPartOfTitle = frame.args[2]										-- Get the "yes"/"no" value.
	
	local newStylizedArticleName														-- Variable to save new stylized article name.
	local hasDisambiguation																-- Variable to save status of if the article is disambiguated or not.
		
	if (isParenthesesPartOfTitle == "yes") then											-- Check if the parentheses is part of the episode title.
		stylizedArticleName = "\"" .. articleName .. "\""								-- Add qutoation marks for the title per [[MOS:QUOTETITLE]].
		hasDisambiguation = false														-- Set disambiguation to false.
	end

	local disambiguation = string.match(articleName, "%s%((.-)%)")						-- Get the text inside the disambiguation parentheses.

	if not disambiguation then															-- Check if the article name does not have disambiguation parentheses.
		stylizedArticleName = "\"" .. articleName .. "\""								-- Add qutoation marks for the title per [[MOS:QUOTETITLE]].
		hasDisambiguation = false														-- Set disambiguation to false.
	else																				-- Article has disambiguation.
		local articleTitle = string.gsub(articleName, "%s+%b()$", "", 1, false)			-- Get the article title without the disambiguation.
		local stylizedArticleTitle = "\"" .. articleTitle .. "\""						-- Add qutoation marks to the title per [[MOS:QUOTETITLE]].
		hasDisambiguation = true														-- Set disambiguation to true.
		
		local isDisambiguationExtended = string.find(disambiguation, "episode")			-- Check if the article name has extended disambiguation with the word "episode".
		local stylizedDisambiguation													-- Variable to save new stylized disambiguation.
		
		if not isDisambiguationExtended then											-- Article does not have extended disambiguation.
			stylizedDisambiguation = "(''" .. 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.
			stylizedDisambiguation = "(''" .. 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.
		
		stylizedArticleName = stylizedArticleTitle .. " " .. stylizedDisambiguation		-- Recreate the article name from the title and disambiguation.
    end
    
    local formattedArticleLink															-- Variable to save new formmated article link.
    
    if (hasDisambiguation) then															-- Check if the article is disambiguated.
    	    formattedLink = "[[" .. articleName .. "|" .. stylizedArticleName .. "]]"	-- The article is disambiguated; Create a pipped link.
    	else
    		formattedLink = "[[" .. stylizedArticleName .. "]]"							-- The article is not disambiguated; Create a normal link.
    return formattedLink																-- Return formmated link.
    end
end

return p