An array of page names that should not be validated; If there are none, pass an empty array.
required
otherInfoboxList
An array of key/value pairs of the type the disambiguation to check for (key) and the tracking category to add it to (value).
required
locallibraryUtil=require('libraryUtil')--=============================================================---- DisambiguationPattern class.localfunctionDisambiguationPattern(o)localDisambiguationPattern=oor{pattern="",type=""}localcheckSelf=libraryUtil.makeCheckSelfFunction('Television infoboxes disambiguation check','DisambiguationPattern',DisambiguationPattern,'Television infoboxes disambiguation check object')returnDisambiguationPatternend--=============================================================---- Constants.localDAB_VALID={[true]="valid",[false]="invalid"}localCATEGORY_INCORRECT="[[Category:Television articles with incorrect naming style]]"localvalidationTypeList={["VALIDATION_TYPE_YEAR_COUNTRY"]=1,["VALIDATION_TYPE_YEAR"]=2,["VALIDATION_TYPE_COUNTRY"]=3,["VALIDATION_TYPE_YEAR_SEASON_NUMBER"]=4,["VALIDATION_TYPE_COUNTRY_SEASON_NUMBER"]=5,["VALIDATION_TYPE_SEASON_NUMBER"]=6,["VALIDATION_TYPE_COUNTRY_SEASON"]=7,["VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER"]=8}localdebugMessageList={["DEBUG_EMPTY_TITLE"]="Debug: Error: Empty title.",["DEBUG_NO_DAB"]="Debug: No disambiguation.",["DEBUG_TITLE_ON_EXCEPTION"]="Debug: Title on exception list.",["DEBUG_VALID_FORMAT"]="Debug: Using a valid format.",["DEBUG_NOT_VALID_FORMAT"]="Debug: Not a valid format.",["DEBUG_YEAR_COUNTRY"]="Debug: Using a valid format with an extended Year and Country - {}.",["DEBUG_YEAR"]="Debug: Using a valid format with an extended Year - {}.",["DEBUG_COUNTRY"]="Debug: Using a valid format with an extended Country - {}.",["DEBUG_INCORRECT_STYLE"]="Debug: Using a valid format but using an incorrect extended style.",["DEBUG_INCORRECT_INFOBOX"]="Debug: Using incorrect infobox - {}.",["DEBUG_YEAR_SEASON_NUMBER"]="Debug: Using a valid format with an extended Year 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_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 - {}."}-- Local function which checks if both booleans are true or not.localfunctionvalidateTwoParameters(isValid1,isValid2)if(isValid1andisValid2)thenreturntrueelsereturnfalseendend-- Validate that the season number entered is a valid number --- that it does not start with a leading zero (0).localfunctionvalidateSeasonNumber(seasonNumber)if(tonumber(string.sub(seasonNumber,1,1))==0)thenreturnfalseelsereturntrueendend-- Validate that the year entered is a valid year.localfunctionvalidateYear(year)if(string.len(year)==4)thenreturntrueelsereturnfalseendend-- Validate that the text entered is a supported country adjective.localfunctionvalidateCountryAdjective(adjective)localdata=mw.loadData('Module:Country adjective')-- Search for a country corresponding to the given text.if(data.getCountryFromAdj[adjective])thenreturntrueelsereturnfalseendend-- Checks pages using by validating the disambiguation patterns.localfunctionvalidatePatterns(disambiguation,disambiguationPatternList)localyear=""localadjective=""localseasonNumber=""localisYearValidlocalisAdjectiveValidlocalisSeasonNumberValidfori,vinipairs(disambiguationPatternList)dolocalcurrentDisambiguationPattern=disambiguationPatternList[i]if(disambiguation:match(currentDisambiguationPattern.pattern))then-- Year and Country styles: "1999 American TV series"if(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_YEAR_COUNTRY"])thenyear,adjective=disambiguation:match(currentDisambiguationPattern.pattern)isYearValid=validateYear(year)isAdjectiveValid=validateCountryAdjective(adjective)localisValid=validateTwoParameters(isYearValid,isAdjectiveValid)returnisValid,debugMessageList["DEBUG_YEAR_COUNTRY"]:gsub("{}",DAB_VALID[isValid])-- Year styles: "1999 TV series"elseif(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_YEAR"])thenyear=disambiguationisYearValid=validateYear(year)returnisYearValid,debugMessageList["DEBUG_YEAR"]:gsub("{}",DAB_VALID[isYearValid])-- Country styles: "American TV series"elseif(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_COUNTRY"])thenadjective=disambiguationisAdjectiveValid=validateCountryAdjective(adjective)returnisAdjectiveValid,debugMessageList["DEBUG_COUNTRY"]:gsub("{}",DAB_VALID[isAdjectiveValid])-- Year and Season number styles: "1999 TV series, season 1"elseif(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_YEAR_SEASON_NUMBER"])thenyear,seasonNumber=disambiguation:match(currentDisambiguationPattern.pattern)isYearValid=validateYear(year)isSeasonNumberValid=validateSeasonNumber(seasonNumber)localisValid=validateTwoParameters(isYearValid,isSeasonNumberValid)returnisValid,debugMessageList["DEBUG_YEAR_SEASON_NUMBER"]:gsub("{}",DAB_VALID[isValid])-- Country and Season number styles: "American season 1" and "American TV series, season 1"elseif(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_COUNTRY_SEASON_NUMBER"])thenadjective,seasonNumber=disambiguation:match(currentDisambiguationPattern.pattern)isAdjectiveValid=validateCountryAdjective(mw.text.trim(adjective))isSeasonNumberValid=validateSeasonNumber(seasonNumber)localisValid=validateTwoParameters(isAdjectiveValid,isSeasonNumberValid)returnisValid,debugMessageList["DEBUG_COUNTRY_SEASON_NUMBER"]:gsub("{}",DAB_VALID[isValid])-- Country and the word season: "American season"elseif(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_COUNTRY_SEASON"])thenadjective=disambiguation:match(currentDisambiguationPattern.pattern)isAdjectiveValid=validateCountryAdjective(mw.text.trim(adjective))returnisAdjectiveValid,debugMessageList["DEBUG_COUNTRY_SEASON"]:gsub("{}",DAB_VALID[isAdjectiveValid])--Season number styles: "season 1"elseif(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_SEASON_NUMBER"])thenseasonNumber=disambiguation:match(currentDisambiguationPattern.pattern)isSeasonNumberValid=validateSeasonNumber(seasonNumber)returnisSeasonNumberValid,debugMessageList["DEBUG_SEASON_NUMBER"]:gsub("{}",DAB_VALID[isSeasonNumberValid])-- Year, Country and Season number styles: "Gladiators (2008 British TV series, series 2)"elseif(currentDisambiguationPattern.type==validationTypeList["VALIDATION_TYPE_YEAR_COUNTRY_SEASON_NUMBER"])thenyear,adjective,seasonNumber=disambiguation:match(currentDisambiguationPattern.pattern)isYearValid=validateYear(year)isAdjectiveValid=validateCountryAdjective(mw.text.trim(adjective))isSeasonNumberValid=validateSeasonNumber(seasonNumber)localisValid=validateTwoParameters(isYearValid,isAdjectiveValid)isValid=validateTwoParameters(isValid,isSeasonNumberValid)returnisValid,debugMessageList["DEBUG_YEAR_COUNTRY_SEASON_NUMBER"]:gsub("{}",DAB_VALID[isValid])-- Not a valid supported style.else-- Do nothing.endelse-- Do nothing.endendreturnfalse,debugMessageList["DEBUG_INCORRECT_STYLE"]end-- Validate that the disambiguation type is one of the supported types.localfunctionvalidateDisambiguationType(disambiguation,validDisambiguationTypeList)localextendedDisambiguationlocalcount=0fori,vinipairs(validDisambiguationTypeList)doextendedDisambiguation,count=disambiguation:gsub(v,'')extendedDisambiguation=mw.text.trim(extendedDisambiguation)if(count~=0)then-- Disambiguation was a valid type; Exit loop.breakendendcount=count~=0returncount,extendedDisambiguationend-- Validate that the complete disambiguation is using a supported style.localfunctionvalidateDisambiguation(invoker,disambiguation,validDisambiguationTypeList,validDisambiguationPatternList)-- Check if the list is empty.if(table.getn(validDisambiguationTypeList)~=0)thenlocalisDisambiguationValid,extendedDisambiguation=validateDisambiguationType(disambiguation,validDisambiguationTypeList)-- Exit module if the disambiguation type is not a supported style.if(notisDisambiguationValid)thenreturnfalse,debugMessageList["DEBUG_NOT_VALID_FORMAT"]end-- Check if there is no extended disambiguation.if(extendedDisambiguation=='')thenreturntrue,debugMessageList["DEBUG_VALID_FORMAT"]end-- A bit of hack so I won't need to refactor a ton of code.if(invoker~="infobox television season")thendisambiguation=extendedDisambiguationendendreturnvalidatePatterns(disambiguation,validDisambiguationPatternList)end-- Check if the page is using disambiguation style that belongs to a different infobox.localfunctionisPageUsingIncorrectInfobox(disambiguation,otherInfoboxList)fork,vinpairs(otherInfoboxList)doif(string.match(disambiguation,k))thenreturntrue,v,debugMessageList["DEBUG_INCORRECT_INFOBOX"]:gsub("{}",k)endendreturnfalseend-- Validate that the title has brackets that are part of the title and not part of disambiguation.localfunctionisOnExceptionList(title,exceptionList)for_,vinipairs(exceptionList)doif(v==title)thenreturntrueelseif(string.match(title,v))thenreturntrueendendreturnfalseend-- Get the disambiguation text and make sure that if the title has more than 1 pair of brackets, it returns the last one.localfunctiongetDisambiguation(title)localmatch=require("Module:String")._matchreturnmatch(title,"%s%((.-)%)",1,-1,false,"")-- return (string.match (title, '%s*%b()$') or ''):gsub('[%(%)]', '')end-- Validate that arg is not nill and not empty.localfunctionisEmpty(arg)if(notargorarg=="")thenreturntrueelsereturnfalseendend-- Returns two objects:--- The first is either an empty string or a tracking category which will appear when using the live version.--- The second is a debug string which will appear when using /testcases.localfunctionmain(title,invoker,validDisambiguationTypeList,validDisambiguationPatternList,exceptionList,otherInfoboxList,invalidTitleStyleList)-- Exit module if the parameter has no value.if(isEmpty(title))thenreturn"",debugMessageList["DEBUG_EMPTY_TITLE"]end-- Exit module if the title has brackets that are part of the title (not disambiguation).if(isOnExceptionList(title,exceptionList))thenreturn"",debugMessageList["DEBUG_TITLE_ON_EXCEPTION"]endif(invoker=="infobox television season")thenif(#invalidTitleStyleList~=0)thenfori=1,#invalidTitleStyleListdoif(string.find(title,invalidTitleStyleList[i]))thenreturnCATEGORY_INCORRECT,debugMessageList["DEBUG_NOT_VALID_FORMAT"]endendendend-- Get the disambiguation.localdisambiguation=getDisambiguation(title)-- Exit module if the title has no disambiguation.if(isEmpty(disambiguation))thenreturn"",debugMessageList["DEBUG_NO_DAB"]end-- Exit module if the disambiguation belongs to a different infobox.localisValid,category,debugString=isPageUsingIncorrectInfobox(disambiguation,otherInfoboxList)if(isValid)thenreturncategory,debugStringend-- Check if the disambiguation is valid.isValid,debugString=validateDisambiguation(invoker,disambiguation,validDisambiguationTypeList,validDisambiguationPatternList)-- Check if the disambiguation is not valid and add category.if(notisValid)thencategory=CATEGORY_INCORRECTendreturncategory,debugStringendreturn{main=main,DisambiguationPattern=DisambiguationPattern}