https://wiki.f-si.org/index.php?title=Module:Check_for_unknown_parameters&feed=atom&action=historyModule:Check for unknown parameters - Revision history2024-03-29T15:33:01ZRevision history for this page on the wikiMediaWiki 1.36.1https://wiki.f-si.org/index.php?title=Module:Check_for_unknown_parameters&diff=261&oldid=prevAdmin: 1 revision imported2019-01-25T19:18:12Z<p>1 revision imported</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en">
<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 19:18, 25 January 2019</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Adminhttps://wiki.f-si.org/index.php?title=Module:Check_for_unknown_parameters&diff=260&oldid=prevwikipedia>Frietjes: less aggressive encoding per request on the talk page2019-01-24T12:33:06Z<p>less aggressive encoding per request on the talk page</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.text.encode(mw.text.encode(k),'%c%[%]=')<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.text.encode(mw.text.encode(v),'%c%[%]=')<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>wikipedia>Frietjes