Module:Infobox television season name/sandbox2: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1:
require('strict')
local match = require("Module:String")._match
 
Line 52 ⟶ 53:
return "season"
end
 
--TODO: validate this works
--Space after series name
--The Simpsons season 8
--Hawaii Five-0 (2010 TV series) season 10
--Dancing with the Stars (South Korean TV series) season 3
 
--- Returns the season number from the title.
--- @param title string The article's title.
--- @return string | nil
local function getSeasonNumberNewgetSeasonNumber(title)
ifreturn string.findmatch(title , "season%d+"), or1, string.find(title-1, false, "series") then
end
return match(title , "%d+", 1, -1, false, "")
 
--- Returns the disambiguation from the title.
--- @param title string The article's title.
--- @return string | nil
local function getDisambiguation(title)
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation and disambiguation == "" then
return nil
end
return nildisambiguation
end
 
Line 73 ⟶ 76:
--- @return string | nil
local function getTitleWithoutDisambiguation(title)
local disambiguation = matchgetDisambiguation(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation ~= "" then
return string.gsub(title, "%(" .. disambiguation .. "%)", "")
end
return title
end
 
--TODO: keep for now
local function getDisambiguation(title)
return match(title, "%s%((.-)%)", 1, -1, false, "")
end
 
Line 131 ⟶ 129:
--- @return string
local function getShowName(title)
local name, _ = mw.ustring.gsub(title, "season %s+%b()d*$", "")
name, _ = mw.ustring.gsub(name, "series %d*$", "")
name, _ = mw.ustring.gsub(name, "specials", "")
name, _ = mw.ustring.gsub(name, "story arc %d*$", "")
name = string.match(name, "^%s*(.-)%s*$") -- Trim spaces.
return name
end
Line 187 ⟶ 189:
--- -- Style: <showName> (<year> TV series) <seasonType> <seasonNumber>
--- Example: Love Island (2015 TV series) series 2
--- -- Style: <showName> (<country> <seasonType>) -- TODO: how will this look?
--- Example: Big Brother 2 (American season).
 
Line 194 ⟶ 196:
--- @return string, string
local function getArticleTitleAndPipedLink(title, seasonNumberDiff)
local disambiguationseasonType = getDisambiguationgetSeasonType(title)
local seasonNumber = getSeasonNumber(title)
local shortDisambiguation
local seasonType
local seasonNumber
local pipedLink = ""
 
if disambiguation then
seasonType = getSeasonType(title)
seasonNumber = getSeasonNumberNew(title)
pipedLink = seasonType:gsub("^%l", string.upper) .. " "
end
 
local showName = getShowName(title)
local showNameModified
if not seasonNumber or seasonNumber == "" then
-- Not a valid next/prev season link.
if not string.match(showName, "%s+(%d+)$") then
return "", nil
end
showNameModified, seasonNumber = getShowNameAndSeasonNumberFromShowName(showName)
end
 
if tonumber(seasonNumber) == nil then
return "", nil
end
 
seasonNumber = seasonNumber + seasonNumberDiff
pipedLinklocal modifiedTitle = pipedLink .string.gsub(title, "%d+$", seasonNumber)
local pipedLink = seasonType:gsub("^%l", string.upper) .. " " .. seasonNumber
 
local disambiguation = getDisambiguation(title)
-- Titles such as "Big Brother 1 (American season)".
-- Titles such as "Big Brother 2 (American season) and Teenage Mutant Ninja Turtles (1987 TV series) season 2".
if showNameModified and disambiguation then
if disambiguation then
return showNameModified .. " " .. seasonNumber .. " (" .. disambiguation .. ")", pipedLink
local titleWithoutDisambiguation = string.gsub(title, disambiguation, "_DAB_")
modifiedTitle = string.gsub(titleWithoutDisambiguation, "%d+", seasonNumber)
modifiedTitle = string.gsub(modifiedTitle, "_DAB_", disambiguation)
return modifiedTitle, pipedLink
 
-- Titles such as "Big Brother Brasil 12".
elseif showNameModifiednot string.find(title, seasonType) then
return showNameModified .. " " .. seasonNumbermodifiedTitle, nil
 
-- Invalid usages of TV series articles with the television season infobox.
elseif disambiguation and string.find(disambiguation, "TV series") and not (string.find(disambiguation, ", season") or string.find(disambiguation, ", series")) then
return "", nil
 
-- Standard titles such as "Lost (season 1)".
-- Standard titles such as "Lost season 1".
else
return modifiedTitle, pipedLink
local newDisambiguation, _ = string.gsub(disambiguation, "%d+$", seasonNumber)
return showName .. " (" .. newDisambiguation .. ")", pipedLink
end
end
Line 247 ⟶ 233:
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
if args.italic_title then
return "no"
end
local title = args.title
 
if not title then
title = mw.title.getCurrentTitle().text
Line 320 ⟶ 309:
title = getTitleWithoutDisambiguation(title)
local seasonType = getSeasonType(title)
ifreturn seasonType == "specials" then
end
seasonType = "season"
 
--- Returns an {{Italic title}} instance if title qualifies or a blank string.
 
--- @param frame table
--- @return string
function p.getItalicTitle(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
-- If italic_title is set then "no" is the only valid value.
-- Don't set an italic title.
if args.italic_title then
return ""
end
 
local title = getTitle(frame)
return seasonType
title = getShowName(getTitleWithoutDisambiguation(title))
 
-- If the infobox is used on List of articles don't set an italic title.
-- TODO: this can be fixed in the future but current usages use a manual display title.
if string.find(title, "List of") then
return ""
end
 
return frame:expandTemplate{title = "Italic title", args = {string = title}}
end
 
--- Returns the text used for the |above= field of the infobox.
---
--- @param frame table
--- @return string
function p.getAboveTitle(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local title = getTitle(frame)
title = getShowName(getTitleWithoutDisambiguation(title))
return title
end
 
--- Returns the relevant text used for the sub-header|subheader= field of the infobox.
---
--- The text is returned in the format of "Season #" or "Series #",
Line 333 ⟶ 356:
--- @param frame table The frame invoking the module.
--- @return string | nil
function p.getInfoboxSubHeadergetSubHeader(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
Line 349 ⟶ 372:
if not seasonNumber then
local title = getTitle(frame)
titlelocal titleWithoutDisambiguation = getTitleWithoutDisambiguation(title)
seasonNumber = getSeasonNumberNewgetSeasonNumber(titletitleWithoutDisambiguation)
seasonType = getSeasonType(titletitleWithoutDisambiguation)
-- For pages like "Doctor Who specials (2008–2010)".
--TODO: need to check where this is used
if seasonType == "specials" then
local disambiguation = getDisambiguation(title) or ""
return shortDisambiguation
return disambiguation .. " " .. seasonType
end
seasonType = seasonType:sub(1, 1):upper() .. seasonType:sub(2)
Line 390 ⟶ 414:
 
local title = getTitle(frame)
local showName = getShowName(getTitleWithoutDisambiguation(title))
 
if showName then
local disambiguation = getDisambiguation(title)
if disambiguation then
local TVProgramDisambiguation = getTVProgramDisambiguation(disambiguation)
disambiguation = " (" .. disambiguation .. ")"
local listOfEpisodesArticle = string.format("List of %s%s episodes", showName, TVProgramDisambiguation)
end
local listOfEpisodesArticle = string.format("List of %s%s episodes", showName, disambiguation or "")
return getListOfEpisodesLink(listOfEpisodesArticle)
end