Mô đun:Class mask

local p = {}
local isarticle = function(class)
	local nonarticleclasses = {'Bản mẫu', 'Tập tin', 'Thể loại', 'Bài định hướng', 'Bài đổi hướng', 'Cổng thông tin', 'Dự án', 'Bản nháp', 'Sách', 'FM'} -- these classes will not be identified as conflicting with NA-class
	local article = true
	for _,v in ipairs(nonarticleclasses) do
		if class==v then -- class matches one of the non-article classes
			article = false
			break
		end
	end
	return article
end
local ucfirst = function(s)
	-- Returns the given string with the first character in upper case.
	-- Should not be used with non-ascii strings.
	return s:sub(1, 1):upper() .. s:sub(2, -1)
end
local isTruthyBParam = function(s)
	s = s and s:lower()
	return not s or s == 'yes' or s == 'y' or s == '1' or s == 'pass' or s == 'na' or s == 'n/a' or s == '¬' or s == 'unused'
end
local resolveFQSgrade = function(grade, args)
	if (argsgrade or args.FQS) == 'yes' then
		return ucfirst(grade)
	else
		return 'chưa xếp hạng'
	end
end
local resolveDefaultGrade = function(args, title, talkDefault)
	if title.subjectPageTitle.isRedirect then
		return resolveFQSgrade('redirect',args)
	end
	local ns = title.namespace
	if ns==1 then -- Talk
		if require('Mô đun:Disambiguation').isDisambiguation(title.subjectPageTitle:getContent()) then
			return resolveFQSgrade('disambig',args)
		else
			return talkDefault
		end
	elseif ns==7 or ns==711 then -- File talk
		return resolveFQSgrade('tập tin', args)
	elseif ns==15 then -- Category talk
		return resolveFQSgrade('thể loại', args)
	elseif ns==101 then -- Portal talk
		return resolveFQSgrade('cổng thông tin', args)
	elseif ns==11 or ns==829 then -- Template talk
		return resolveFQSgrade('bản mẫu', args)
	elseif ns==5 then -- Wikipedia talk
		return resolveFQSgrade('dự án', args)
	-- elseif ns==119 then -- Draft talk
	-- 	return resolveFQSgrade('draft', args)
	elseif ns==13 then -- Help talk
		return resolveFQSgrade('trợ giúp', args)
	else
		return 'NA'
	end
end
local getGrade = function(args, title)
	local grade = args1
	grade = grade and grade:match('^%s*(.-)%s*$'):lower()
	local ret
	if not grade or grade == '¬' then -- undefined
		ret = '¬'
	-- Ucfirst
	elseif grade == 'start' or grade == 'stub' or grade == 'list' then
		if argsgrade ~= 'no' then
			ret = ucfirst(grade)
		end
	-- B
	elseif grade == 'b' then
		local bParams = {'b1', 'b2', 'b3', 'b4', 'b5', 'b6'}
		local isExtended = false
		for _, param in ipairs(bParams) do
			if argsparam then
				isExtended = true
				break
			end
		end
		if isExtended then
			local isB = true
			for _, param in ipairs(bParams) do
				if not isTruthyBParam(argsparam) then
					isB = false
					break
				end
			end
			ret = isB and 'B' or 'C'
		elseif args.b ~= 'no' then
			ret = 'B'
		end
	-- Upper-case
	elseif grade == 'bvcl' or grade == 'dscl' or grade == 'a' or grade == 'bvt' or grade == 'c' then
		if argsgrade ~= 'no' then
			ret = grade:upper()
		end
	elseif grade == 'na' then
		if args.forceNA == 'yes' then
			ret = resolveDefaultGrade(args, title, 'NA')
		else
			ret = 'NA'
		end
	elseif grade == 'tập tin' or grade == 'image' or grade == 'img' then
		ret = resolveFQSgrade('tập tin', args)
	elseif grade == 'thể loại' or grade == 'cat' or grade == 'categ' then
		ret = resolveFQSgrade('thể loại', args)
	elseif grade == 'dab' or grade == 'disambig' or grade == 'bài định hướng' or grade == 'disamb' then
		ret = resolveFQSgrade('bài định hướng', args)
	elseif grade == 'bài đổi hướng' or grade == 'red' or grade == 'redir' then
		ret = resolveFQSgrade('bài đổi hướng', args)
	elseif grade == 'help' then
		ret = resolveFQSgrade('help', args)
	elseif grade == 'cổng thông tin' or grade == 'dự án' or grade == 'draft' then
		ret = resolveFQSgrade(grade, args)
	elseif grade == 'bản mẫu' or grade == 'temp' or grade == 'tpl' or grade == 'templ' then
		ret = resolveFQSgrade('template', args)
	elseif grade == 'fm' then
		if args.fm == 'yes' then
			ret = 'FM'
		else
			ret = resolveFQSgrade('file', args)
		end
	else
		-- Upper-case syntax
		ret = argsgrade:upper()
		-- Lower-case syntax
		if not ret then
			if argsgrade:lower() == 'yes' then
				ret = mw.language.getContentLanguage():ucfirst(grade:lower())
			end
		end
		-- Defaults
		if not ret then
			ret = resolveDefaultGrade(args, title)
		end
	end
	return ret
