Minecraft Wiki
(Add notitle param)
Tag: Mobile edit
(autoformat)
 
(20 intermediate revisions by 3 users not shown)
Line 2: Line 2:
   
 
-- {{Protocol version}}
 
-- {{Protocol version}}
function p.protocol_version( f )
+
function p.protocol_version(f)
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
+
args = require("Module:ProcessArgs").merge(true)
end
+
end
local version = mw.text.trim( args[1] or '' )
+
local version = mw.text.trim(args[1] or "")
  +
 
-- load the values from the submodule
+
-- load the values from the submodule
local version_data = mw.loadData( 'Module:Protocol version/Versions' ).versions[version]
+
local version_data = mw.loadData("Module:Protocol version/Versions").versions[version]
  +
local category = ''
+
local category = ""
local value
+
local value
if version_data then
 
 
local title = mw.title.getCurrentTitle()
value = version_data.protocol
 
  +
else
 
 
if version_data then
value = '[[Template:Protocol version#Unknown version|]]'
 
 
if version_data.protocol then
local title = mw.title.getCurrentTitle()
 
 
if version_data.protocol == "Unknown" then
if not args.nocat and title.namespace == 0 and not title.isSubpage then
 
category = '[[Category:Unknown Protocol version]]'
+
value = "[[Template:Protocol version#Unknown version|Unknown]]"
 
if not args.nocat and title.namespace == 0 and not title.isSubpage then
end
 
 
category = "[[Category:Unknown protocol version]]"
end
+
end
return value .. category
 
 
else
 
value = version_data.protocol
 
end
 
else
 
value = "N/A"
  +
end
  +
else
 
value = "[[Template:Protocol version#Unknown version|Pending]]"
 
if not args.nocat and title.namespace == 0 and not title.isSubpage then
  +
category = "[[Category:Pending protocol version]]"
  +
end
  +
end
 
return value .. category
 
end
 
end
   
 
-- {{Data version}}
 
-- {{Data version}}
function p.data_version( f )
+
function p.data_version(f)
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
+
args = require("Module:ProcessArgs").merge(true)
end
+
end
local version = mw.text.trim( args[1] or '' )
+
local version = mw.text.trim(args[1] or "")
  +
 
-- load the values from the submodule
+
-- load the values from the submodule
local version_data = mw.loadData( 'Module:Protocol version/Versions' ).versions[version]
+
local version_data = mw.loadData("Module:Protocol version/Versions").versions[version]
  +
local category = ''
+
local category = ""
local value
+
local value
if version_data then
 
 
local title = mw.title.getCurrentTitle()
if version_data.data then
 
  +
value = version_data.data
 
  +
if version_data then
else
 
  +
if version_data.data then
value = "N/A"
 
  +
if version_data.data == "Unknown" then
end
 
 
value = "[[Template:Data version#Unknown version|Unknown]]"
else
 
  +
if not args.nocat and title.namespace == 0 and not title.isSubpage then
value = '[[Template:Data version#Unknown version|]]'
 
  +
category = "[[Category:Unknown data version]]"
local title = mw.title.getCurrentTitle()
 
  +
end
if not args.nocat and title.namespace == 0 and not title.isSubpage then
 
  +
else
category = '[[Category:Unknown Data version]]'
 
 
value = version_data.data
end
 
end
+
end
  +
else
return value .. category
 
  +
value = "N/A"
  +
end
  +
else
  +
value = "[[Template:Data version#Unknown version|Pending]]"
  +
if not args.nocat and title.namespace == 0 and not title.isSubpage then
  +
category = "[[Category:Pending data version]]"
  +
end
  +
end
 
return value .. category
 
end
 
end
   
 
-- Version table ({{Protocol version/table}})
 
-- Version table ({{Protocol version/table}})
function p.table( f )
+
function p.table(f)
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
+
args = require("Module:ProcessArgs").merge(true)
end
+
end
 
local html = {}
 
local groups = mw.loadData( 'Module:Protocol version/Versions' ).groups
 
   
 
local html = {}
for _, group in ipairs(groups) do
 
 
local groups = mw.loadData("Module:Protocol version/Versions").groups
local include = true
 
  +
if #args ~= 0 then
 
 
for _, group in ipairs(groups) do
include = nil
 
 
local include = true
for __, name in ipairs(args) do
 
if name == group.name then
+
if #args ~= 0 then
include = true
+
include = nil
 
for __, name in ipairs(args) do
break
 
  +
if name == group.name then
 
include = true
 
break
 
end
 
end
 
end
 
end
Line 76: Line 98:
   
 
if include then
 
