Jump to content

Module:FRS notification

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Naypta (talk | contribs) at 22:26, 6 July 2020 (start from 0). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.notification(frame)
	finalString = ""
	args = frame:getParent().args
	argNums = getArgNums(args, "title")
	for index, num in ipairs(argNums) do
		num = tostring(num)
		finalString = finalString .. " " .. frame:expandTemplate{
			title = 'User:Yapperbot/FRS notification/content',
			args = {
				title = args["title" .. num],
				rfcid = args["rfcid" .. num],
				type = args["type" .. num]
			}
		}
		if #argNums ~= 1 and index ~= #argNums then
			if index == (#argNums - 1) then
				-- penultimate element, append "and"
				finalString = finalString .. " and"
			else
				finalString = finalString .. ","
			end
		end
	end
    return finalString
end

function getArgNums(args, prefix)
	-- Returns a table containing the numbers of the arguments that exist
	-- for the specified prefix. For example, if the prefix was 'data', and
	-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
	
	-- This function is adapted from [[Module:Infobox]], and is released under
	-- the Creative Commons Attribution-Share-Alike License 3.0.
	-- https://creativecommons.org/licenses/by-sa/3.0/
	local nums = {}
	for k, v in pairs(args) do
		local num = tostring(k):match('^' .. prefix .. '([0-9]%d*)$')
		if num then table.insert(nums, tonumber(num)) end
	end
	table.sort(nums)
	return nums
end

return p