Module:Television infoboxes disambiguation check and Module:Television infoboxes disambiguation check/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
added support for "year, country TV series, season #" styles |
No edit summary |
||
Line 1: | Line 1: | ||
local libraryUtil = require( |
require("strict") |
||
local libraryUtil = require("libraryUtil") |
|||
--=============================================================-- |
--=============================================================-- |
||
Line 5: | Line 7: | ||
local function DisambiguationPattern(o) |
local function DisambiguationPattern(o) |
||
local DisambiguationPattern = o or {pattern = "", type = ""} |
local DisambiguationPattern = o or {pattern = "", type = ""} |
||
local checkSelf = libraryUtil.makeCheckSelfFunction( |
local checkSelf = libraryUtil.makeCheckSelfFunction("Television infoboxes disambiguation check", "DisambiguationPattern", DisambiguationPattern, "Television infoboxes disambiguation check object") |
||
return DisambiguationPattern |
return DisambiguationPattern |
||
Line 27: | Line 29: | ||
["VALIDATION_TYPE_COUNTRY_SEASON_NUMBER"] = 5, |
["VALIDATION_TYPE_COUNTRY_SEASON_NUMBER"] = 5, |
||
["VALIDATION_TYPE_SEASON_NUMBER"] = 6, |
["VALIDATION_TYPE_SEASON_NUMBER"] = 6, |
||
["VALIDATION_TYPE_COUNTRY_SEASON"] = 7, |
|||
["VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER"] = 8 |
["VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER"] = 8 |
||
} |
} |
||
Line 45: | Line 46: | ||
["DEBUG_COUNTRY_SEASON_NUMBER"] = "Debug: Using a valid format with an extended Country and Season number - {}.", |
["DEBUG_COUNTRY_SEASON_NUMBER"] = "Debug: Using a valid format with an extended Country and Season number - {}.", |
||
["DEBUG_SEASON_NUMBER"] = "Debug: Using a valid format with a Season number - {}.", |
["DEBUG_SEASON_NUMBER"] = "Debug: Using a valid format with a Season number - {}.", |
||
["DEBUG_COUNTRY_SEASON"] = "Debug: Using a valid format with a Country and the word Season - {}.", |
|||
["DEBUG_YEAR_COUNTRY_SEASON_NUMBER"] = "Debug: Using a valid format with an extended Year, Country and Season number - {}." |
["DEBUG_YEAR_COUNTRY_SEASON_NUMBER"] = "Debug: Using a valid format with an extended Year, Country and Season number - {}." |
||
} |
} |
||
Line 79: | Line 79: | ||
-- Validate that the text entered is a supported country adjective. |
-- Validate that the text entered is a supported country adjective. |
||
local function validateCountryAdjective(adjective) |
local function validateCountryAdjective(adjective) |
||
local data = mw.loadData( |
local data = mw.loadData("Module:Country adjective") |
||
-- Search for a country corresponding to the given text. |
-- Search for a country corresponding to the given text. |
||
Line 123: | Line 123: | ||
return isAdjectiveValid, debugMessageList["DEBUG_COUNTRY"]:gsub("{}", DAB_VALID[isAdjectiveValid]) |
return isAdjectiveValid, debugMessageList["DEBUG_COUNTRY"]:gsub("{}", DAB_VALID[isAdjectiveValid]) |
||
-- Year and Season number styles: "1999 TV series |
-- Year and Season number styles: "(1999 TV series) season 1" |
||
elseif (currentDisambiguationPattern.type == validationTypeList["VALIDATION_TYPE_YEAR_SEASON_NUMBER"]) then |
elseif (currentDisambiguationPattern.type == validationTypeList["VALIDATION_TYPE_YEAR_SEASON_NUMBER"]) then |
||
year, seasonNumber = disambiguation:match(currentDisambiguationPattern.pattern) |
year, seasonNumber = disambiguation:match(currentDisambiguationPattern.pattern) |
||
Line 132: | Line 132: | ||
return isValid, debugMessageList["DEBUG_YEAR_SEASON_NUMBER"]:gsub("{}", DAB_VALID[isValid]) |
return isValid, debugMessageList["DEBUG_YEAR_SEASON_NUMBER"]:gsub("{}", DAB_VALID[isValid]) |
||
-- Country and Season number styles: " |
-- Country and Season number styles: "(American TV series) season 1" |
||
elseif (currentDisambiguationPattern.type == validationTypeList["VALIDATION_TYPE_COUNTRY_SEASON_NUMBER"]) then |
elseif (currentDisambiguationPattern.type == validationTypeList["VALIDATION_TYPE_COUNTRY_SEASON_NUMBER"]) then |
||
adjective, seasonNumber = disambiguation:match(currentDisambiguationPattern.pattern) |
adjective, seasonNumber = disambiguation:match(currentDisambiguationPattern.pattern) |
||
Line 140: | Line 140: | ||
local isValid = validateTwoParameters(isAdjectiveValid, isSeasonNumberValid) |
local isValid = validateTwoParameters(isAdjectiveValid, isSeasonNumberValid) |
||
return isValid, debugMessageList["DEBUG_COUNTRY_SEASON_NUMBER"]:gsub("{}", DAB_VALID[isValid]) |
return isValid, debugMessageList["DEBUG_COUNTRY_SEASON_NUMBER"]:gsub("{}", DAB_VALID[isValid]) |
||
-- Country and the word season: "American season" |
|||
elseif (currentDisambiguationPattern.type == validationTypeList["VALIDATION_TYPE_COUNTRY_SEASON"]) then |
|||
adjective = disambiguation:match(currentDisambiguationPattern.pattern) |
|||
isAdjectiveValid = validateCountryAdjective(mw.text.trim(adjective)) |
|||
return isAdjectiveValid, debugMessageList["DEBUG_COUNTRY_SEASON"]:gsub("{}", DAB_VALID[isAdjectiveValid]) |
|||
--Season number styles: "season 1" |
--Season number styles: "season 1" |
||
Line 153: | Line 147: | ||
return isSeasonNumberValid, debugMessageList["DEBUG_SEASON_NUMBER"]:gsub("{}", DAB_VALID[isSeasonNumberValid]) |
return isSeasonNumberValid, debugMessageList["DEBUG_SEASON_NUMBER"]:gsub("{}", DAB_VALID[isSeasonNumberValid]) |
||
-- Year, Country and Season number styles: "Gladiators (2008 British TV series |
-- Year, Country and Season number styles: "Gladiators (2008 British TV series) series 2" |
||
elseif (currentDisambiguationPattern.type == validationTypeList["VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER"]) then |
elseif (currentDisambiguationPattern.type == validationTypeList["VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER"]) then |
||
year, adjective, seasonNumber = disambiguation:match(currentDisambiguationPattern.pattern) |
year, adjective, seasonNumber = disambiguation:match(currentDisambiguationPattern.pattern) |
||
Line 181: | Line 175: | ||
for i, v in ipairs(validDisambiguationTypeList) do |
for i, v in ipairs(validDisambiguationTypeList) do |
||
extendedDisambiguation, count = disambiguation:gsub(v, |
extendedDisambiguation, count = disambiguation:gsub(v, "") |
||
extendedDisambiguation = mw.text.trim(extendedDisambiguation) |
extendedDisambiguation = mw.text.trim(extendedDisambiguation) |
||
if (count ~= 0) then |
if (count ~= 0) then |
||
Line 206: | Line 200: | ||
-- Check if there is no extended disambiguation. |
-- Check if there is no extended disambiguation. |
||
if (extendedDisambiguation == |
if (extendedDisambiguation == "") then |
||
return true, debugMessageList["DEBUG_VALID_FORMAT"] |
return true, debugMessageList["DEBUG_VALID_FORMAT"] |
||
end |
end |
||
Line 245: | Line 239: | ||
local match = require("Module:String")._match |
local match = require("Module:String")._match |
||
return match(title, "%s%((.-)%)", 1, -1, false, "") |
return match(title, "%s%((.-)%)", 1, -1, false, "") |
||
-- return (string.match (title, |
-- return (string.match (title, "%s*%b()$") or ""):gsub("[%(%)]", "") |
||
end |
end |
||