本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明

全站通知:

模块:Fixes

来自我的世界地下城WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

使用{{#invoke:fixes|fixes}}来调用此模块。

详细用法请见:Template:Fixes

local p = {}
p.fixes = function( f )
	local args = f:getParent().args
	local project = args.project or 'MC'
	
	local argLen = 0
	for i in ipairs( args ) do
		argLen = i
	end
	
	local parentVersion = f:callParserFunction( '#dplvar', 'parentVersion' )
	local parentMajorVersion = nil
	if parentVersion == nil or parentVersion == '' then
		parentVersion = f:callParserFunction( '#var', 'title' )
	end
	if args.veralias ~= nil and args.veralias ~= '' and parentVersion ~= nil and parentVersion ~= '' then
		parentMajorVersion = table.concat( mw.text.split( string.gsub( parentVersion, '%s', '' ), '[\.]' ), '.', 1, 2 )
	end

	local headerAliases = {
		[';old'] = ';' .. parentVersion .. '前正式版的漏洞',
		[';dev'] = ';' .. parentVersion .. '开发版本的漏洞',
		[';previous'] = ';上个开发版本的漏洞',
		[';prev'] = ';上个开发版本的漏洞',
		[';hotfix'] = ';当前版本的热修复漏洞',
		[';hotfix-launcher'] = ';通过启动器更新热修复的漏洞',
		[';private'] = ';未公开漏洞',
		[';priv'] = ';未公开漏洞',
	}
	
	local sections = {}
	local headers = {}
	local section = {}
	local issues = 0
	local index = {}
	local i = 1
	while i < argLen do
		local this = args[i]
		if this:match( '^;' ) then
			if #section > 0 then
				table.insert( sections, section )
				section = {}
			end
			
			local header = mw.text.trim( this )
			headers[#sections + 1] = headerAliases[header:lower()] or header
		else
			local issue = tonumber( this:match( '%d+' ) )
			if issue then
				table.insert( section, issue )
				issues = issues + 1
				index[issue] = i
			end
			
			i = i + 1
		end
		
		i = i + 1
	end
	if #section > 0 then
		table.insert( sections, section )
	end
	
	local list = {}
	for i, section in ipairs( sections ) do
		local header = headers[i]
		if header and header ~= '' then
			table.insert( list, header )
		end
		
		table.sort( section )
		for _, issue in ipairs( section ) do
			local title = mw.text.trim( args[index[issue] + 1] or '' )
			table.insert( list, '* [[' .. 'mojira:' .. project .. '-' .. issue .. '|' .. project:upper() .. '-' .. issue ..  ']] — ' .. title )
		end
	end

	local prefix = ''

	-- For weird versions
	if args.prefix and args.prefix ~= '' then
		prefix = args.prefix .. ' '
	end
	
	local trackerQuery = {}
	local makeQuery = function( query, arg )
		if arg and arg ~= '' then
			local makeQuery_results = {}
			for v in mw.text.gsplit( arg, '%s*,%s*' ) do
				local trimmed_query = mw.text.trim( v )
				if trimmed_query ~= '' then
					if string.lower( trimmed_query ) == 'future' then
						if parentMajorVersion ~= nil then
							table.insert( makeQuery_results, '"Future Version - ' .. parentMajorVersion .. '+"' )
						end
					else
						table.insert( makeQuery_results, '"' .. prefix .. trimmed_query .. '"' )
					end
				end
			end
			table.insert( trackerQuery, query .. ' in (' .. table.concat( makeQuery_results, ',' ) .. ')' )
		end
	end
	makeQuery( 'fixVersion', args.fixedin )
	makeQuery( 'fixVersion not', args.notfixedin )
	makeQuery( 'affectedVersion', args.affected )
	makeQuery( 'affectedVersion not', args.notaffected )
	
	local makeMatch = function( query, arg )
		if arg and arg ~= '' then
			for v in mw.text.gsplit( arg, '%s*,%s*' ) do
				local trimmed_query = mw.text.trim( v )
				if trimmed_query ~= '' then
					table.insert( trackerQuery, query .. ' ~ "' .. prefix .. trimmed_query .. '"' )
				end
			end
		end
	end
	makeMatch( 'fixVersion', args.fixedmatch )
	makeMatch( 'not fixVersion', args.notfixedmatch )
	makeMatch( 'affectedVersion', args.affectedmatch )
	makeMatch( 'not affectedVersion', args.notaffectedmatch )
	
	if args.otherissuescount then issues = issues + args.otherissuescount end

	local text = '修复了' .. issues .. '个漏洞'
	
	if #trackerQuery > 0 then
		table.insert( trackerQuery, 'project = ' .. project:upper() )

		-- For the sake of [[1.9]]
		if not args.upcoming then
			table.insert( trackerQuery, 'resolution = Fixed' )
		end
		text = '[https://bugs.mojang.com/issues/?jql=' .. mw.uri.encode( table.concat( trackerQuery, ' AND ' ) .. ' ORDER BY key' ) .. ' ' .. text .. ']'
	end
	
	if args.nocount then
		return table.concat( list, '\n' )
	else
		if args.showdesc then
			return ';' .. text .. '\n' .. table.concat( list, '\n' )
		else
			return ';' .. text
		end
	end
end
return p