Jump to content

Module:ArgTracker

Script error: The function "docPage" does not exist. Tracks argument names that set in a specific template, include empty arguments, whether meanful in that template.

Usage

Add the following content into a template:

{{ #invoke: ArgTracker | main | _cat = Category name for tracking }}

|_cat= should contain and only contains one %s, which refers the name of the tracked argument. Defaults to %s.

Categories added by this module can usually find in Special:WantedCategories after pages updated.

zh:Module:ArgTracker


local p = {}

function p.main( f )
	local args = f
	local frame = mw.getCurrentFrame()
	if f == frame then
		args = {}
		local parentArgs = frame:getParent().args
		local selfArgs = frame.args
		for k, v in pairs( parentArgs ) do
			args[ k ] = v
		end
		for k, v in pairs( selfArgs ) do
			if not args[ k ] then
				args[ k ] = v
			end
		end
	end

	local category = string.format( '[[Category:%s]]', args[ '_cat' ] or '%s' )
	local categories = {}

	for k, _ in pairs( args ) do
		if k ~= '_cat' then
			table.insert( categories, category:format( k ) )
		end
	end

	return table.concat( categories )
end

return p