https://safernicotine.wiki/mediawiki/index.php?title=Module:ParameterCount&feed=atom&action=historyModule:ParameterCount - Revision history2024-03-29T10:53:05ZRevision history for this page on the wikiMediaWiki 1.41.0https://safernicotine.wiki/mediawiki/index.php?title=Module:ParameterCount&diff=4373&oldid=prevRichardpruen: 1 revision imported: Wikipedia article on Varenicline2020-12-17T17:19:50Z<p>1 revision imported: Wikipedia article on Varenicline</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en-GB">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 17:19, 17 December 2020</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en-GB"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Richardpruenhttps://safernicotine.wiki/mediawiki/index.php?title=Module:ParameterCount&diff=4372&oldid=prevwikipedia>Mr. Stradivarius: Protected "Module:ParameterCount": High-risk Lua module: 20,000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))2017-02-11T14:32:57Z<p>Protected "<a href="/mediawiki/index.php/Module:ParameterCount" title="Module:ParameterCount">Module:ParameterCount</a>": <a href="/mediawiki/index.php?title=WP:High-risk_templates&action=edit&redlink=1" class="new" title="WP:High-risk templates (page does not exist)">High-risk Lua module</a>: 20,000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))</p>
<p><b>New page</b></p><div>-- This module produces a count of all the arguments passed to it.<br />
<br />
local yesno = require('Module:Yesno')<br />
<br />
-- Trim a string<br />
local function trim(s)<br />
return s:match('^%s*(.-)%s*$')<br />
end<br />
<br />
-- Test whether a string is blank<br />
local function isBlank(s)<br />
return not s:find('%S')<br />
end<br />
<br />
-- Tests whether a string is a valid positional key, and if so, returns it. If<br />
-- the key is invalid, this returns nil.<br />
local function isPositionalKey(s)<br />
s = trim(s)<br />
if s:find('^[1-9][0-9]*$') then<br />
return tonumber(s)<br />
end<br />
end<br />
<br />
-- Return the count of all arguments for which testFunc returns a truthy value.<br />
local function count(args, testFunc)<br />
local ret = 0<br />
for key, val in pairs(args) do<br />
if testFunc(key, val) then<br />
ret = ret + 1<br />
end<br />
end<br />
return ret<br />
end<br />
<br />
-- Check shared arguments and get the parent argument count.<br />
local function main(frame, testFunc)<br />
local blankifiedTestFunc<br />
if yesno(frame.args.checkblanks) ~= false then<br />
-- Extend the test function to check for blanks as well.<br />
blankifiedTestFunc = function (key, val)<br />
if not isBlank(val) then<br />
return testFunc(key, val)<br />
end<br />
end<br />
else<br />
blankifiedTestFunc = testFunc<br />
end<br />
return count(frame:getParent().args, blankifiedTestFunc)<br />
end<br />
<br />
return {<br />
-- Called with {{#invoke:ParameterCount|all}}<br />
-- All specified parameters are counted, even those not supported by the<br />
-- template.<br />
all = function (frame)<br />
return main(frame, function () return true end)<br />
end,<br />
<br />
-- Called with {{#invoke:ParameterCount|main}}<br />
-- Users can specify a list of parameters to check, and a list of Lua<br />
-- Ustring patterns to check each parameter against.<br />
main = function (frame)<br />
local args = frame.args<br />
local keys, patterns = {}, {}<br />
<br />
-- Get key list<br />
for i, key in ipairs(args) do<br />
local positionalKey = isPositionalKey(key)<br />
if positionalKey then<br />
keys[positionalKey] = true<br />
else<br />
keys[trim(key)] = true<br />
end<br />
end<br />
<br />
-- Get patterns<br />
do<br />
local function getPattern(i)<br />
local pattern = args['pattern' .. tostring(i)]<br />
if pattern and pattern ~= '' then<br />
return pattern<br />
end<br />
end<br />
local i = 1<br />
local pattern = getPattern(i)<br />
while pattern do<br />
patterns[i] = pattern<br />
i = i + 1<br />
pattern = getPattern(i)<br />
end<br />
end<br />
<br />
-- Construct the test function<br />
local testFunc = function (key, val)<br />
if keys[key] then<br />
return true<br />
end<br />
for i, pattern in ipairs(patterns) do<br />
if mw.ustring.find(tostring(key), pattern) then<br />
return true<br />
end<br />
end<br />
return false<br />
end<br />
<br />
return main(frame, testFunc)<br />
end<br />
}</div>wikipedia>Mr. Stradivarius