if include then
if not args.notitle then
+
if not args.notitle then
table.insert( html, "=== [[" .. group.link .. '|' .. group.name .. "]] ===\n" )
+
table.insert(html, "=== [[" .. group.link .. "|" .. group.name .. "]] ===\n")
  +
end
end
 
if group.desc ~= nil then
+
if group.desc ~= nil then
table.insert( html, group.desc .. '\n')
+
table.insert(html, group.desc .. "\n")
end
+
end
table.insert( html, "<table class='wikitable sortable jquery-tablesorter'>\n" )
+
table.insert(html, "<table class='wikitable sortable jquery-tablesorter'>\n")
table.insert( html, '<tr>\n' )
+
table.insert(html, "<tr>\n")
table.insert( html, '<th>Client version</th>\n' )
+
table.insert(html, "<th>Client version</th>\n")
table.insert( html, '<th>Protocol version</th>\n' )
+
table.insert(html, "<th>[[Protocol version]]</th>\n")
if group.has_data_versions then
+
if group.has_data_versions then
table.insert( html, '<th>Data version</th>\n' )
+
table.insert(html, "<th>[[Data version]]</th>\n")
end
+
end
table.insert( html, '</tr>\n' )
+
table.insert(html, "</tr>\n")
  +
 
local num_same_protocol
+
local num_same_protocol
local last_protocol = -1
+
local last_protocol = -1
local protocol_row
+
local protocol_row
  +
 
  +
local num_same_data
for __, version in ipairs(group.values) do
 
  +
local last_data = -1
table.insert( html, '<tr>' )
 
  +
local data_row
table.insert( html, '<td>[[' .. version.name .. ']]</td>' )
 
  +
if version.protocol ~= last_protocol or version.force_split then
 
 
for __, version in ipairs(group.values) do
last_protocol = version.protocol
 
 
table.insert(html, "<tr>")
num_same_protocol = 1
 
table.insert( html, '<td>' .. version.protocol .. '</td>' )
+
table.insert(html, "<td>[[" .. version.name .. "]]</td>\n")
 
if version.protocol ~= last_protocol or version.force_split_protocol then
protocol_row = #html
 
 
last_protocol = version.protocol
else
 
num_same_protocol = num_same_protocol + 1
+
num_same_protocol = 1
html[protocol_row] = '<td rowspan="' .. num_same_protocol .. '">' .. version.protocol .. '</td>'
+
table.insert(html, '<td style="text-align:center">' .. version.protocol .. "</td>\n")
 
protocol_row = #html
end
 
  +
else
if group.has_data_versions then
 
  +
num_same_protocol = num_same_protocol + 1
if version.data then
 
  +
html[protocol_row] = '<td style="text-align:center" rowspan="'
table.insert( html, '<td>' .. version.data .. '</td>' )
 
 
.. num_same_protocol
else
 
  +
.. '">'
table.insert( html, '<td>—</td>' )
 
  +
.. version.protocol
end
 
  +
.. "</td>\n"
end
 
  +
end
table.insert( html, '</tr>' )
 
 
if group.has_data_versions then
end
 
 
if version.data then
 
  +
if version.data ~= last_data then
table.insert( html, '</table>\n' )
 
  +
last_data = version.data
end
 
  +
num_same_data = 1
end
 
 
table.insert(html, '<td style="text-align:center">' .. version.data .. "</td>\n")
  +
data_row = #html
  +
else
  +
num_same_data = num_same_data + 1
  +
html[data_row] = '<td style="text-align:center" rowspan="'
  +
.. num_same_data
  +
.. '">'
  +
.. version.data
  +
.. "</td>\n"
  +
end
  +
else
 
if last_data ~= "N/A" then
  +
last_data = "N/A"
  +
num_same_data = 1
  +
table.insert(html, '<td style="text-align:center">N/A</td>\n')
  +
data_row = #html
  +
else
  +
num_same_data = num_same_data + 1
  +
html[data_row] = '<td style="text-align:center" rowspan="'
  +
.. num_same_data
  +
.. '">'
  +
.. "N/A </td>\n"
  +
end
  +
end
  +
end
 
table.insert(html, "</tr>\n")
  +
end
  +
 
table.insert(html, "</table>\n")
  +
end
  +
end
   
return table.concat( html )
+
return table.concat(html)
 
end
 
end
   

Latest revision as of 05:48, 6 May 2021

[view | edit | history | purge]DocumentationJump to code ↴

This module implements {{Protocol version}}, {{Data version}}, and {{Protocol version/Table}}.

The actual data used by this module is stored in Module:Protocol version/Versions.

See also

[view | edit | history | purge]The above documentation is transcluded from Module:Protocol version/doc.
local p = {}

