Content deleted Content added
No edit summary |
No edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1:
require('strict')
local match = require("Module:String")._match
Line 52 ⟶ 53:
return "season"
end
--- Returns the season number from the title.
--- @param title string The article's title.
--- @return string | nil
local function
return match(title , "%d+", 1, -1, false, "")
end
--- 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
end
Line 73 ⟶ 76:
--- @return string | nil
local function getTitleWithoutDisambiguation(title)
local disambiguation =
if disambiguation
return string.gsub(title, "%(" .. disambiguation .. "%)", "")
end
return title
end
Line 131 ⟶ 129:
--- @return string
local function getShowName(title)
local name, _ = mw.ustring.gsub(title, "season %
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>)
--- Example: Big Brother 2 (American season).
Line 194 ⟶ 196:
--- @return string, string
local function getArticleTitleAndPipedLink(title, seasonNumberDiff)
local
local seasonNumber = getSeasonNumber(title)
if tonumber(seasonNumber) == nil then
return "", nil
end
seasonNumber = seasonNumber + seasonNumberDiff
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
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
elseif
return
-- 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".
else
return modifiedTitle, 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)
end
--- 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)
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
---
--- 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.
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
Line 349 ⟶ 372:
if not seasonNumber then
local title = getTitle(frame)
seasonNumber =
seasonType = getSeasonType(
-- For pages like "Doctor Who specials (2008–2010)".
if seasonType == "specials" then
local 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
disambiguation = " (" .. disambiguation .. ")"
end
local listOfEpisodesArticle = string.format("List of %s%s episodes", showName, disambiguation or "")
return getListOfEpisodesLink(listOfEpisodesArticle)
end
|