Documentation for this module may be created at Module:Sandbox/Swpb/wrong-namespace/doc

--Implement Wrong namespace template

local p={}

function p.wrongns(frame)
--Get arguments and context
	local content = frame.args[1]
	local yes = frame.args['yes']
	local no = frame.args['no']
	local show = frame.args['show']
	local nowarn = frame.args['nowarn']

	local nstext = mw.title.getCurrentTitle().nsText
	local nsnum = mw.title.getCurrentTitle().namespace

--Internal variables
	local istalk = math.fmod(nsnum,2)
	local isok = 0

--Check if namespace is ok
	if yes then
		for space in mw.ustring.gmatch( yes, "[%s%d]+" ) do
			if space==nstext or space==nsnum then
				isok = 1
				break
			end
		end
	end
	
	if no and not isok then
		for space in mw.ustring.gmatch( no, "[%s%d]+" ) do
			if space == nstext or space == nsnum then
				isok = 0
				break
			elseif space=='notalk' then
				if istalk then isok = 0 end
			elseif space=='talkonly' then
				if istalk then isok = 1 end
			end
		end
	end
	
--Generate output
	local output = ''
	if isok==1 then
		output = content
	else
		if show=='yes' or show=='1' then
			output = content
		end
		if not (nowarn=='yes' or nowarn=='1') then
			output = output .. frame:expandTemplate{ title = 'error', args = { 'Error: This content is not intended for use in this [[Wikipedia:Namespace|namespace]]' } }
		end
	end
	
	return output
end

return p