Module:Check blp parameter

require('strict')
local p = {}

p.main = function(frame)
	local args = frame:getParent().args
	local yesno = require('Module:Yesno')
	local current_title = mw.title.getCurrentTitle()
	local templates = mw.loadData('Module:WikiProject banner/config').banner_shell.redirects
	local getparam = function(p)
		local TPVmodule = require('Module:Template parameter value').getParameter
		local success, param = TPVmodule(current_title.fullText, templates, p, {ignore_subtemplates=true, ignore_blank=true})
		return success and param or nil
	end
	local check = function(p_table)
		local conflict = false
		local resolved
		for _, p in pairs(p_table) do
			local yn = yesno(p)
			if yn==true or yn==false then -- parameter is set
				if resolved==nil then -- no resolved status yet
					resolved = yn -- resolve to parameter
				elseif yn~=resolved then -- resolved differs from parameter
					conflict = true
				end
			end
		end
		return resolved, conflict
	end
	local conflict, shell_resolved, bio_resolved, resolved
	shell_resolved, conflict = check({getparam('blp'), getparam('living')})
	if not conflict then
		bio_resolved, conflict = check({args.blp, args.living, args.BLP})
		if not conflict then
			resolved, conflict = check({shell_resolved, bio_resolved})
		end
	end
	local out
	if conflict then
		out = 'Pages using WikiProject Biography with conflicting living parameter'
	elseif shell_resolved==nil then
		if bio_resolved==nil then
			if current_title.namespace==1 then-- main talk namespace
				out = 'Biography articles without living parameter'
			end
		else
			out = 'Pages using WikiProject Biography which need living parameter transferring'
		end
	elseif shell_resolved==bio_resolved then
		out = 'Pages using WikiProject Biography with redundant living parameter'
	end
	return out and '[[Category:' .. out .. ']]'
end

return p