Module:Video game release: Difference between revisions

Content added Content deleted
(Removing INT. Target article has been deleted, and usage has been cleaned up.)
 
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 6: Line 6:


local labels = {
local labels = {
['NA'] = "[[North America|NA]]",
['NA'] = "[[w:North America|NA]]",
['EU'] = "[[Europe|EU]]",
['EU'] = "[[w:Europe|EU]]",
['EUR'] = "[[Europe|EU]]",
['EUR'] = "[[w:Europe|EU]]",
['AU'] = "[[Australasia|AU]]",
['AU'] = "[[w:Australasia|AU]]",
['AUS'] = "[[Australasia|AU]]",
['AUS'] = "[[w:Australasia|AU]]",
['PAL'] = "[[PAL region|PAL]]",
['PAL'] = "[[w:PAL region|PAL]]",
['SEA'] = "[[Southeast Asia|SEA]]",
['SEA'] = "[[w:Southeast Asia|SEA]]",
['AS'] = "[[Asia|AS]]",
['AS'] = "[[w:Asia|AS]]",
['SA'] = "[[South America|SA]]",
['SA'] = "[[w:South America|SA]]",
['OC'] = "[[Oceania|OC]]",
['OC'] = "[[w:Oceania|OC]]",
['JP'] = "[[w:Japan|JP]]",
['WW'] = "<abbr title=\"Worldwide\">WW</abbr>",
['WW'] = "<abbr title=\"Worldwide\">WW</abbr>",
['?'] = "<abbr title=\"Unknown\">?</abbr>"
['?'] = "<abbr title=\"Unknown\">?</abbr>"

Latest revision as of 01:52, 13 October 2017

Documentation for this module may be created at Module:Video game release/doc

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local cd = require('Module:CountryData')
local p = {}

local labels  = {
    ['NA'] = "[[w:North America|NA]]",
    ['EU'] = "[[w:Europe|EU]]",
    ['EUR'] = "[[w:Europe|EU]]",
    ['AU'] = "[[w:Australasia|AU]]",
    ['AUS'] = "[[w:Australasia|AU]]",
    ['PAL'] = "[[w:PAL region|PAL]]",
    ['SEA'] = "[[w:Southeast Asia|SEA]]",
    ['AS'] = "[[w:Asia|AS]]",
    ['SA'] = "[[w:South America|SA]]",
    ['OC'] = "[[w:Oceania|OC]]",
    ['JP'] = "[[w:Japan|JP]]",
    ['WW'] = "<abbr title=\"Worldwide\">WW</abbr>",
    ['?'] = "<abbr title=\"Unknown\">?</abbr>"
}

local function getLocalLabel(alias)
	local label = labels[string.upper(alias)] 

	return label
end

local 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) then
		local cdtable = cd.gettable(frame,alias,{})
		countryData[ualias] = cdtable['alias']
	end

	return countryData[ualias]
end

function p.main(frame)
	local args = getArgs(frame)
	local out = "<ul style=\"list-style: none none; line-height: inherit; margin: 0px;\">"
	
	-- 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
		out = out .. "<li><span style=\"font-size:95%;\">[["
		if(args[1] ~= nil) then
			out = out .. args[1]
		end
		out = out .. "|"
		if(args[2] ~= nil) then
			out = out .. args[2]
		end
		out = out .. "]]:</span> " .. args[3] .. "[[Category:Pages using vgrelease with two parameter region]]</li>"
	-- 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
		out = out .. "<li>" .. args[2] .. "[[Category:Pages using vgrelease without a region]]</li>"
	-- 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 label = getLocalLabel(args[i]);
    	
	    	-- Didn't find a local label? Check for country data.
    		if(label == nil) then
    			label = getCountryData(frame, args[i])
    		
	    		-- Found something? Build a sitelink with it.
    			if(label ~= nil) then
    				label = "[[" .. label .. "|" .. args[i] .. "]]"
    			else
	    			label = args[i]
				end
			end

			out = out .. "<li><span style=\"font-size:95%;\">" .. label .. ":</span> " .. args[j] .. "</li>"
      
			i = i + 2
			j = j + 2
		end
    end

    out = out .. "</ul>"
    
    -- Check for named parameters
	local parameterMsg = "[[Category:Pages using vgrelease with named parameters|_VALUE_]]"
	if(frame:preprocess( "{{REVISIONID}}" ) == "") then
		-- Preview?
		parameterMsg = "<div class=\"hatnote\" style=\"color:red\"><strong>Warning:</strong> unknown parameter \"_VALUE_\" (this message is shown only in preview).</div>"
	end
	for k, v in pairs(args) do
		if(type(k) ~= 'number') then
			local msg = parameterMsg:gsub('_VALUE_', k)
			out = out .. msg
		end
	end

    return out
end

return p