HerrHulaHoop (talk | contribs) No edit summary Tag: Manual revert |
HerrHulaHoop (talk | contribs) m (test9) Tag: Reverted |
||
Line 50: | Line 50: | ||
function p.main(frame) | function p.main(frame) | ||
local args = getArgs(frame) | |||
local listformat = args['format'] | |||
if (listformat == nil or listformat == "") then | |||
listformat = "unbulleted" | |||
end | |||
local items = {} | |||
-- Add named parameter handling here: | |||
local i = 1 | |||
while (args[i]) do | |||
local parts = mw.text.split(args[i], '=') | |||
if #parts == 2 then -- Check if there's an = sign | |||
local region, date = parts[1], parts[2] | |||
-- Process arguments with region and date | |||
local labels = {} | |||
for k,v in ipairs(splitLabel(region)) do | |||
local label = getLocalLabel(v); | |||
-- Didn't find a local label? Check for country data (commented out for now). | |||
-- if (label == nil) then | |||
-- if not v:match('^%s*%[') then | |||
-- label = getCountryData(frame, v) | |||
-- end | |||
-- | |||
-- -- Found something? Build a sitelink with it. | |||
-- if (label ~= nil) then | |||
-- label = "[[" .. label .. "|" .. v .. "]]" | |||
-- else | |||
-- label = v | |||
-- end | |||
-- end | |||
table.insert(labels, label) | |||
end | |||
local item = "<span style=\"font-size:97%;\">" .. table.concat(labels,'/') .. ":</span> " .. date | |||
table.insert(items, item) | |||
else | |||
-- Handle cases where there's no = sign (original behavior) | |||
local labels = {} | |||
-- Assuming positional arguments are region followed by date (2 arguments per pair) | |||
if (args[i+1] ~= nil) then | |||
local label = getLocalLabel(args[i]); | |||
-- Didn't find a local label? Check for country data (commented out for now). | |||
-- if (label == nil) then | |||
-- if not args[i]:match('^%s*%[') then | |||
-- label = getCountryData(frame, args[i]) | |||
-- end | |||
-- | |||
-- -- Found something? Build a sitelink with it. | |||
-- if (label ~= nil) then | |||
-- label = "[[" .. label .. "|" .. args[i] .. "]]" | |||
-- else | |||
-- label = args[i] | |||
-- end | |||
-- end | |||
table.insert(labels, label) | |||
table.insert(items, "<span style=\"font-size:97%;\">" .. table.concat(labels,'/') .. ":</span> " .. args[i+1]) | |||
i = i + 2 | |||
else | |||
error("Invalid argument: '" .. args[i] .. "' - Region without a date provided.") | |||
end | |||
end | |||
i = i + 1 | |||
end | |||
-- Add known parameters of Module:List to the table | -- Add known parameters of Module:List to the table |
Revision as of 18:58, 17 March 2024
Documentation for this module may be created at Module:Test/doc
require('strict') 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'] = "[[:Category:North America (Release region)|NA]]", ['EU'] = "[[:Category:Europe (Release region)|EU]]", ['AU'] = "[[:Category:Australia (Release region)|AU]]", ['PAL'] = "[[:Category:Europe (Release region)|PAL]]", ['JP'] = "[[:Category:Japan (Release region)|JP]]", ['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 = {} -- Add named parameter handling here: local i = 1 while (args[i]) do local parts = mw.text.split(args[i], '=') if #parts == 2 then -- Check if there's an = sign local region, date = parts[1], parts[2] -- Process arguments with region and date local labels = {} for k,v in ipairs(splitLabel(region)) do local label = getLocalLabel(v); -- Didn't find a local label? Check for country data (commented out for now). -- if (label == nil) then -- if not v:match('^%s*%[') then -- label = getCountryData(frame, v) -- end -- -- -- Found something? Build a sitelink with it. -- if (label ~= nil) then -- label = "[[" .. label .. "|" .. v .. "]]" -- else -- label = v -- end -- end table.insert(labels, label) end local item = "<span style=\"font-size:97%;\">" .. table.concat(labels,'/') .. ":</span> " .. date table.insert(items, item) else -- Handle cases where there's no = sign (original behavior) local labels = {} -- Assuming positional arguments are region followed by date (2 arguments per pair) if (args[i+1] ~= nil) then local label = getLocalLabel(args[i]); -- Didn't find a local label? Check for country data (commented out for now). -- if (label == nil) then -- if not args[i]:match('^%s*%[') then -- label = getCountryData(frame, args[i]) -- end -- -- -- Found something? Build a sitelink with it. -- if (label ~= nil) then -- label = "[[" .. label .. "|" .. args[i] .. "]]" -- else -- label = args[i] -- end -- end table.insert(labels, label) table.insert(items, "<span style=\"font-size:97%;\">" .. table.concat(labels,'/') .. ":</span> " .. args[i+1]) i = i + 2 else error("Invalid argument: '" .. args[i] .. "' - Region without a date provided.") end end i = i + 1 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) -- Preview message and category local parameterMsg = require('Module:If preview')._warning({ 'Unknown parameter "_VALUE_".' }) .. "[[Category:Pages using vgregion with named parameters|_VALUE_]]" -- 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