Khác biệt giữa bản sửa đổi của “Mô đun:Infobox television season name”

Nội dung được xóa Nội dung được thêm vào
Không có tóm lược sửa đổi
Thẻ: Đã bị lùi lại
n Đã lùi lại sửa đổi của Thienhau2003 (Thảo luận) quay về phiên bản cuối của Phjtieudoc
Thẻ: Lùi tất cả
Dòng 1:
-- This module requires the use of Module:Arguments.
local match = require("Module:String")._match
local getArgs = require('Module:Arguments').getArgs
 
local pipedLink = ""
 
local p = {}
 
-- Local function which is used to create an pipped article link.
--[[
Locallocal function which is used to create an pipped createArticleTitleWithPipedLink(article link.)
--]]
local function createArticleTitleWithPipedLink(article, pipedLink)
if (pipedLink == nil or pipedLink == "") then
return "[[" .. article .. "]]"
else
return "[[" .. article .. "|" .. pipedLink .. "]]"
end
end
 
--[[
Local helper function which is used to get the current season number and modified show name
from the show name.
--]]
local function getModifiedShowNameAndCurrentSeasonNumberFromShowName(showName)
local _, _, showNameModified, seasonNumber = string.find(showName, "(.*)%s+(%d+)")
return showNameModified, seasonNumber
end
 
--[[
Local helper function which is used to get the current season number from the disambiguation.
--]]
local function getCurrentSeasonNumberFromDisambiguation(shortDisambiguation)
return match(shortDisambiguation , "%d+", 1, -1, false, "")
end
 
--[[
Local helper function which is used to get the type of word used for "season"
in the disambiguation.
 
Returns one of three options: "season", "series" or "story arc".
--]]
local function getSeasonType(shortDisambiguation)
if (string.find(shortDisambiguation, "story arc")) then
return "story arc"
end
 
if (string.find(shortDisambiguation, "series")) then
return "series"
end
 
return "season"
end
 
--[[
Local helper function which is used to get the short disambiguation,
without the "(year) TV series," part, which can cause issues later on.
--]]
local function getShortDisambiguation(disambiguation)
return string.gsub(disambiguation, "%d+ TV series, ", "")
end
 
--[[
Local helper function which is used to get the disambiguation from the title.
--]]
local function getDisambiguation(title)
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if (disambiguation == "") then
return nil
else
return disambiguation
end
end
 
--[[
Local helper function which is used to get the show name from the title.
--]]
local function getShowName(title)
return mw.ustring.gsub(title, "%s+%b()$", "")
end
 
Hàng 85 ⟶ 25:
-- A redirect exists, but it is a general redirect and not for any specific season section.
]]--
local function checkArticle(articleTitlearticleName)
local article = mw.title.new(articleTitlearticleName)
if (article ~= nil and article.exists) then
local redirectTarget = article.redirectTarget
Hàng 106 ⟶ 46:
 
--[[
Local function which returnsis aused seasonto articlecreate titlea andTV a pipedseason link.
 
The following are the supported season naming styles:
-- <showName> (<seasonQualifier> <seasonType>)
Example: Big Brother 1 (U.S. season).
-- <showName> (<seasonType> <seasonNumber>)
Example: Lost (season 23).
-- <showName> (<countryseasonQualifier> <seasonType> <seasonNumber>)
Example: The OfficeFlash (American2014 season 23).
-- <showName> <preSeasonQualifier> (<seasonType> <seasonNumber>)
Example: X Factor (British series 2).
Example: Dallas (1978 TV series) (season 3).
-- <showName> (<country> <seasonType>)
-- <showName> <preSeasonQualifier> (<seasonQualifier> <seasonType> <seasonNumber>)
Example: Big Brother 2 (American season).
Example: No current example.
-- <showName> (<year> TV series, <seasonType> <seasonNumber>)
-- <showName> (<preSeasonQualifier>, <seasonType> <seasonNumber>) - TODO
Example: Teenage Mutant Ninja Turtles (1987 TV series, season 2)
--Example: <showName>Teenage Mutant Ninja Turtles (<country>1987 TV series, <seasonType>season <seasonNumber>1)
Example: Love Island (British TV series, series 2)
--]]
local function getArticleTitlecreateLink(titleargs, prevOrNextSeasonNumber)
local showName = getShowName(title)args[1] or args['show_name']
if (showName == nil) then
local disambiguation = getDisambiguation(title)
return ""
end
showName = showName .. " "
local shortDisambiguation
 
