Minecraft Wiki

The Minecraft Wiki has moved from Fandom; see the linked discussion page for details.

READ MORE

Minecraft Wiki
Advertisement
[create | history | purge]Documentation
This module has no documentation. If you know how to use this module, please create it.
local VL = mw.ext.VariablesLua

local p = {}

local editionAliases = { -- roughly in order of usage
	["java pre-classic"] = "Java pre-Classic",
	["java classic"] = "Java Classic",
	["java indev"] = "Java Indev",
	["java infdev"] = "Java Infdev",
	["java alpha"] = "Java Alpha",
	["java edition alpha"] = "Java Alpha",
	["java beta"] = "Java Beta",
	["java edition beta"] = "Java Beta",

	["je"] = "Java",
	["java"] = "Java",
	["java edition"] = "Java",

	["java edition upcoming"] = "Java upcoming",
	["java upcoming"] = "Java upcoming",
	["upcoming java"] = "Java upcoming",
	["upcoming java edition"] = "Java upcoming",

	["pe alpha"] = "Pocket Alpha",
	["pocket alpha"] = "Pocket Alpha",
	["pocket edition alpha"] = "Pocket Alpha",

	["pe"] = "Pocket",
	["pocket"] = "Pocket",
	["pocket edition"] = "Pocket",

	["be"] = "Bedrock",
	["bedrock"] = "Bedrock",
	["bedrock edition"] = "Bedrock",

	["be upcoming"] = "Bedrock upcoming",
	["bedrock upcoming"] = "Bedrock upcoming",
	["bedrock edition upcoming"] = "Bedrock upcoming",
	["upcoming bedrock"] = "Bedrock upcoming",
	["upcoming bedrock edition"] = "Bedrock upcoming",
	
	["ce"] = "Console",
	["lce"] = "Console",
	["console"] = "Console",
	["legacy console"] = "Console",
	["console edition"] = "Console",
	["legacy console edition"] = "Console",
	
	["ps4"] = "PS4",
	["playstation4"] = "PS4",
	["playstation 4"] = "PS4",

	["3ds"] = "New 3DS",
	["new3ds"] = "New 3DS",
	["new 3ds"] = "New 3DS",
	
	["earth"] = "Earth",
	["minecraft earth"] = "Earth",

	["dungeons"] = "Dungeons",
	["minecraft dungeons"] = "Dungeons",

	["dungeons arcade"] = "Dungeons Arcade",
	["minecraft dungeons arcade"] = "Dungeons Arcade",

	["legends"] = "Legends",
	["minecraft legends"] = "Legends",
	
	["education"] = "Education",
	["education edition"] = "Education",

	["education upcoming"] = "Education upcoming",
	["education edition upcoming"] = "Education upcoming",
	["upcoming education"] = "Education upcoming",
	["upcoming education edition"] = "Education upcoming",

	-- Used less than established editions but more than niche ones.
	-- This works as an natural seperator between the two.
	["?"] = "Unknown",
	["unknown"] = "Unknown",

	-- rename to MinecraftEdu once module is used and
	-- Category:Unknown MinecraftEDU version history is moved
	["edu"] = "MinecraftEDU",
	["minecraftedu"] = "MinecraftEDU",
	
	["pi"] = "Pi",
	["raspberry pi"] = "Pi",
	
	["china"] = "China",
	
	["realms"] = "Realms",
	
	-- unused
	["bs"] = "Bedrock Server",
	["bds"] = "Bedrock Server",
	["bedrock server"] = "Bedrock Server",
	["bedrock dedicated server"] = "Bedrock Server"
}

