Module:Video game release

require('strict')local getArgs = require('Module:Arguments').getArgslocal cd = require('Module:CountryData')local list = require('Module:List');local p = {}local knownargs = {['format'] = true,['class'] = true,['style'] = true,['list_style'] = true,['item_style'] = true,['item1_style'] = true,['indent'] = true}local labels = {['NA'] = "[[North America|NA]]",['EU'] = "[[Europe|EU]]",['EUR'] = "[[Europe|EU]]",['AU'] = "[[Australasia|AU]]",['AUS'] = "[[Australasia|AU]]",['PAL'] = "[[PAL region|PAL]]",['SEA'] = "[[Southeast Asia|SEA]]",['AS'] = "[[Asia|AS]]",['SA'] = "[[South America|SA]]",['OC'] = "[[Oceania|OC]]",['WW'] = "<abbr title=\"Worldwide\">WW</abbr>"}local function getLocalLabel(alias)local label = labels[string.upper(alias)]return labelendlocal countryData = {}; -- Used to store country data to avoid the need of repeated calls to Module:CountryData. This saves a little time if the same abbreviation appears multiple times in the template.local function getCountryData(frame, alias)local ualias = string.upper(alias)if (countryData[ualias] == nil) thenlocal cdtable = cd.gettable(frame, alias, {})countryData[ualias] = cdtable['alias']endreturn countryData[ualias]endlocal function splitLabel(s)local islist = truelocal res = {}for k,v in ipairs(mw.text.split(s or '', '%s*/%s*')) dolocal v1 = v:match('^%s*([A-Z][A-Z][A-Z]?)%s*$')if v1 thentable.insert(res,v1)elselocal v2 = v:match('^%s*(%[%[[^%[%]|]*|[A-Z][A-Z][A-Z]?%]%])%s*$')if v2 thentable.insert(res,v2)elseislist = falseendendendreturn islist and res or {s}endfunction p.main(frame)local args = getArgs(frame)local listformat = args['format']if (listformat == nil or listformat == "") thenlistformat = "unbulleted"endlocal items = {}-- Old syntax "Two parameter region" use case, where param 1 is an article, param 2 is a label, and param 3 is the date. We assume this case if argument 4 is nil.if (args[3] ~= nil and args[4] == nil) thenlocal item = "<span style=\"font-size:97%;\">[["if (args[1] ~= nil) thenitem = item .. args[1]enditem = item .. "|"if (args[2] ~= nil) thenitem = item .. args[2]enditem = item .. "]]:</span> " .. args[3] .. "[[Category:Pages using vgrelease with two parameter region]]"table.insert(items, item)-- Old syntax "Blank region" use case, where param 1 is empty, and param 2 is the date.elseif (args[1] == nil and args[2] ~= nil) thenlocal item = args[2] .. "[[Category:Pages using vgrelease without a region]]"table.insert(items, item)-- Normal use cases, region/date pairs in 1/2, 3/4, 5/6, etc.elselocal i = 1local j = 2while (args[i] and args[j]) dolocal labels = {}for k,v in ipairs(splitLabel(args[i])) dolocal label = getLocalLabel(v);-- Didn't find a local label? Check for country data.if (label == nil) thenif not v:match('^%s*%[') thenlabel = getCountryData(frame, v)end-- Found something? Build a sitelink with it.if (label ~= nil) thenlabel = "[[" .. label .. "|" .. v .. "]]"elselabel = vendendtable.insert(labels, label)endlocal item = "<span style=\"font-size:97%;\">" .. table.concat(labels,'/') .. ":</span> " .. args[j]table.insert(items, item)i = i + 2j = j + 2endend-- Add known parameters of Module:List to the tablefor k, v in pairs(args) doif (knownargs[k] == true) thenitems[k] = vendendlocal out = list.makeList(listformat, items)-- Preview message and categorylocal parameterMsg = require('Module:If preview')._warning({'Unknown parameter "_VALUE_".'}) .. "[[Category:Pages using vgrelease with named parameters|_VALUE_]]"-- Check for invalid parametersfor k, v in pairs(args) doif (type(k) ~= 'number' and knownargs[k] ~= true) thenlocal msg = parameterMsg:gsub('_VALUE_', k)out = out .. msgendendreturn outendreturn p