local seasonType
local preSeasonQualifier = args[2] or args['pre_season_qualifier']
local seasonNumber = ""
if (preSeasonQualifier == nil) then
local pipedLink = ""
preSeasonQualifier = ""
if (disambiguation) then
else
shortDisambiguation = getShortDisambiguation(disambiguation)
preSeasonQualifier = preSeasonQualifier .. " "
seasonType = getSeasonType(shortDisambiguation)
end
seasonNumber = getCurrentSeasonNumberFromDisambiguation(shortDisambiguation)
pipedLink = seasonType:gsub("^%l", string.upper) .. " "
local seasonQualifier = args[3] or args['season_qualifier']
if (seasonQualifier == nil) then
seasonQualifier = ""
else
seasonQualifier = seasonQualifier .. " "
end
local seasonType = args[4] or args['season_type']
if (seasonType == nil) then
seasonType = "season"
end
 
local realitySeriesStyle = false
local showNameModified
iflocal (seasonNumber == "")args[5] or thenargs['season_number']
if (seasonNumber == nil) then
if (string.match(showName , "%s+(%d+)")) then
_, _, showNameModified, seasonNumber = getModifiedShowNameAndCurrentSeasonNumberFromShowNamestring.find(showName, "(.*)%s+(%d+)")
realitySeriesStyle = true
else
return "" -- Not a valid next/prev season link
end
end
 
if (tonumber(seasonNumber) == nil) then
return ""
else
seasonNumber = seasonNumber + prevOrNextSeasonNumber
pipedLink = pipedLinkseasonType:gsub("^%l", string.upper) .. " " .. seasonNumber
-- Titles such as "Big Brother 1 (American season)""
if (showNameModified and disambiguationrealitySeriesStyle) then
return showNameModified .. " " .. seasonNumber .. " (" .. disambiguationseasonQualifier .. seasonType .. ")", pipedLink
 
-- Titles such as "Big Brother Brasil 1"
elseif (showNameModified) then
return showNameModified .. " " .. seasonNumber, nil
-- Standard titles such as "Lost (season 1)"
else
return showName .. preSeasonQualifier .. "(" .. seasonQualifier .. seasonType .. " " .. seasonNumber .. ")"
disambiguation = string.gsub(disambiguation, "%d+$", seasonNumber)
return showName .. " (" .. disambiguation .. ")", pipedLink
end
end
end
 
