http://wiki.naturalphilosophy.org/index.php?title=Module:Check_for_unknown_parameters&feed=atom&action=historyModule:Check for unknown parameters - Revision history2024-03-28T14:41:19ZRevision history for this page on the wikiMediaWiki 1.34.0http://wiki.naturalphilosophy.org/index.php?title=Module:Check_for_unknown_parameters&diff=277062&oldid=prevDeHilster: 1 revision imported2018-05-10T02:04:25Z<p>1 revision imported</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">Revision as of 02:04, 10 May 2018</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>DeHilsterhttp://wiki.naturalphilosophy.org/index.php?title=Module:Check_for_unknown_parameters&diff=244&oldid=prevAdmin: 1 revision imported2016-12-28T04:23:01Z<p>1 revision imported</p>
<p><b>New page</b></p><div>-- This module may be used to compare the arguments passed to the parent<br />
-- with a list of arguments, returning a specified result if an argument is<br />
-- not on the list<br />
local p = {}<br />
<br />
local function trim(s)<br />
return s:match('^%s*(.-)%s*$')<br />
end<br />
<br />
local function isnotempty(s)<br />
return s and trim(s) ~= ''<br />
end<br />
<br />
function p.check (frame)<br />
local args = frame.args<br />
local pargs = frame:getParent().args<br />
local ignoreblank = isnotempty(frame.args['ignoreblank'])<br />
local showblankpos = isnotempty(frame.args['showblankpositional'])<br />
local knownargs = {}<br />
local unknown = frame.args['unknown'] or 'Found _VALUE_, '<br />
local preview = frame.args['preview']<br />
<br />
local values = {}<br />
local res = {}<br />
local regexps = {}<br />
<br />
-- create the list of known args, regular expressions, and the return string<br />
for k, v in pairs(args) do<br />
if type(k) == 'number' then<br />
v = trim(v)<br />
knownargs[v] = 1<br />
elseif k:find('^regexp[1-9][0-9]*$') then<br />
table.insert(regexps, '^' .. v .. '$')<br />
end<br />
end<br />
if isnotempty(preview) then <br />
preview = '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview).</div>'<br />
elseif preview == nil then<br />
preview = unknown<br />
end<br />
<br />
-- loop over the parent args, and make sure they are on the list<br />
for k, v in pairs(pargs) do<br />
if type(k) == 'string' and knownargs[k] == nil then<br />
local knownflag = false<br />
for i, regexp in ipairs(regexps) do<br />
if mw.ustring.match(k, regexp) then<br />
knownflag = true<br />
break<br />
end<br />
end<br />
if not knownflag and ( not ignoreblank or isnotempty(v) ) then<br />
k = mw.ustring.gsub(k, '[^%w\-_ ]', '?')<br />
table.insert(values, k)<br />
end<br />
elseif type(k) == 'number' and <br />
knownargs[tostring(k)] == nil and<br />
( showblankpos or isnotempty(v) )<br />
then<br />
local vlen = mw.ustring.len(v)<br />
v = mw.ustring.sub(v, 1, (vlen < 25) and vlen or 25) <br />
v = mw.ustring.gsub(v, '[^%w\-_ ]', '?')<br />
table.insert(values, k .. ' = ' .. v .. ((vlen >= 25) and ' ...' or ''))<br />
end<br />
end<br />
<br />
-- add resuls to the output tables<br />
if #values > 0 then<br />
if frame:preprocess( "{{REVISIONID}}" ) == "" then<br />
unknown = preview<br />
end<br />
for k, v in pairs(values) do<br />
if v == '' then<br />
-- Fix odd bug for | = which gets stripped to the empty string and<br />
-- breaks category links<br />
v = ' '<br />
end<br />
local r = unknown:gsub('_VALUE_', v)<br />
table.insert(res, r)<br />
end<br />
end<br />
<br />
return table.concat(res)<br />
end<br />
<br />
return p</div>Admin