Documentation for this module may be created at Module:Sandbox/Nardog/15/doc

require('strict')
local p = {}
local args, hasError

local function check(sources, targets)
	local source
	for _, param in ipairs(sources) do
		if args[param] and args[param] ~= '' then
			source = param
			break
		end
	end
	if not source then
		return nil
	end
	for link in mw.ustring.gmatch(args[source], '%[%[[^%[%]]+%]%]') do
		local name = mw.ustring.match(link, '([^%|]+)%]%]$', 3)
		for _, param in ipairs(targets) do
			if args[param] and args[param] ~= '' and
				mw.ustring.find(args[param], '%f[%w]' .. name .. '%f[%W]')
			then
				mw.log('The link "' .. link .. '" in |' .. source .. '= should be moved to |' .. param .. '=.')
				hasError = true
				break
			end
		end
	end
end

function p.main(frame)
	args = frame:getParent().args
	check({ 'producer', 'producers' }, { 'writer', 'writers', 'screenplay', 'story', 'based_on' })
	check({ 'music' }, { 'cinematography', 'editing' })
	if hasError and mw.title.getCurrentTitle().namespace == 0 then
		return '[[Category:Articles using Infobox film with incorrectly placed links]]'
	end
end

return p