-- {{Protocol version}}
function p.protocol_version(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = require("Module:ProcessArgs").merge(true)
	end
	local version = mw.text.trim(args[1] or "")

	-- load the values from the submodule
	local version_data = mw.loadData("Module:Protocol version/Versions").versions[version]

	local category = ""
	local value
	local title = mw.title.getCurrentTitle()

	if version_data then
		if version_data.protocol then
			if version_data.protocol == "Unknown" then
				value = "[[Template:Protocol version#Unknown version|Unknown]]"
				if not args.nocat and title.namespace == 0 and not title.isSubpage then
					category = "[[Category:Unknown protocol version]]"
				end
			else
				value = version_data.protocol
			end
		else
			value = "N/A"
		end
	else
		value = "[[Template:Protocol version#Unknown version|Pending]]"
		if not args.nocat and title.namespace == 0 and not title.isSubpage then
			category = "[[Category:Pending protocol version]]"
		end
	end
	return value .. category
end

-- {{Data version}}
function p.data_version(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = require("Module:ProcessArgs").merge(true)
	end
	local version = mw.text.trim(args[1] or "")

	-- load the values from the submodule
	local version_data = mw.loadData("Module:Protocol version/Versions").versions[version]

	local category = ""
	local value
	local title = mw.title.getCurrentTitle()

	if version_data then
		if version_data.data then
			if version_data.data == "Unknown" then
				value = "[[Template:Data version#Unknown version|Unknown]]"
				if not args.nocat and title.namespace == 0 and not title.isSubpage then
					category = "[[Category:Unknown data version]]"
				end
			else
				value = version_data.data
			end
		else
			value = "N/A"
		end
	else
		value = "[[Template:Data version#Unknown version|Pending]]"
		if not args.nocat and title.namespace == 0 and not title.isSubpage then
			category = "[[Category:Pending data version]]"
		end
	end
	return value .. category
end

-- Version table ({{Protocol version/table}})
function p.table(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = require("Module:ProcessArgs").merge(true)
	end

	local html = {}
	local groups = mw.loadData("Module:Protocol version/Versions").groups

	for _, group in ipairs(groups) do
		local include = true
		if #args ~= 0 then
			include = nil
			for __, name in ipairs(args) do
				if name == group.name then
					include = true
					break
				end
			end
		end

		if include then
			if not args.notitle then
				table.insert(html, "=== [[" .. group.link .. "|" .. group.name .. "]] ===\n")
			end
			if group.desc ~= nil then
				table.insert(html, group.desc .. "\n")
			end
			table.insert(html, "<table class='wikitable sortable jquery-tablesorter'>\n")
			table.insert(html, "<tr>\n")
			table.insert(html, "<th>Client version</th>\n")
			table.insert(html, "<th>[[Protocol version]]</th>\n")
			if group.has_data_versions then
				table.insert(html, "<th>[[Data version]]</th>\n")
			end
			table.insert(html, "</tr>\n")

			local num_same_protocol
			local last_protocol = -1
			local protocol_row

			local num_same_data
			local last_data = -1
			local data_row

			for __, version in ipairs(group.values) do
				table.insert(html, "<tr>")
				table.insert(html, "<td>[[" .. version.name .. "]]</td>\n")
				if version.protocol ~= last_protocol or version.force_split_protocol then
					last_protocol = version.protocol
					num_same_protocol = 1
					table.insert(html, '<td style="text-align:center">' .. version.protocol .. "</td>\n")
					protocol_row = #html
				else
					num_same_protocol = num_same_protocol + 1
					html[protocol_row] = '<td style="text-align:center" rowspan="'
						.. num_same_protocol
						.. '">'
						.. version.protocol
						.. "</td>\n"
				end
				if group.has_data_versions then
					if version.data then
						if version.data ~= last_data then
							last_data = version.data
							num_same_data = 1
							table.insert(html, '<td style="text-align:center">' .. version.data .. "</td>\n")
							data_row = #html
						else
							num_same_data = num_same_data + 1
							html[data_row] = '<td style="text-align:center" rowspan="'
								.. num_same_data
								.. '">'
								.. version.data
								.. "</td>\n"
						end
					else
						if last_data ~= "N/A" then
							last_data = "N/A"
							num_same_data = 1
							table.insert(html, '<td style="text-align:center">N/A</td>\n')
							data_row = #html
						else
							num_same_data = num_same_data + 1
							html[data_row] = '<td style="text-align:center" rowspan="'
								.. num_same_data
								.. '">'
								.. "N/A </td>\n"
						end
					end
				end
				table.insert(html, "</tr>\n")
			end

			table.insert(html, "</table>\n")
		end
	end

	return table.concat(html)
end

return p