<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://themidnight.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AParameterCount</id>
	<title>Module:ParameterCount - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://themidnight.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AParameterCount"/>
	<link rel="alternate" type="text/html" href="https://themidnight.wiki/index.php?title=Module:ParameterCount&amp;action=history"/>
	<updated>2026-04-03T18:19:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://themidnight.wiki/index.php?title=Module:ParameterCount&amp;diff=6685&amp;oldid=prev</id>
		<title>Timothy: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://themidnight.wiki/index.php?title=Module:ParameterCount&amp;diff=6685&amp;oldid=prev"/>
		<updated>2023-06-03T20:42:03Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:42, 3 June 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Timothy</name></author>
	</entry>
	<entry>
		<id>https://themidnight.wiki/index.php?title=Module:ParameterCount&amp;diff=6684&amp;oldid=prev</id>
		<title>wikipedia&gt;Mr. Stradivarius: Protected &quot;Module:ParameterCount&quot;: High-risk Lua module: 20,000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://themidnight.wiki/index.php?title=Module:ParameterCount&amp;diff=6684&amp;oldid=prev"/>
		<updated>2017-02-11T14:32:57Z</updated>

		<summary type="html">&lt;p&gt;Protected &amp;quot;&lt;a href=&quot;/wiki/Module:ParameterCount&quot; title=&quot;Module:ParameterCount&quot;&gt;Module:ParameterCount&lt;/a&gt;&amp;quot;: &lt;a href=&quot;/index.php?title=WP:High-risk_templates&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;WP:High-risk templates (page does not exist)&quot;&gt;High-risk Lua module&lt;/a&gt;: 20,000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module produces a count of all the arguments passed to it.&lt;br /&gt;
&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
-- Trim a string&lt;br /&gt;
local function trim(s)&lt;br /&gt;
	return s:match(&amp;#039;^%s*(.-)%s*$&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Test whether a string is blank&lt;br /&gt;
local function isBlank(s)&lt;br /&gt;
	return not s:find(&amp;#039;%S&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Tests whether a string is a valid positional key, and if so, returns it. If&lt;br /&gt;
-- the key is invalid, this returns nil.&lt;br /&gt;
local function isPositionalKey(s)&lt;br /&gt;
	s = trim(s)&lt;br /&gt;
	if s:find(&amp;#039;^[1-9][0-9]*$&amp;#039;) then&lt;br /&gt;
		return tonumber(s)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Return the count of all arguments for which testFunc returns a truthy value.&lt;br /&gt;
local function count(args, testFunc)&lt;br /&gt;
	local ret = 0&lt;br /&gt;
	for key, val in pairs(args) do&lt;br /&gt;
		if testFunc(key, val) then&lt;br /&gt;
			ret = ret + 1&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Check shared arguments and get the parent argument count.&lt;br /&gt;
local function main(frame, testFunc)&lt;br /&gt;
	local blankifiedTestFunc&lt;br /&gt;
	if yesno(frame.args.checkblanks) ~= false then&lt;br /&gt;
		-- Extend the test function to check for blanks as well.&lt;br /&gt;
		blankifiedTestFunc = function (key, val)&lt;br /&gt;
			if not isBlank(val) then&lt;br /&gt;
				return testFunc(key, val)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		blankifiedTestFunc = testFunc&lt;br /&gt;
	end&lt;br /&gt;
	return count(frame:getParent().args, blankifiedTestFunc)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	-- Called with {{#invoke:ParameterCount|all}}&lt;br /&gt;
	-- All specified parameters are counted, even those not supported by the&lt;br /&gt;
	-- template.&lt;br /&gt;
	all = function (frame)&lt;br /&gt;
		return main(frame, function () return true end)&lt;br /&gt;
	end,&lt;br /&gt;
&lt;br /&gt;
	-- Called with {{#invoke:ParameterCount|main}}&lt;br /&gt;
	-- Users can specify a list of parameters to check, and a list of Lua&lt;br /&gt;
	-- Ustring patterns to check each parameter against.&lt;br /&gt;
	main = function (frame)&lt;br /&gt;
		local args = frame.args&lt;br /&gt;
		local keys, patterns = {}, {}&lt;br /&gt;
		&lt;br /&gt;
		-- Get key list&lt;br /&gt;
		for i, key in ipairs(args) do&lt;br /&gt;
			local positionalKey = isPositionalKey(key)&lt;br /&gt;
			if positionalKey then&lt;br /&gt;
				keys[positionalKey] = true&lt;br /&gt;
			else&lt;br /&gt;
				keys[trim(key)] = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- Get patterns&lt;br /&gt;
		do&lt;br /&gt;
			local function getPattern(i)&lt;br /&gt;
				local pattern = args[&amp;#039;pattern&amp;#039; .. tostring(i)]&lt;br /&gt;
				if pattern and pattern ~= &amp;#039;&amp;#039; then&lt;br /&gt;
					return pattern&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			local i = 1&lt;br /&gt;
			local pattern = getPattern(i)&lt;br /&gt;
			while pattern do&lt;br /&gt;
				patterns[i] = pattern&lt;br /&gt;
				i = i + 1&lt;br /&gt;
				pattern = getPattern(i)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- Construct the test function&lt;br /&gt;
		local testFunc = function (key, val)&lt;br /&gt;
			if keys[key] then&lt;br /&gt;
				return true&lt;br /&gt;
			end&lt;br /&gt;
			for i, pattern in ipairs(patterns) do&lt;br /&gt;
				if mw.ustring.find(tostring(key), pattern) then&lt;br /&gt;
					return true&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return false&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		return main(frame, testFunc)&lt;br /&gt;
	end&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>wikipedia&gt;Mr. Stradivarius</name></author>
	</entry>
</feed>