Module:Infobox film/track

MyWikiBiz, Author Your Legacy — Wednesday December 25, 2024
Jump to navigationJump to search

This module checks arguments passed to {{Infobox film}} and adds Category:Articles using Infobox film with incorrectly placed links if a person linked in Template:Para is also listed in Template:Para etc., or a person linked in Template:Para is also listed in Template:Para or Template:Para (in the main namespace only).

It also adds suggestions like The link "[[Samuel G. Engel]]" in |producer= should be moved to |screenplay= in Lua logs (available under "Parser profiling data" in preview). This is done in all namespaces.

Template:Sandbox other


local p = {}

local function check(args, 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 false
	end
	local hasError = false
	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
	return hasError
end

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

return p