end
p._main = function(args, title)
	title = title or mw.title.getCurrentTitle()
	local out = 
	if title.namespace == 10 and title.subpageText == 'class' then
		out = mw.getCurrentFrame():expandTemplate{title = 'Class mask/doc warning'}
	end
	out = out .. (getGrade(args, title) or )
	return out
end
p.main = function(frame)
	local getArgs = require('Mô đun:Arguments').getArgs
	local args = getArgs(frame,{removeBlanks=false, wrappers='Bản mẫu:Class mask'})
	return p._main(args)
end
local getclass = function(args, title)
	local class = '¬'
	if args.QUALITY_SCALE == 'inline' then
		class = args.class
	elseif args.QUALITY_SCALE == 'subpage' then
		if mw.title.new(args.BANNER_NAME..'/class').exists then
			local frame = mw.getCurrentFrame()
			class = frame:expandTemplate{title = args.BANNER_NAME..'/class', args = args}
		end
	else
		args.FQS = (args.QUALITY_SCALE == 'extended') and 'yes' or 'no'
		args1 = args.class
		class = p._main(args, title)
	end
	return class
end
p.readarticleclass = function(options, page) -- used by p._quality and Module:Banner shell
	page = page or mw.title.getCurrentTitle().prefixedText
	local get_parameter_value = require("Mô đun:Template parameter value").getValue
	local WPBSredirects = {'Nhóm dự án','Nhóm dự án/sandbox','Bannershell','Đa dự án Wiki','Project shell','Scope shell','WPB','WPBS','WPBannerShell','WP Banner Shell','WP banner shell','WikiProjectBannerShell','WikiProjectBanner Shell','WikiProjectBanners','WikiProject BannerShell','WikiProject Banner Shell','WikiProject Banners','WikiProject Banners Shell','WikiProject Shell','WikiProject banner','WikiProject banner shell/redirect','WikiProject shell','WikiprojectBannerShell','Wikiproject banner holder','Wikiproject banner shell','Wikiprojectbanners','Wikiprojectbannershell','Wpb','Wpbannershell','Wpbsgclass'}
	local success, result = get_parameter_value(page, WPBSredirects, "class", options)
	return success and result
	-- returns FALSE if banner shell template does not exist on page
	-- returns BLANK if class parameter is not defined or is defined blank
	-- otherwise returns class parameter
end
p._quality = function(args)
	local title = args.page and mw.title.new(args.page) or mw.title.getCurrentTitle()
	local local_class = getclass(args, title)
	local prefix, class = 'Y', local_class
	if local_class=='¬' then
		class = '¬'
	elseif args.QUALITY_CRITERIA ~= 'custom' then -- project uses standard scale and will inherit article class if needed
		local article_class = p.readarticleclass({ignore_subtemplates=true},title.prefixedText)
		article_class = article_class and p._main({article_class}, title)
		if article_class then -- banner shell exists
			if article_class ==  then -- no article class defined
				if local_class ==  then -- local class also does not exist, check whether any other class parameters are defined inside the shell
					local classparam = p.readarticleclass({ignore_blank=true, only_subtemplates=true},title.prefixedText)
					if classparam ==  then -- no class parameters defined, display as globally unassessed
						prefix = 'H' -- hide quality class in project banner
					end
				end
			elseif local_class ==  or local_class == article_class then -- local class matches article class or is blank
				prefix = 'H' -- hide quality class in project banner
				class = article_class
			elseif (article_class == 'Chưa xếp hạng') and not isarticle(local_class) then -- article class and local class are both non-article classes
				prefix = 'H'
			else -- article class exists and differs from local class
				prefix = 'X' -- X will indicate to meta banner that classes are different, so trigger a tracking category
			end
		end
	end
	return (args.noprefix and  or prefix) .. class
end
p.quality = function(frame) -- used by WPBM to check global quality and compare with local parameter
	return p._quality(frame.args)
end
return p