local headerText = {
	["Java pre-Classic"] = "[[Java Edition pre-Classic]]",
	["Java Classic"] = "[[Java Edition Classic]]",
	["Java Indev"] = "[[Java Edition Indev]]",
	["Java Infdev"] = "[[Java Edition Infdev]]",
	["Java Alpha"] = "[[Java Edition Alpha]]",
	["Java Beta"] = "[[Java Edition Beta]]",
	["Java"] = "[[Java Edition version history|''Java Edition'']]",
	["Java upcoming"] = "[[Planned versions#Java Edition|Upcoming Java Edition]]",

	["Pocket Alpha"] = "[[Pocket Edition Alpha]]",
	["Pocket"] = "''[[Pocket Edition]]''",

	["Bedrock"] = "[[Bedrock Edition version history|''Bedrock Edition'']]",
	["Bedrock upcoming"] = "[[Planned versions#Bedrock Edition|Upcoming Bedrock Edition]]",
	
	["Console"] = "[[Legacy Console Edition version history|Legacy Console Edition]]",
	["PS4"] = "[[Legacy Console Edition version history|''PlayStation 4 Edition'']]",
	["New 3DS"] = "[[New Nintendo 3DS Edition version history|''New Nintendo 3DS Edition'']]",
	
	["Earth"] = "[[MCE:Version history|''Minecraft Earth'']]",

	["Dungeons"] = "[[MCD:Version_history|''Minecraft Dungeons'']]",

	["Dungeons arcade"] = "[[MCD:Arcade|''Minecraft Dungeons Arcade'']]",

	["Legends"] = "[[MCL:Version_history|''Minecraft Legends'']]",

	["Education"] = "[[Education Edition version history|''Education Edition'']]",
	["Education upcoming"] = "[[Planned versions#Education Edition|Upcoming Education Edition]]",

	["MinecraftEDU"] = "[[MinecraftEdu#Versions|''MinecraftEdu'']]",

	["Pi"] = "[[Pi Edition#Release|''Pi Edition'']]",

	["China"] = "[[China Edition#History|''China Edition'']]",

	["Realms"] = "[[Realms#History|Realms]]",
	
	["Bedrock Server"] = "[[Bedrock Dedicated Server#History|Realms Plus & Bedrock Dedicated Server]]",
}

local upcomingCategories = {
	["java upcoming"] = "[[Category:Java Edition upcoming]]",
	["bedrock upcoming"] = "[[Category:Bedrock Edition upcoming]]",
	["education upcoming"] = "[[Category:Education Edition upcoming]]"
}

