Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:FRS notification
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} function p.notification(frame) local args = frame:getParent().args local argNums = getArgNums(args, "title") local out = "" local multipleInHeader = false for index, num in ipairs(argNums) do num = tostring(num) local ending = "" local argsForOutput = { title = args["title" .. num], rfcid = args["rfcid" .. num], } if index == 1 or not isOffsetItemSameHeader(args, argNums, index, -1) then -- it's the first in the header! pass firstInHeader argsForOutput["firstInHeader"] = true end -- if there's multiple of a single type and header, i.e. -- the next item is of the same header, don't -- write the type every time; it's just not needed if index ~= #argNums and isOffsetItemSameHeader(args, argNums, index, 1) then multipleInHeader = true if index == #argNums - 1 or not isOffsetItemSameHeader(args, argNums, index, 2) then -- it's the penultimate in the header; set the ending to " and " ending = frame:expandTemplate{title="MediaWiki:Word-separator"} .. frame:expandTemplate{title="MediaWiki:And"} .. frame:expandTemplate{title="MediaWiki:Word-separator"} else -- it's not the last or penultimate in the header; -- set the ending to ", " ending = frame:expandTemplate{title="MediaWiki:Comma-separator"} .. frame:expandTemplate{title="MediaWiki:Word-separator"} end else argsForOutput["type"] = args["type" .. num] argsForOutput["header"] = args["header" .. num] if multipleInHeader then -- if there've been multiple in the header, queue this -- as the last one, so it'll include the multiple end -- with the header name and type multipleInHeader = false argsForOutput["multipleEnd"] = true end if index ~= #argNums then -- this isn't the last in the list, but it's clearly the -- last in the header; start the next header with an -- "and" to separate the headers ending = frame:expandTemplate{title="MediaWiki:Comma-separator"} .. frame:expandTemplate{title = "MediaWiki:And"} .. frame:expandTemplate{title="MediaWiki:Word-separator"} end end argsForOutput["multipleInHeader"] = multipleInHeader out = out .. frame:expandTemplate{ title = 'FRS notification/content', args = argsForOutput } .. ending end return out 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 -- isOffsetItemSameHeader takes the args, the argument numbers gathered, -- the current index, and a given offset, and checks whether the item at that -- offset is from the same type and the same header. function isOffsetItemSameHeader(args, argNums, index, offset) return args["type" .. argNums[index + offset]] == args["type" .. argNums[index]] and args["header" .. argNums[index + offset]] == args["header" .. argNums[index]] end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:User
(
edit
)
Module:FRS notification/doc
(
edit
)