跳转到内容

模組:ArticleHistoryParser

维基百科,自由的百科全书
local TemplateParam = require("Module:Template parameter value")
local p = {}

function p.findDate(frame)
	local args = require("Module:Arguments").getArgs(frame)
	local page = args[1] or args.page
	local targetAction = args[2]
	if not page or not targetAction then
		return ""
	end
	local success, template = TemplateParam.getTemplate(page, {"Article[_ ]history", "ArticleHistory"}, {treat_as_regex = true})
	if not success then
		return ""
	end
	local params = TemplateParam.getAllParameters(template)
	local lastIndex = 0
	for key, values in pairs(params) do
		local num = key:match("^action(%d+)$")
		if num and values[1] == targetAction then
			num = tonumber(num)
			if num > lastIndex then
				lastIndex = num
			end
		end
	end
	if lastIndex > 0 then
		local dateKey = "action" .. lastIndex .. "date"
		if params[dateKey] and params[dateKey][1] then
			return params[dateKey][1]
		end
	end
	return ""
end

return p