local categorySortKeys = {
	["Java"] = {
		["1.0.0"] = "A",
		["1.1"] = "B",
		["1.2.1"] = "C",
		["1.2.5"] = "C",
		["1.3.1"] = "D",
		["1.3.2"] = "D",
		["1.4.2"] = "E",
		["1.4.4"] = "E",
		["1.4.5"] = "E",
		["1.4.6"] = "E",
		["1.4.7"] = "E",
		["1.5"] = "F",
		["1.5.1"] = "F",
		["1.5.2"] = "F",
		["1.6.1"] = "G",
		["1.6.4"] = "G",
		["1.7.2"] = "H",
		["1.7.4"] = "H",
		["1.7.6"] = "H",
		["1.7.10"] = "H",
		["1.8"] = "I",
		["1.8.1"] = "I",
		["1.8.2"] = "I",
		["1.8.8"] = "I",
		["1.9"] = "J",
		["1.9.1"] = "J",
		["1.9.3"] = "J",
		["1.10"] = "K",
		["1.11"] = "L",
		["1.11.1"] = "L",
		["1.12"] = "M",
		["1.12.1"] = "M",
		["1.12.2"] = "M",
		["1.13"] = "N",
		["1.13.1"] = "N",
		["1.13.2"] = "N",
		["1.14"] = "O",
		["1.14.1"] = "O",
		["1.14.2"] = "O",
		["1.14.3"] = "O",
		["1.14.4"] = "O",
		["1.15"] = "P",
		["1.15.1"] = "P",
		["1.15.2"] = "P",
		["1.16"] = "Q",
		["1.16.2"] = "Q",
		["1.16.3"] = "Q",
		["1.16.4"] = "Q",
		["1.16.5"] = "Q",
		["1.17"] = "R",
		["1.17.1"] = "R",
		["1.18"] = "S",
		["1.18.1"] = "S",
		["1.18.2"] = "S",
		["1.19"] = "T",
		["1.19.1"] = "T",
		["1.19.2"] = "T",
		["1.19.3"] = "T",
		["1.19.4"] = "T",
		["1.20"] = "U",
		["1.20.1"] = "U",
		["1.20.2"] = "U",
		["Texture Update"] = "_",
	},
	["Bedrock"] = {
		["1.2.0"] = "A",
		["1.2.3"] = "A",
		["1.2.5"] = "A",
		["1.2.6"] = "A",
		["1.2.10"] = "A",
		["1.2.13"] = "A",
		["1.4.0"] = "B",
		["1.5.0"] = "C",
		["1.6.0"] = "D",
		["1.7.0"] = "E",
		["1.8.0"] = "F",
		["1.9.0"] = "G",
		["1.10.0"] = "H",
		["1.11.0"] = "I",
		["1.12.0"] = "J",
		["1.13.0"] = "K",
		["1.14.0"] = "L",
		["1.14.1"] = "L",
		["1.14.20"] = "L",
		["1.14.30"] = "L",
		["1.16.0"] = "M",
		["1.16.20"] = "M",
		["1.16.100"] = "M",
		["1.16.200"] = "M",
		["1.16.210"] = "M",
		["1.16.220"] = "M",
		["1.17.0"] = "N",
		["1.17.10"] = "N",
		["1.17.30"] = "N",
		["1.17.40"] = "N",
		["1.18.0"] = "O",
		["1.18.10"] = "O",
		["1.18.30"] = "O",
		["1.19.0"] = "P",
		["1.19.10"] = "P",
		["1.19.20"] = "P",
		["1.19.30"] = "P",
		["1.19.40"] = "P",
		["1.19.50"] = "P",
		["1.19.60"] = "P",
		["1.19.70"] = "P",
		["1.19.80"] = "P",
		["1.20.0"] = "Q",
		["1.20.10"] = "Q",
		["1.20.30"] = "Q"
	},
	["Pocket Alpha"] = {
		["V0.8.0"] = "A",
		["0.8.0"] = "A",
		["V0.9.0"] = "B",
		["0.9.0"] = "B",
		["V0.10.0"] = "C",
		["0.10.0"] = "C",
		["V0.11.0"] = "D",
		["0.11.0"] = "D",
		["V0.12.1"] = "E",
		["0.12.1"] = "E",
		["V0.13.0"] = "F",
		["0.13.0"] = "F",
		["V0.14.0"] = "G",
		["0.14.0"] = "G",
		["V0.15.0"] = "H",
		["0.15.0"] = "H",
		["V0.16.0"] = "I",
		["0.16.0"] = "I",
	},
	["Pocket"] = {
		["1.0.0"] = "0",
		["1.1.0"] = "1",
		["1.1.3"] = "3",
	},
	["Java Beta"] = {
		["1.6"] = "6",
		["1.8"] = "8",
	}
}

local function resetVersionVariables(consoleOnly)
	if not consoleOnly then VL.vardefine("history-version") end
	VL.vardefine("history-version-xbox360")
	VL.vardefine("history-version-xbone")
	VL.vardefine("history-version-ps")
	VL.vardefine("history-version-wiiu")
	VL.vardefine("history-version-switch")
end

local function consoleColumn(edition, version, rows, row)
	local id = VL.var("history-id-" .. edition, 0)
	if not version or version == VL.var("history-version-" .. edition) then
		VL.vardefine(
			"history-rowspan-" .. edition .. id,
			VL.var("history-rowspan-" .. edition .. id, rows) + rows
		)
	else
		id = id + 1
		VL.vardefine("history-id-" .. edition, id)
		VL.vardefine("history-version-" .. edition, version or "none")
		local text
		if version ~= "none" and version then
			text = mw.getCurrentFrame():expandTemplate{
				title = "Version link",
				args = {edition .. " " .. version, ""}
			}
		end
		row:tag("th")
			:addClass("nowrap")
			:attr("rowspan", VL.var_final("history-rowspan-" .. edition .. id, rows))
			:wikitext(text)
	end
end

