Minecraft Wiki
(quebrou as páginas já existentes)
(adicionando link para a página em inglês caso não exista em pt (ou tentando))
Linha 93: Linha 93:
 
command = params
 
command = params
 
end
 
end
  +
  +
 
 
 
if args.link then
 
if args.link then
 
if args.link:lower() ~= 'none' then
 
if args.link:lower() ~= 'none' then
commandName = '[[' .. args.link .. '|' .. commandName .. ']]'
+
commandLink = '[[' .. args.link .. '|' .. commandName .. ']]'
 
end
 
end
 
else
 
else
commandName = '[[Comandos/' .. commandName .. '|' .. commandName .. ']]'
+
ing = f:callParserFunction( '#ifexist', 'Comandos/' .. commandName, '0', '1' )
  +
if ing == '0' then
  +
commandLink = '[[Comandos/' .. commandName .. '|' .. commandName .. ']]'
  +
else
  +
commandLink = '[[\:en\:Commands/' .. commandName .. '|' .. commandName .. ']]'
  +
end
 
end
 
end
table.insert( command, 1, commandName )
+
table.insert( command, 1, commandLink )
 
 
 
local slash = '/'
 
local slash = '/'
Linha 115: Linha 122:
 
end
 
end
 
 
  +
local tag = ''
return '<!-- Command start --><code ' .. attr .. '>' .. slash .. table.concat( command, ' ' ):gsub( '&#32;', ' ' ) .. '</code><!-- Command end -->'
 
  +
if ing == 1 then
  +
tag = "<sup class='nowrap' title='Este comando só está disponível na Minecraft Wiki inglesa.'>[''inglês'']</sup>"
  +
end
  +
 
return '<!-- Início do comando --><code ' .. attr .. '>' .. slash .. table.concat( command, ' ' ):gsub( '&#32;', ' ' ) .. '</code>' .. tag .. '<!-- Fim do comando -->'
 
end
 
end
 
return p
 
return p

Edição das 12h24min de 10 de janeiro de 2021

Implementa {{Comando}}.

Dependências

[ver | editar | histórico | purgar]A documentação acima é transcluída de Módulo:Command/doc.
local p = {}
function p.cmd( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	local syntax = mw.loadData( 'Module:Command/Syntax' )
	local fullCommand
	local commandName = args[1]:match( '^%s*/?([^%s]+)' ):lower()
	local params = {}
	local command = {}
	
	for i, v in ipairs( args ) do
		if not fullCommand and v == '...' then
			fullCommand = true
		elseif i > 1 or v:match( '^%s*/?(.+)' ):lower() ~= commandName then
			-- Don't encode if told not to or if there is a sub-command
			if args.encode ~= '0' and not v:find( '<!%-%- Command %-%->' ) then
				v = v:gsub( '<', '&lt;' )
			end
			
			table.insert( params, mw.text.trim( v ) )
		end
	end
	if #params == 1 and ( not args[2] or args[2] == '...' ) and params[1]:find( '%s' ) then
		local startPos, endPos = params[1]:find( '{.+}' )
		if not startPos then
			startPos, endPos = params[1]:find( '<!%-%- Command %-%->.+<!%-%- /Command %-%->' )
		end
		
		if startPos then
			params[1] = params[1]:sub( 1, startPos ) ..
				params[1]:sub( startPos + 1, endPos - 1 ):gsub( '%s', '&#32;' ) ..
				params[1]:sub( endPos )
		end
		
		params = mw.text.split( params[1]:match( '^[^%s]+%s(.+)' ), '%s+' )
	end
	
	if ( fullCommand or params[1] ) and syntax[commandName] then
		local param = 0
		function parseParams( defaultParams, sub )
			local section = {}
			local hasValue
			for i, v in ipairs( defaultParams ) do
				if type( v ) == 'table' then
					local subSection, subHasValue = parseParams( v, true )
					if subHasValue then
						hasValue = true
					end
					table.insert( section, subSection )
				else
					param = param + 1
					if params[param] then
						hasValue = true
						if params[param] ~= '' and params[param] ~= '?' then
							table.insert( section, params[param] )
						end
					end
					if not section[i] and ( fullCommand or params[param] == '?' ) then
						table.insert( section, v )
					end
				end
			end
			section = table.concat( section, ' ' )
			
			if sub then
				if not hasValue then
					if fullCommand then
						section = '(' .. section .. ')'
					else
						section = nil
					end
				end
				
				return section, hasValue
			else
				return section
			end
		end
		
		command = { parseParams( syntax[syntax[commandName]] or syntax[commandName] ) }
		
		-- Add any extra parameters not defined in the syntax
		if #params > param then
			for i, v in ipairs( params ) do
				if i > param then
					table.insert( command, v )
				end
			end
		end
	else
		command = params
	end
	
	
	
	if args.link then
		if args.link:lower() ~= 'none' then
			commandLink = '[[' .. args.link .. '|' .. commandName .. ']]'
		end
	else
		ing = f:callParserFunction( '#ifexist', 'Comandos/' .. commandName, '0', '1' )
		if ing == '0' then
			commandLink = '[[Comandos/' .. commandName .. '|' .. commandName .. ']]'
		else
			commandLink = '[[\:en\:Commands/' .. commandName .. '|' .. commandName .. ']]'
		end
	end
	table.insert( command, 1, commandLink )
	
	local slash = '/'
	if args['/'] == '0' or args.slash == '0' then
		slash = ''
	end
	
	local attr
	if args.long then
		attr = 'style="display: block; padding: 0.8em 1em; margin-bottom: 0.4em; word-wrap: break-word;"'
	else
		attr = 'style="word-break: break-word;"'
	end
	
	local tag = ''
	if ing == 1 then
		tag = "<sup class='nowrap' title='Este comando só está disponível na Minecraft Wiki inglesa.'>[''inglês'']</sup>"
	end
	
	return '<!-- Início do comando --><code ' .. attr .. '>' .. slash .. table.concat( command, ' ' ):gsub( '&#32;', ' ' ) .. '</code>' .. tag .. '<!-- Fim do comando -->'
end
return p