-- Local function which is called to create a TV season link for the next season.
--[[
-- Passes the value "1" to increment the current season number.
Local helper function which is used to get the title,
local function createNextSeasonArticle(args)
either from args (usually from /testcases) or from the page itself.
return createLink(args, 1)
--]]
local function getTitle(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
local title = args.title
if (not title) then
title = mw.title.getCurrentTitle().text
end
 
return title
end
 
-- Local function which is called to create a TV season link for the previous season.
--[[
-- Passes the value "-1" to decrement the current season number.
Local helper function which is called to create a TV season title for the next or previous season.
local function createPreviousSeasonArticle(args)
Passes the value "1" or -1" to increment or decrement the current season number.
return createLink(args, -1)
--]]
local function createArticleTitleHelper(frame, number)
local title = getTitle(frame)
return getArticleTitle(title, number)
end
 
--[[
Local helperWrapper function which is used tohandles checkthe ifprocessing aof seasonthe articlearguments exists.
from multiple public invoked functions.
--]]
local function checkSeason(frame, number)
local articleTitle = createArticleTitleHelper(frame, number)
return checkArticle(articleTitle)
end
 
Parameters:
--[[
-- |show_name= — required; The title of TV program.
Local helper function which is used to create a season article link.
-- |pre_season_qualifier= — optional; For cases where disambiguation before the season is required
(e.g. the pre-season qualifier for Dallas (1978 TV series) (season 7) is (1978 TV series)).
-- |season_qualifier= — optional; For cases where disambiguation (typically of the show's origin country) before the season type is required
(e.g. the season qualifier for The Apprentice (U.S. season 2) is U.S.).
-- |season_type= — optional; To determine the usage of the word "season" for American-based shows, or "series" for shows using British-English.
-- |season_number= — optional; Season number. The N season of this particular show.
--]]
local function getSeasonArticleLinkmakeInvokeFunc(frame, numberfuncName)
return function (frame)
local articleTitle, pipedLink = createArticleTitleHelper(frame, number)
local args = getArgs(frame)
return createArticleTitleWithPipedLink(articleTitle, pipedLink)
return p[funcName](args)
end
end
 
p.checkNextSeason = makeInvokeFunc('_checkNextSeason')
 
--[[
Public function which is used to check if the next season has
a valid created article or redirect.
 
Parameters: See makeInvokeFunc() for documentation.
--]]
function p.checkNextSeason_checkNextSeason(frameargs)
local articleName = createNextSeasonArticle(args)
return checkSeason(frame, 1)
return checkArticle(articleName)
end
 
p.checkPrevSeason = makeInvokeFunc('_checkPrevSeason')
 
--[[
Public function which is used to check if the previous season has
a validcreated article or redirect.
 
Parameters: See makeInvokeFunc() for documentation.
--]]
function p.checkPrevSeason_checkPrevSeason(frameargs)
local articleName = createPreviousSeasonArticle(args)
return checkSeason(frame, -1)
return checkArticle(articleName)
end
 
p.checkAll = makeInvokeFunc('_checkAll')
 
--[[
Public function which is used to check if the next or previous season have
a validcreated article or redirect.
 
Parameters: See makeInvokeFunc() for documentation.
--]]
function p.checkAll_checkAll(frameargs)
if (p.checkPrevSeason_checkPrevSeason(frameargs) == "true") then
return "true"
else
return p.checkNextSeason_checkNextSeason(frameargs)
end
end
 
p.getNextSeasonArticle = makeInvokeFunc('_getNextSeasonArticle')
 
--[[
Public function which is used to get the next season article title.
 
Parameters: See makeInvokeFunc() for documentation.
--]]
function p.getNextSeasonArticle_getNextSeasonArticle(frameargs)
local articleTitle = createNextSeasonArticle(args)
return getSeasonArticleLink(frame, 1)
return createArticleTitleWithPipedLink(articleTitle)
end
 
p.getPrevSeasonArticle = makeInvokeFunc('_getPrevSeasonArticle')
 
--[[
Public function which is used to get the previous season article title.
--]]
function p.getPrevSeasonArticle(frame)
return getSeasonArticleLink(frame, -1)
end
 
Parameters: See makeInvokeFunc() for documentation.
--[[
Public function which is used to get the type of season word used - "season" or "series".
--]]
function p.getSeasonWord_getPrevSeasonArticle(frameargs)
local titlearticleTitle = getTitlecreatePreviousSeasonArticle(frameargs)
return createArticleTitleWithPipedLink(articleTitle)
local disambiguation = getDisambiguation(title)
if (disambiguation) then
local shortDisambiguation = getShortDisambiguation(disambiguation)
return getSeasonType(shortDisambiguation)
else
return ""
end
end
 
--[[
Public function which is used to return the relevant text for the sub-header field.
The text is returned in the format of <code>Season #</code> or <code>Series #</code>,
depending on either what the article disambiguation uses, or on manually entered parameters of the infobox.
--]]
function p.getInfoboxSubHeader(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
 
local seasonType
local seasonNumber
if (args.season_number) then
seasonType = "Season"
seasonNumber = args.season_number
elseif (args.series_number) then
seasonType = "Series"
seasonNumber = args.series_number
end
 
local title = getTitle(frame)
local showName = getShowName(title)
local disambiguation = getDisambiguation(title)
if (not seasonNumber and disambiguation) then
local shortDisambiguation = getShortDisambiguation(disambiguation)
 
seasonType = getSeasonType(shortDisambiguation)
seasonType = seasonType:sub(1, 1):upper() .. seasonType:sub(2)
seasonNumber = getCurrentSeasonNumberFromDisambiguation(shortDisambiguation)
end
 
if (seasonNumber and seasonNumber ~= "") then
return seasonType .. " " .. seasonNumber
end
return nil
end
 
--[[
Public function which is used to return the formatted link
to the list of episodes article in the style of:
[List of <series name> <disambiguation if present> episodes <seasons if present>|List of ''<series name>'' episodes <seasons if present>]
 
The link will only return if the page exists.
--]]
function p.getListOfEpisodes(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
 
local listRange = ""
local title = getTitle(frame)
local showName
local disambiguation
 
if (args.link) then
-- Parameter should be unformatted.
if (string.find(args.link, "%[")) then
local delink = require('Module:Delink')._delink
args.link = delink({args.link})
end
 
-- Get the season or year range if present.
-- Examples:
-- List of The Simpsons episodes (seasons 1–20) will return '(seasons 1–20)'.
-- List of Doctor Who episodes (2005–present) will return '(2005–present)'.
listRange = args.link:match('episodes(.*)$') or ""
 
-- Get the series name with disambiguation.
local seriesNameWithDisambiguation = args.link:match('List of (.*) episodes')
 
if (seriesNameWithDisambiguation) then
showName = getShowName(seriesNameWithDisambiguation)
disambiguation = getDisambiguation(seriesNameWithDisambiguation)
end
 
else
showName = getShowName(title)
disambiguation = getDisambiguation(title)
end
 
if (disambiguation) then
if string.match(disambiguation, "^season %d*$") or string.match(disambiguation, "^series %d*$") then
-- Check if the disambiguation is normal 'season #' or 'series #'.
-- If so, remove disambiguation.
disambiguation = ""
elseif (string.find(disambiguation, "TV series")) then
-- Check if the disambiguation is extended
-- and has 'TV series' and isn't just season #.
-- Only leave the TV series disambiguation, not including the season #.
-- Example: Teenage Mutant Ninja Turtles (1987 TV series, season 55) will return '1987 TV series'.
disambiguation = disambiguation:match('^(.*),') or disambiguation
disambiguation = string.format(" (%s)", disambiguation)
else
-- Check if the disambiguation is extended with country adjective.
-- Example: The Office (American season 2) will return "American season 2".
-- Keep only country adjective.
local countryDisambiguation = disambiguation:match('^(.*) season %d*') or disambiguation:match('^(.*) series %d*')
local data = mw.loadData('Module:Country adjective')
local valid_result = data.getCountryFromAdj[countryDisambiguation]
-- Check if the country adjective is valid.
if (valid_result) then
-- Add 'TV series' suffix
disambiguation = string.format(" (%s)", countryDisambiguation .. ' TV series')
else
-- Not a known diambiguation style. Use whatever was used in the title or manually added.
-- Note: might not be a valid style link.
disambiguation = string.format(" (%s)", disambiguation)
end
end
else
disambiguation = ""
end
 
if (showName) then
local episodeListArticle = "List of %s%s episodes%s"
episodeListArticle = episodeListArticle:format(showName, disambiguation, listRange)
local episodeListArticlePage = mw.title.new(episodeListArticle, 0)
 
if (episodeListArticlePage.exists and episodeListArticlePage.redirectTarget ~= mw.title.getCurrentTitle()) then
local episodeList = "[[%s|List of ''%s'' episodes%s]]"
episodeList = episodeList:format(episodeListArticle, showName, listRange)
return episodeList
end
end
end