มอดูล:debug/track

จาก วิกิพจนานุกรม พจนานุกรมเสรี
local pairs = pairs
local pcall = pcall
local type = type

local function expand_template(frame, key)
	-- I tried checking for invalid chars and removing the pcall() in an attempt to speed things up, but this
	-- doesn't work; `frame:expandTemplate` on a nonexistent page throws a Lua error and there's no flag to
	-- disable this.
	-- if not key:find("[#<>%[%]{|}%c\194][\128-\159]?") then
		-- [[Special:WhatLinksHere/Wiktionary:Tracking/KEY]]
		pcall(frame.expandTemplate, frame, { title = "Wiktionary:Tracking/" .. key })
	-- end
end
		
return function(key)
	if not key then
		error("No tracking key supplied to [[Module:debug/track]].")
	end
	local frame = mw.getCurrentFrame()
	if type(key) == "table" then
		for _, v in pairs(key) do
			expand_template(frame, v)
		end
	else
		expand_template(frame, key)
	end
	return true
end