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

Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1:
require('strict')
local match = require("Module:String")._match
 
Line 37 ⟶ 38:
local function getCurrentSeasonNumberFromDisambiguation(disambiguation)
return match(disambiguation , "%d+", 1, -1, false, "")
end
 
--- Returns the type of word used for "season" in the title.
---
--- The returned value can be one of three options: "season", "series", "story arc" or "specials".
--- @param title string The article's title.
--- @return string
local function getSeasonType(title)
for _, seasonType in pairs({"season", "series", "story arc", "specials"}) do
if string.find(title, seasonType) then
return seasonType
end
end
return "season"
end
 
--- Returns the season number from the title.
--- @param title string The article's title.
--- @return string | nil
local function getSeasonNumber(title)
return match(title , "%d+", 1, -1, false, "")
end
 
Line 44 ⟶ 66:
local function getDisambiguation(title)
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation and disambiguation == "" then
return nil
end
Line 54 ⟶ 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
 
--- Returns the type of word used for "season" in the title.
---
--- The returned value can be one of three options: "season", "series", "story arc" or "specials".
--- @param title string The article's title.
--- @return string
local function getSeasonType(title)
seasonTypes = {"season", "series", "story arc", "specials"}
for _, seasonType in pairs(seasonTypes) do
if string.find(getTitleWithoutDisambiguation(title), seasonType) then
return seasonType
end
end
-- Since rare cases exist such as "Doctor Who (2008–2010 specials)" and "Ben 10: Omniverse (story arc 1)"
-- if the default season type "season" is used at this point, do an extra validation to make sure the dismabiguation isn't used for these titles.
local disambiguation = getDisambiguation(title)
if disambiguation then
for _, seasonType in pairs(seasonTypes) do
if string.find(disambiguation, seasonType) then
return seasonType
end
end
end
 
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 getSeasonNumberNew(title)
return match(title , "%d+", 1, -1, false, "")
end
 
Line 147 ⟶ 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 203 ⟶ 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 211 ⟶ 197:
local function getArticleTitleAndPipedLink(title, seasonNumberDiff)
local seasonType = getSeasonType(title)
local seasonNumber = getSeasonNumberNewgetSeasonNumber(title)
if tonumber(seasonNumber) == nil then
return "", nil
Line 217 ⟶ 203:
seasonNumber = seasonNumber + seasonNumberDiff
local modifiedTitle = string.gsub(title, "%d+$", seasonNumber)
local pipedLink = seasonType:gsub("^%l", string.upper) .. " " .. seasonNumber
 
local disambiguation = getDisambiguation(title)
 
-- Titles such as "Big Brother 2 (American season) and Teenage Mutant Ninja Turtles (1987 TV series) season 2".
if disambiguation then
Line 233 ⟶ 218:
 
-- 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
 
Line 248 ⟶ 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 319 ⟶ 307:
function p.getSeasonWord(frame)
local title = getTitle(frame)
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)
titleNoDablocal titleWithoutDisambiguation = getTitleWithoutDisambiguation(title)
seasonNumber = getSeasonNumberNewgetSeasonNumber(titleNoDabtitleWithoutDisambiguation)
seasonType = getSeasonType(titletitleWithoutDisambiguation)
-- For pages like "Doctor Who specials (2008–2010)".
--TODO: need to check where this is used
if seasonType == "specials" then
returnlocal disambiguation = getDisambiguation(title) or ""
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