Module:Exclusive

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴

This module implements {{Exclusive}}.

[view] [edit] [history] [purge]The above documentation is transcluded from Module:Exclusive/doc.
require( 'strict' )
local editionData = {
	java = {
		edition = "''Java Edition''",
		linkname = 'Java Edition',
		category = 'Java Edition'
	},
	bedrock = {
		edition = "''Bedrock Edition''",
		linkname = 'Bedrock Edition',
		category = 'Bedrock Edition'
	},
	console = {
		edition = 'Legacy Console Edition',
		linkname = 'Legacy Console Edition',
		category = 'Legacy Console Edition'
	},
	ps = {
		edition = 'Minecraft for PlayStation',
		linkname = 'Bedrock Edition',
		category = 'Minecraft for PlayStation'
	},
	education = {
		edition = "''Minecraft Education''",
		linkname = 'Minecraft Education',
		category = 'Minecraft Education'
	},
	china = {
		edition = "''China Edition''",
		linkname = 'China Edition',
		category = 'China Edition'
	},
	new3ds = {
		edition = "''New Nintendo 3DS Edition''",
		linkname = 'New Nintendo 3DS Edition',
		category = 'New Nintendo 3DS Edition'
	},
	earth = {
		edition = "''Minecraft Earth''",
		linkname = 'Minecraft Earth',
		category = 'Minecraft Earth'
	},
	mcedu = {
		edition = "''MinecraftEdu''",
		linkname = 'MinecraftEdu',
		category = 'MinecraftEdu'
	},
	['dungeons'] = {
		edition = "''Minecraft Dungeons''",
		linkname = 'Minecraft Dungeons',
		category = 'Minecraft Dungeons'
	},
	['dungeons arcade'] = {
		edition = "''Minecraft Dungeons Arcade''",
		linkname = 'Dungeons:Arcade',
		category = 'Minecraft Dungeons Arcade'
	}
}
editionData['legacy console'] = editionData.console
editionData['edu'] = editionData.education
editionData['new 3ds'] = editionData.new3ds
editionData['3ds'] = editionData.new3ds
editionData['mcd arcade'] = editionData['dungeons arcade']

local p = {}
local curTitle = mw.title.getCurrentTitle()
local contentLang = mw.getContentLanguage()
p.main = function( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge( true )
	else
		f = mw.getCurrentFrame()
	end

	-- Title
	local title = (args.plural and 'These ' or 'This ' ) ..
	( curTitle.nsText == 'Tutorial' and 'tutorial is' or (args.plural and 'features are' or 'feature is' ) ) ..
	' exclusive to $1.'

	-- Generate links and categories
	local editions = {}
	local categories = {}
	for _, arg in ipairs( args ) do
		arg = mw.text.trim(arg or '')
		local d = editionData[ string.lower( arg ) ] or {
			edition = contentLang:ucfirst( arg .. ' Edition'),
			linkname = contentLang:ucfirst( arg .. ' Edition'),
			category = contentLang:ucfirst( arg .. ' Edition')
		}

		-- Link
		table.insert( editions,
			'[[' .. ( d.edition == d.linkname and '' or ( d.linkname .. '|' ) ) .. d.edition .. ']]'
		)

		-- Category
		table.insert( categories,
			'[[Category:' .. d.category .. ( args.section and ' specific information' or '' ) .. ']]'
		)
	end

	if ( args.customtext ) then
		table.insert( categories, '[[Category:Pages using the Exclusive template customtext parameter]]' )
	end

	-- Output
	return f:expandTemplate( {
		title = 'Message box',
		args = {
			class = 'msgbox-blue',
			title = args.customtext or title:gsub('$1', mw.text.listToText( editions ) ),
			text = '',
			image = args.image or 'Information icon.svg',
			mini = args.section
		}
	} ) .. ( args.nocat and '' or curTitle.isContentPage and table.concat( categories, '' ) or '' )
	
end

return p