Documentation for this module may be created at Module:ReleaseDate/doc
-- Obtained and modified from https://en.wikipedia.org/wiki/Module:Video_game_release
local getArgs = require('Module:Arguments').getArgs
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'] = "<abbr title=\"North America\">NA</abbr>",
['EU'] = "<abbr title=\"Europe\">EU</abbr>",
['NAEU'] = "<abbr title=\"North America\">NA</abbr>/<abbr title=\"Europe\">EU</abbr>",
['EUR'] = "<abbr title=\"Europe\">EU</abbr>",
['AU'] = "<abbr title=\"Australasia\">AU</abbr>",
['AUS'] = "<abbr title=\"Australasia\">AU</abbr>",
['JP'] = "<abbr title=\"Japan\">JP</abbr>",
['KO'] = "<abbr title=\"South Korea\">KO</abbr>",
['BR'] = "<abbr title=\"Brazil\">BR</abbr>",
['CN'] = "<abbr title=\"China\">CN</abbr>",
['PAL'] = "<abbr title=\"PAL region\">PAL</abbr>",
['SEA'] = "<abbr title=\"Southeast Asia\">SEA</abbr>",
['AS'] = "<abbr title=\"Asia\">AS</abbr>",
['SA'] = "<abbr title=\"South America\">SA</abbr>",
['OC'] = "<abbr title=\"Oceania\">OC</abbr>",
['TW'] = "<abbr title=\"Taiwan\">TW</abbr>",
['SG'] = "<abbr title=\"Singapore\">SG</abbr>",
['WW'] = "<abbr title=\"Worldwide\">WW</abbr>"
}
local function getLocalLabel(alias)
local label = labels[string.upper(alias)]
return label
end
local function splitLabel(s)
local islist = true
local res = {}
for k,v in ipairs(mw.text.split(s or '', '%s*/%s*')) do
local v1 = v:match('^%s*([A-Z][A-Z][A-Z]?)%s*$')
if v1 then
table.insert(res,v1)
else
local v2 = v:match('^%s*(%[%[[^%[%]|]*|[A-Z][A-Z][A-Z]?%]%])%s*$')
if v2 then
table.insert(res,v2)
else
islist = false
end
end
end
return islist and res or {s}
end
function p.main(frame)
local args = getArgs(frame)
local listformat = args['format']
if (listformat == nil or listformat == "") then
listformat = "unbulleted"
end
local 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) then
local item = "<span style=\"font-size:95%;\">[["
if (args[1] ~= nil) then
item = item .. args[1]
end
item = item .. "|"
if (args[2] ~= nil) then
item = item .. args[2]
end
item = item .. "]]:</span> " .. args[3] .. "[[Category:Pages using releasedate 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) then
local item = args[2] .. "[[Category:Pages using releasedate without a region]]"
table.insert(items, item)
-- Normal use cases, region/date pairs in 1/2, 3/4, 5/6, etc.
else
local i = 1
local j = 2
while (args[i] and args[j]) do
local labels = {}
for k,v in ipairs(splitLabel(args[i])) do
local label = getLocalLabel(v);
table.insert(labels, label)
end
local item = "<span style=\"font-size:95%;\">" .. table.concat(labels,'/') .. ":</span> " .. args[j]
table.insert(items, item)
i = i + 2
j = j + 2
end
end
-- Add known parameters of Module:List to the table
for k, v in pairs(args) do
if (knownargs[k] == true) then
items[k] = v
end
end
local out = list.makeList(listformat, items)
-- Set message for invalid parameters.
local parameterMsg = "[[Category:Pages using releasedate with named parameters|_VALUE_]]"
-- Preview message.
if (frame:preprocess("{{REVISIONID}}") == "") then
parameterMsg = "<div class=\"hatnote\" style=\"color:red\"><strong>Warning:</strong> unknown parameter \"_VALUE_\" (this message is shown only in preview).</div>"
end
-- Check for invalid parameters
for k, v in pairs(args) do
if (type(k) ~= 'number' and knownargs[k] ~= true) then
local msg = parameterMsg:gsub('_VALUE_', k)
out = out .. msg
end
end
return out
end
return p