Jump to content

Module:Episode short description: Difference between revisions

Created page with "--- @module local television = {} --- someone who is good at lua and mediawiki please parse this and remove the --- part that adds maintenance categories if the series doesnt have a season number --- RLM doesnt do seasons -- Unique suffix list. local uniqueSuffix = { [1] = "st", [2] = "nd", [3] = "rd", } -- Common suffix. local commonSuffix = "th" -- Test validation. local test = false local descriptions = { no_series = { type = 1, text = "Television episode..."
 
No edit summary
 
Line 1: Line 1:
--- @module
--- @module
local television = {}
local television = {}
--- someone who is good at lua and mediawiki please parse this and remove the
--- part that adds maintenance categories if the series doesnt have a season number
--- RLM doesnt do seasons


-- Unique suffix list.
-- Unique suffix list.
Line 22: Line 18:
no_series = {
no_series = {
type = 1,
type = 1,
text = "Television episode",
text = "Red Letter Media episode",
category = "[[Category:Television episode articles with short description with no series name|%s]]",
category = "",
},
},
only_series_name = {
only_series_name = {
type = 2,
type = 2,
text = "Episode of %s",
text = "Episode of %s",
category = "[[Category:Television episode articles with short description with no season number|%s]]",
category = "",
},
},
season_and_series_name = {
season_and_series_name = {
type = 3,
type = 3,
text = "Episode of the %s %s of %s",
text = "Episode of %s",
category = "[[Category:Television episode articles with short description with no episode number|%s]]",
category = "",
},
},
single_episode = {
single_episode = {
type = 4,
type = 4,
text = "%s episode of the %s %s of %s",
text = "%s episode of %s",
category = "[[Category:Television episode articles with short description for single episodes|%s]]",
category = "",
},
},
multi_episodes = {
multi_episodes = {
type = 5,
type = 5,
text = "%s episodes of the %s %s of %s",
text = "%s episodes of %s",
category = "[[Category:Television episode articles with short description for multi-part episodes|%s]]",
category = "",
},
},
limited_series = {
limited_series = {
Line 62: Line 58:
-- Tracking category list.
-- Tracking category list.
local trackingCategories = {
local trackingCategories = {
disambiguated = "[[Category:Television episode articles with short description and disambiguated page names|%s]]"
disambiguated = "[[Category:Episode articles with short description and disambiguated page names|%s]]"
}
}


Line 136: Line 132:
end
end


--- Returns a short description in the style of: "Episode of Lost" and a maintenance category:
--- Returns a short description in the style of: "Episode of Lost".
--- "Category:Television episode articles with short description with no season number".
--- @param tvSeriesName string The TV series name.
--- @param tvSeriesName string The TV series name.
local function getShortDescriptionOnlySeriesName(tvSeriesName)
local function getShortDescriptionOnlySeriesName(tvSeriesName)
Line 146: Line 141:
end
end


--- Returns a short description in the style of: "Episode of the first season of Lost" and a maintenance category:
--- Returns a short description in the style of: "5th episode of Lost".
--- "Category:Television episode articles with short description with no episode number".
--- @param tvSeriesName string The TV series name.
--- @param seasonOrdinalNumber string The season's ordinal number.
--- @param seasonTextStyle string The text to use for seasons - either "season" or "series".
local function getShortDescriptionSeasonAndSeriesName(tvSeriesName, seasonOrdinalNumber, seasonTextStyle)
local text = descriptions.season_and_series_name.text
local shortDescription = string.format(text, seasonOrdinalNumber, seasonTextStyle, tvSeriesName)
local category = getTrackingCategory(tvSeriesName, "season_and_series_name")
return shortDescription, category
end
 
--- Returns a short description for a limited series in the style of: "1st episode of WandaVision" and a tracking category
--- based on the categoryKey value.
--- @param tvSeriesName string The TV series name.
--- @param episodeOrdinalNumber string The episode's ordinal number.
--- @param descriptionName string A key from the descriptions table.
local function getShortDescriptionLimitedSeries(tvSeriesName, episodeOrdinalNumber, descriptionName)
local text = descriptions.limited_series.text[descriptionName]
local shortDescription = string.format(text, episodeOrdinalNumber, tvSeriesName)
local category = getTrackingCategory(tvSeriesName, descriptionName)
return shortDescription, category
end
 
--- Returns a short description in the style of: "5th episode of the fourth season of Lost" and a tracking category:
--- "Category:Television episode articles with short description for single episodes".
--- @param tvSeriesName string The TV series name.
--- @param tvSeriesName string The TV series name.
--- @param seasonOrdinalNumber string The season's ordinal number.
--- @param seasonTextStyle string The text to use for seasons - either "season" or "series".
--- @param episodeOrdinalNumber string The episode's ordinal number.
--- @param episodeOrdinalNumber string The episode's ordinal number.
--- @param limitedSeries boolean Whether the episode belongs to a limited series.
local function getShortDescriptionSingleEpisode(tvSeriesName, episodeOrdinalNumber)
local function getShortDescriptionSingleEpisode(tvSeriesName, seasonOrdinalNumber, seasonTextStyle, episodeOrdinalNumber, limitedSeries)
if (limitedSeries) then
return getShortDescriptionLimitedSeries(tvSeriesName, episodeOrdinalNumber,"single_episode")
end
 
local text = descriptions.single_episode.text
local text = descriptions.single_episode.text
local shortDescription =  string.format(text, episodeOrdinalNumber, seasonOrdinalNumber, seasonTextStyle, tvSeriesName)
local shortDescription =  string.format(text, episodeOrdinalNumber, tvSeriesName)
local category = getTrackingCategory(tvSeriesName, "single_episode")
local category = getTrackingCategory(tvSeriesName, "single_episode")
return shortDescription, category
return shortDescription, category
Line 189: Line 152:


--- Returns a short description for a multi-part episode in the style of:
--- Returns a short description for a multi-part episode in the style of:
--- "23rd and 24th episodes of the third season of Lost" and a tracking category:
--- "23rd and 24th episodes of Lost".
--- "Category:Television episode articles with short description for multi-part episodes".
--- @param tvSeriesName string The TV series name.
--- @param tvSeriesName string The TV series name.
--- @param seasonOrdinalNumber string The season's ordinal number.
--- @param seasonTextStyle string The text to use for seasons - either "season" or "series".
--- @param episodeOrdinalNumbers table A list of episode ordinal numbers.
--- @param episodeOrdinalNumbers table A list of episode ordinal numbers.
--- @param limitedSeries boolean Whether the episode belongs to a limited series.
local function getShortDescriptionMultiEpisode(tvSeriesName, episodeOrdinalNumbers)
local function getShortDescriptionMultiEpisode(tvSeriesName, seasonOrdinalNumber, seasonTextStyle, episodeOrdinalNumbers, limitedSeries)
local episodeText = mw.text.listToText(episodeOrdinalNumbers)
local episodeText = mw.text.listToText(episodeOrdinalNumbers)
if (limitedSeries) then
return getShortDescriptionLimitedSeries(tvSeriesName, episodeText, "multi_episodes")
end


local text = descriptions.multi_episodes.text
local text = descriptions.multi_episodes.text
local shortDescription = string.format(text, episodeText, seasonOrdinalNumber, seasonTextStyle, tvSeriesName)
local shortDescription = string.format(text, episodeText, tvSeriesName)
local category = getTrackingCategory(tvSeriesName, "multi_episodes")
local category = getTrackingCategory(tvSeriesName, "multi_episodes")
return shortDescription, category
return shortDescription, category
Line 210: Line 165:


--- Returns a short description for a special episode in the style of:
--- Returns a short description for a special episode in the style of:
--- "Special episode of Lost" or "<value> episode of Lost" and a tracking category:
--- "Special episode of Lost" or "<value> episode of Lost".
--- "Category:Television episode articles with short description for single episodes".
--- @param tvSeriesName string The TV series name.
--- @param tvSeriesName string The TV series name.
--- @param special string The type of special episode. A "yes" value defaults to "Special".
--- @param special string The type of special episode. A "yes" value defaults to "Special".
Line 226: Line 180:
--- Returns a short description based on the description type passed.
--- Returns a short description based on the description type passed.
--- @param descriptionType number A description type number.
--- @param descriptionType number A description type number.
--- @param tvSeriesName string The TV series name.
--- @param tvSeriesName string The series name.
--- @param seasonOrdinalNumber string The season's ordinal number.
--- @param seasonTextStyle string The text to use for seasons - either "season" or "series".
--- @param episodeOrdinalNumbers table A list of episode ordinal numbers.
--- @param episodeOrdinalNumbers table A list of episode ordinal numbers.
--- @param specialEpisode string The type of special episode.
--- @param specialEpisode string The type of special episode.
--- @param limitedSeries boolean Whether the episode belongs to a limited series.
local function getShortDescriptionByType(
local function getShortDescriptionByType(
descriptionType, tvSeriesName, seasonOrdinalNumber, seasonTextStyle, episodeOrdinalNumbers, specialEpisode, limitedSeries)
descriptionType, tvSeriesName, episodeOrdinalNumbers, specialEpisode)
if descriptionType == descriptions.no_series.type then
if descriptionType == descriptions.no_series.type then
return getShortDescriptionNoSeries()
return getShortDescriptionNoSeries()
elseif descriptionType == descriptions.only_series_name.type then
elseif descriptionType == descriptions.only_series_name.type then
return getShortDescriptionOnlySeriesName(tvSeriesName)
return getShortDescriptionOnlySeriesName(tvSeriesName)
elseif descriptionType == descriptions.season_and_series_name.type then
--- elseif descriptionType == descriptions.season_and_series_name.type then
return getShortDescriptionSeasonAndSeriesName(tvSeriesName, seasonOrdinalNumber, seasonTextStyle)
--- return getShortDescriptionSeasonAndSeriesName(tvSeriesName, seasonOrdinalNumber, seasonTextStyle)
elseif descriptionType == descriptions.single_episode.type then
elseif descriptionType == descriptions.single_episode.type then
return getShortDescriptionSingleEpisode(
return getShortDescriptionSingleEpisode(
                 tvSeriesName, seasonOrdinalNumber, seasonTextStyle, episodeOrdinalNumbers[1], limitedSeries)
                 tvSeriesName, episodeOrdinalNumbers[1])
elseif descriptionType == descriptions.multi_episodes.type then
elseif descriptionType == descriptions.multi_episodes.type then
return getShortDescriptionMultiEpisode(
return getShortDescriptionMultiEpisode(
tvSeriesName, seasonOrdinalNumber, seasonTextStyle, episodeOrdinalNumbers, limitedSeries)
tvSeriesName, episodeOrdinalNumbers)
elseif descriptionType == descriptions.special_episode.type then
elseif descriptionType == descriptions.special_episode.type then
return getShortDescriptionSpecialEpisode(tvSeriesName, specialEpisode)
return getShortDescriptionSpecialEpisode(tvSeriesName, specialEpisode)
Line 255: Line 206:
--- Returns the type of the description to use.
--- Returns the type of the description to use.
--- @param tvSeriesName string The TV series name.
--- @param tvSeriesName string The TV series name.
--- @param seasonOrdinalNumber string The season's ordinal number.
--- @param episodeOrdinalNumbers table A list of episode ordinal numbers.
--- @param episodeOrdinalNumbers table A list of episode ordinal numbers.
--- @param specialEpisode string The type of special episode.
--- @param specialEpisode string The type of special episode.
--- @param limitedSeries boolean Whether the episode belongs to a limited series.
local function getDescriptionType(tvSeriesName, episodeOrdinalNumbers, specialEpisode)
local function getDescriptionType(tvSeriesName, seasonOrdinalNumber, episodeOrdinalNumbers, specialEpisode, limitedSeries)
if (not tvSeriesName) then
if (not tvSeriesName) then
return descriptions.no_series.type
return descriptions.no_series.type
Line 268: Line 217:
end
end


if (not seasonOrdinalNumber and not limitedSeries) then
if (#episodeOrdinalNumbers < 1) then
return descriptions.only_series_name.type
return descriptions.only_series_name.type
end
if (#episodeOrdinalNumbers < 1) then
return descriptions.season_and_series_name.type
end
end


Line 283: Line 228:
return descriptions.multi_episodes.type
return descriptions.multi_episodes.type
end
end
end


--- Returns true if the TV series is a limited series.
return descriptions.only_series_name.type
--- @param limitedSeries string Any value will be considered as true.
--- @param tvSeriesNameDab string The disambiguation used in the series name article title.
local function isLimitedSeries(limitedSeries, tvSeriesNameDab)
if (limitedSeries) then
return true
end
 
if tvSeriesNameDab and string.find(tvSeriesNameDab, "miniseries") then
return true
end
 
return false
end
end


Line 383: Line 315:


return episodeOrdinals
return episodeOrdinals
end
--- Returns true if the season number value is a number.
--- @param seasonNumber string The season number value in string format.
local function validateSeasonNumber(seasonNumber)
if (tonumber(seasonNumber)) then
return true
else
return false
end
end
--- Returns the season's ordinal number, or nil if no season number was set.
--- @param seasonNumber string The season number.
local function getSeasonOrdinalNumber(seasonNumber)
if (seasonNumber) then
local convertOrdinal = require("Module:Ordinal")
return convertOrdinal._ordinal(seasonNumber)
end
return nil
end
--- Returns a season number after removing from it unwanted characters.
---
--- This is done to make sure that no malformed season values have been entered.
--- The function will remove all text which is not part of the first number in the string.
---
--- The function converts entries such as:
--- "1.2" -> "1"
--- "12.2" -> "12"
--- @param seasonNumber string The season number value in string format.
local function cleanSeasonNumber(seasonNumber)
if (seasonNumber) then
return string.match(seasonNumber, "%d+")
end
return nil
end
--- Returns the season number after or cleaning it from unwanted values and validating value is a number.
--- Also returns the text style to use - either "season" or "series".
--- If no value was entered or if value was not a number, return nil.
--- @param seasonNumber string The season number.
--- @param seasonNumberUK string The season number, if UK style was used.
local function getSeasonNumberAndTextStyle(seasonNumber, seasonNumberUK)
    for _, v in ipairs({{seasonNumber, "season"}, {seasonNumberUK, "series"}}) do
        local cleanedSeasonNumber = cleanSeasonNumber(v[1])
        if (validateSeasonNumber(cleanedSeasonNumber)) then
            return cleanedSeasonNumber, v[2]
        end
    end
return nil
end
end


Line 456: Line 337:
--- @param args table The values that should be processed.
--- @param args table The values that should be processed.
local function cleanValues(args)
local function cleanValues(args)
for i, v in ipairs({"episode_num", "season_num", "season_num_uk", "series_name"}) do
for i, v in ipairs({"episode_num", "series_name"}) do
if (args[v]) then
if (args[v]) then
args[v] = args[v]:gsub("\127[^\127]*UNIQ%-%-(%a+)%-%x+%-QINU[^\127]*\127", "") -- Remove all strip-markers.
args[v] = args[v]:gsub("\127[^\127]*UNIQ%-%-(%a+)%-%x+%-QINU[^\127]*\127", "") -- Remove all strip-markers.
Line 485: Line 366:
args = cleanValues(args)
args = cleanValues(args)
local tvSeriesName, tvSeriesNameDab = getTVSeriesName(args.series_name, args.not_dab)
local tvSeriesName, tvSeriesNameDab = getTVSeriesName(args.series_name, args.not_dab)
    local seasonNumber, seasonTextStyle = getSeasonNumberAndTextStyle(args.season_num, args.season_num_uk)
--- RLMWiki doesn't need seasons
local seasonOrdinalNumber = getSeasonOrdinalNumber(seasonNumber)
--- local seasonNumber, seasonTextStyle = getSeasonNumberAndTextStyle(args.season_num, args.season_num_uk)
--- local seasonOrdinalNumber = getSeasonOrdinalNumber(seasonNumber)
local episodeOrdinalNumbers = getEpisodeOrdinalNumbers(args.episode_num)
local episodeOrdinalNumbers = getEpisodeOrdinalNumbers(args.episode_num)
local limitedSeries = isLimitedSeries(args.limited, tvSeriesNameDab)
--- local limitedSeries = isLimitedSeries(args.limited, tvSeriesNameDab)
local descriptionType = getDescriptionType(
local descriptionType = getDescriptionType(
tvSeriesName,
tvSeriesName,
seasonOrdinalNumber,
episodeOrdinalNumbers,
episodeOrdinalNumbers,
args.special,
args.special
limitedSeries
)
)


Line 501: Line 381:
descriptionType,
descriptionType,
tvSeriesName,
tvSeriesName,
seasonOrdinalNumber,
            seasonTextStyle,
episodeOrdinalNumbers,
episodeOrdinalNumbers,
args.special,
args.special
limitedSeries
)
)


Line 526: Line 403:
--- Parameters:
--- Parameters:
--- |episode_num= — optional; The episode's number.
--- |episode_num= — optional; The episode's number.
--- |season_num= — optional; The season's number.
--- |season_num_uk= — optional; The season's number if using the British "series" term.
--- |series_name= — optional; The TV series name.
--- |series_name= — optional; The TV series name.
--- |not_dab= — optional; Set if the TV series name has parentheses as part of its name.
--- |not_dab= — optional; Set if the TV series name has parentheses as part of its name.
Line 533: Line 408:
--- Any other value will replace the word "special" with the one entered.
--- Any other value will replace the word "special" with the one entered.
--- For example "special=recap" will create "recap episode".
--- For example "special=recap" will create "recap episode".
--- |limited= — optional; Set if the series is a single season series, such as miniseries or limited series
--- and does not need a season number as part of the description.
--- @param frame table The frame invoking the module.
--- @param frame table The frame invoking the module.
function television.getShortDescription(frame)
function television.getShortDescription(frame)