local function versionLink(edition, parentVersion, version, link)
	if version == "unknown" or version == "?" then
		return "[[:Category:Unknown version history|?]]" .. mw.getCurrentFrame():expandTemplate{
			title = 'Translation category',
			args = {
				"Unknown " .. (edition == "Unknown" and "" or edition .. " ") .. "version history",
				sort = parentVersion and categorySortKeys[edition][parentVersion] or "*"
			}
		}
	end

	edition = mw.ustring.gsub(edition, " upcoming", "") -- remove upcoming for version link

	if not link then
		local frame = mw.getCurrentFrame()
		local link

		if parentVersion then
			local prepend = {
				["build"] = true,
				["pre-release"] = true,
				["release"] = true,
				["experimental"] = true,
				["test"] = true,
				["200"] = true,
				["201"] = true
			}
			local parenthesis = { -- deprecated naming scheme for 0.31 verions
				["december"] = true,
				["january"] = true,
				["february"] = true
			}
			local prefix = mw.ustring.match(version, "[%w-]+")
			if prepend[prefix] then
				link = parentVersion .. " " .. version
			elseif prefix == "pre" then
				link = parentVersion .. "-" .. version
			elseif prefix == "release" then
				link = parentVersion
			elseif parenthesis[prefix] then
				link = parentVersion .. " (" .. version .. ")"
			else
				link = version
			end
		end
		
		return frame:expandTemplate{
			title = "Version link",
			args = {edition .. " " .. link, ""}
		}
	end

	if link == "none" then
		return version
	end
	
	if mw.ustring.find(link, "//", 1, true) then -- url
		return "[" .. link .. " " .. version .. "]"
	end

	return "[[" .. link .. "|" .. version .. "]]"
end

local function additonalRows(args, tbl, rows, offset)
	if rows > 1 then
		local frame = mw.getCurrentFrame()
		for i = offset, offset + rows - 2 do
			tbl[#tbl + 1] = tostring(mw.html.create("tr"):tag("td")
				:wikitext(frame:preprocess(args[i]))
				:done() -- without this another tr isn't created
			)
		end
	end
end

function p.main(frame)
	local args = require('Module:ProcessArgs').merge()
	local edition = args[1] ~= "" and (editionAliases[args[1]:lower()] or args[1]:lower())
	if edition == "foot" then
		resetVersionVariables()
		VL.vardefine("history-head")
		return "</table>"
	end
	local html = {}
	if VL.var("history-head") ~= "1" then
		VL.vardefine("history-head", "1")
		html[1] = '<table class="wikitable" data-description="History">'
	end
	local row = mw.html.create("tr")
	if edition then
		resetVersionVariables()
		VL.vardefine("history-edition", edition)
		row:tag("th")
			:attr("colspan", "6")
			:wikitext((headerText[edition] or edition) .. (upcomingCategories[edition] or ""))
		html[#html+1] = tostring(row)
		return table.concat(html)
	end
	local xbox360 = args.xbox
	local xbone = args.xbone
	local ps = args.ps
	local wiiu = args.wiiu
	local switch = args.switch

	if xbox360 or xbone or ps or wiiu or switch then
		local rows = #args - 1
		consoleColumn("xbox360", xbox360, rows, row)
		consoleColumn("xbone", xbone, rows, row)
		consoleColumn("ps", ps, rows, row)
		consoleColumn("wiiu", wiiu, rows, row)
		consoleColumn("switch", switch, rows, row)

		row:tag("td"):wikitext(frame:preprocess(args[2]))
		html[#html+1] = tostring(row)
		additonalRows(args, html, rows, 3)
	else
		resetVersionVariables(true)
		edition = VL.var("history-edition")
		local rows = #args - 2
		local version = args[2]
		local oldVersion = VL.var("history-version")
		local devVersion = args.snap
		local link = args.link
		local devLink = args.slink
		local id = VL.var("history-id", 0)
		if not devVersion or not (version == "" or version == oldVersion) then
			id = id + 1
			VL.vardefine("history-id", id)
			VL.vardefine("history-version", version)
			row:tag("th")
				:addClass("nowrap")
				:attr{
					["rowspan"] = VL.var_final("history-rowspan-" .. id, rows),
					["colspan"] = devVersion and 2 or 5
				}
				:wikitext(versionLink(edition, nil, version, link))
		end
		if devVersion then
			VL.vardefine(
				"history-rowspan-" .. id,
				VL.var("history-rowspan-" .. id, 0) + rows
			)
			row:tag("th")
				:addClass("nowrap")
				:attr{["rowspan"] = rows, ["colspan"] = 3}
				:wikitext(versionLink(edition, version or oldVersion, devVersion, devLink))
		end

		row:tag("td"):wikitext(frame:preprocess(args[3]))
		html[#html + 1] = tostring(row)
		additonalRows(args, html, rows, 4)
	end

	return table.concat(html)
end

return p
Advertisement