Module:KnightMiner/Sandbox

local p = {} function p.row( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end -- Define some functions for commonly used stuffs function var( name, default ) return f:callParserFunction( '#var', 'history-'.. name, default ) end function define( name, value ) f:callParserFunction( '#vardefine', 'history-' .. name, value or '' ) return value or '' end function verlink( ver, title ) return f:expandTemplate{ title = 'Version link', args = { ver, title } } end local argLen = 0 for i in ipairs( args ) do		argLen = i	end local rows = argLen - 2 -- Figure out the mode for the history table -- Might want to mw.loadData this local modes = { -- Computer ['pre-classic']     = 'Pre-classic', c                   = 'Classic', classic             = 'Classic', s                   = 'Classic', st                  = 'Classic', stest               = 'Classic', survival            = 'Classic', ['survival test']   = 'Classic', i                   = 'Indev', ['in']              = 'Indev', id                  = 'Indev', indev               = 'Indev', inf                 = 'Infdev', infdev              = 'Infdev', infdev              = 'Infdev', a                   = 'Alpha', alpha               = 'Alpha', b                   = 'Alpha', beta                = 'Alpha', r                   = 'release', f                   = 'release', full                = 'release', rel                 = 'release', release             = 'release', official            = 'release', ['official release'] = 'release', u                   = 'weekly', upcoming            = 'weekly', -- Pocket ['pocket alpha']          = 'pocket Alpha', ['pocket edition alpha']  = 'pocket Alpha', pa                        = 'pocket Alpha', pocketa                   = 'pocket Alpha', ['pocket beta']           = 'pocket Beta', pb                        = 'pocket Beta', pocketb                   = 'pocket Beta', ['pocket upcoming']       = 'pocket upcoming', ['pocket editon upcoming'] = 'pocket upcoming', pu                        = 'pocket upcoming', pocketu                   = 'pocket upcoming', -- Console xbox                     = 'console', ['xbox edition']         = 'console', ps3                      = 'console', ['playstation 3']        = 'console', ['ps3 edition']          = 'console', ['playstation 3 edition'] = 'console', console                  = 'console', ['console edition']      = 'console', -- Other realms              = 'realms', ['minecraft realms'] = 'realms', ['?']               = 'unknown', unknown             = 'unknown', foot                = 'foot', footer              = 'foot' }	local nomode, mode if args[1] == '' then nomode = 1 mode = var( 'mode' ) -- No need to define the variable if using the footer elseif args[1] == 'foot' or args[1] == 'footer' then mode = 'foot' define( 'mode' ) else mode = define( 'mode', modes[args[1]:lower] or args[1] ) end local prefixs = { release            = '', weekly             = '', ['pocket upcoming'] = 'pocket ' }	local prefix = prefixs[mode] or mode .. ' '	local overrides = { none = '', [] = ,		unknown = '?', ['?'] = '?'	}	-- Create the output local output = {} -- Main cell function function insertCell( name, colspan, rows ) local index = tonumber( var( name .. '-index', 0 ) ) local rowspan = var( name .. '-rowspan-' .. index, 0 ) local arg = args[name] or '' if name == 'release' then arg = args[2] or '' end if arg == var( name .. '-ver', 'none' ) or name == 'release' and args[2] == '' then define( name .. '-rowspan-' .. index, rowspan + rows ) else define( name .. '-ver', arg ) index = index + 1 define( name .. '-index', index ) define( name .. '-rowspan-' .. index, rows ) local override = overrides[arg] -- Define the link for the cell local link = args[(				( name == 'release' and '' ) or				name			) .. 'link'] or 'ver' if link == 'none' then link = override or arg elseif link == 'ver' then if mode == 'realms' then link = arg else link = override or verlink(						prefix .. arg,						arg:gsub( '%s*%(.-%)$', '' )					) end else if link:find( '//' ) then link = '[' .. link .. ' ' .. arg .. ']'				else link =  .. arg ..  end end -- Data of the cell local data = { '! colspan="',				colspan,				'" rowspan="',				f:callParserFunction( '#var_final', 'history-' .. name .. '-rowspan-' .. index ),				'" | ', link }			table.insert( output, table.concat( data ) ) end end if var( "head" ) ~= '1' then table.insert( output, ' {| class="wikitable"' ) define( "head", 1 ) end if mode == 'foot' then table.insert( output, '|}' ) define( 'head', 0 ) define( 'release-ver' ) define( 'xbox-ver' ) define( 'xbone-ver' ) define( 'ps-ver' ) elseif not nomode then define( 'release-ver' ) define( 'xbox-ver' ) define( 'xbone-ver' ) define( 'ps-ver' ) local headers = { release            = 'Official release', weekly             = 'Upcoming', ['pocket Alpha']   = 'Pocket Edition Alpha', ['pocket Beta']    = 'Pocket Edition Beta', ['pocket upcoming'] = 'Upcoming Pocket Edition', console            = 'Console Edition', ['pi Alpha']       = 'Pi Edition', realms             = 'Realms', unknown            = 'Unknown' }		local header = headers[mode] or  .. mode ..  table.insert( output, '|-\n! colspan="7" | ' .. header ) else table.insert( output, '|-' ) if mode == 'console' and ( args.xbox or args.xbone or args.ps ) then define( 'release-ver' ) if args[2] then rows = rows + 1 end insertCell( 'xbox', 2, rows ) insertCell( 'xbone', 2, rows ) insertCell( 'ps', 2, rows ) if args[2] then table.insert( output, '| ' .. args[2] ) end if args[3] then table.insert( output, '|-\n| ' .. args[3] ) end else define( 'xbox-ver' ) define( 'xbone-ver' ) define( 'ps-ver' ) local snap = args.snap insertCell( 'release', snap and 3 or 6, rows ) if snap then local overrides = { release = '', unknown = '?', ['?'] = '?'				}				local override = overrides[arg] local link = args.slink or 'ver' if link == 'none' then link = override or arg elseif link == 'ver' then if override then link = override else local linkdata = snap if snap:find( '^pre' ) or snap:find( '^RC') then linkdata = var( 'release-ver' ) .. '-' .. snap elseif snap:find( '^build' ) then linkdata = var( 'release-ver' ) .. ' ' .. snap end link = verlink(							prefix .. linkdata,							snap:gsub( '%((.-)%)$', '%1' )						) end else if link:find( '//' ) then link = '[' .. link .. ' ' .. arg .. ']'					else link =  .. arg ..  end end local data = { '! colspan="3" rowspan="',					rows,					'" | ', link }				table.insert( output, table.concat( data ) ) end if args[3] then table.insert( output, '| ' .. args[3] ) end end for i, v in ipairs( args ) do			if i ~= 1 and i ~= 2 and i ~= 3 then table.insert( output, '|-\n| ' .. v ) end end end -- Insert categories local category = '' if mw.title.getCurrentTitle.namespace == 0 then if mode == 'weekly' then table.insert( category, '' ) elseif mode == 'pocket upcoming' then table.insert( category, '' ) elseif mode == 'console' and not ( args.xbox or args.xbone or args.ps or args.link ) then table.insert( category, f:expandTemplate{ name = 'translation category', args = { 'History uses old console format' } } ) end local parameters = { mode, args[2], args.snap, args.xbox, args.xbone, args.ps } for _, v in pairs( parameters ) do			if v == 'unknown' or v == '?' then table.insert( category, f:expandTemplate{ name = 'translation category', args = { 'Unknown version history' } } ) break end end category = table.concat( category ) end return table.concat( output, '\n' ) .. category end

return p