https://wiki.sg/index.php?title=Module:Check_for_unknown_parameters&feed=atom&action=historyModule:Check for unknown parameters - Revision history2024-03-28T23:29:18ZRevision history for this page on the wikiMediaWiki 1.39.2https://wiki.sg/index.php?title=Module:Check_for_unknown_parameters&diff=774&oldid=prevJoe Tan: 1 revision imported2019-03-01T07:28:38Z<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 15:28, 1 March 2019</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Joe Tanhttps://wiki.sg/index.php?title=Module:Check_for_unknown_parameters&diff=773&oldid=prevTemplate>Johnuniq: update from sandbox to sanitize displayed parameters, replacing strip markers with "<tag>...</tag>" per User talk:Johnuniq#Check for unknown parameters2019-02-03T01:04:52Z<p>update from sandbox to sanitize displayed parameters, replacing strip markers with "<tag>...</tag>" per <a href="/index.php?title=User_talk:Johnuniq&action=edit&redlink=1" class="new" title="User talk:Johnuniq (page does not exist)">User talk:Johnuniq#Check for unknown parameters</a></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 s:match('%S')<br />
end<br />
<br />
local function clean(text)<br />
-- Return text cleaned for display and truncated if too long.<br />
-- Strip markers are replaced with dummy text representing the original wikitext.<br />
local pos, truncated<br />
local function truncate(text)<br />
if truncated then<br />
return ''<br />
end<br />
if mw.ustring.len(text) > 25 then<br />
truncated = true<br />
text = mw.ustring.sub(text, 1, 25) .. '...'<br />
end<br />
return mw.text.nowiki(text)<br />
end<br />
local parts = {}<br />
for before, tag, remainder in text:gmatch('([^\127]*)\127[^\127]*%-(%l+)%-[^\127]*\127()') do<br />
pos = remainder<br />
table.insert(parts, truncate(before) .. '&lt;' .. tag .. '&gt;...&lt;/' .. tag .. '&gt;')<br />
end<br />
table.insert(parts, truncate(text:sub(pos or 1)))<br />
return table.concat(parts)<br />
end<br />
<br />
function p.check (frame)<br />
local args = frame.args<br />
local pargs = frame:getParent().args<br />
local ignoreblank = isnotempty(args['ignoreblank'])<br />
local showblankpos = isnotempty(args['showblankpositional'])<br />
local knownargs = {}<br />
local unknown = args['unknown'] or 'Found _VALUE_, '<br />
local preview = 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 _, 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 />
table.insert(values, clean(k))<br />
end<br />
elseif type(k) == 'number' and<br />
knownargs[tostring(k)] == nil and<br />
( showblankpos or isnotempty(v) )<br />
then<br />
table.insert(values, k .. ' = ' .. clean(v))<br />
end<br />
end<br />
<br />
-- add results to the output tables<br />
if #values > 0 then<br />
if frame:preprocess( "{{REVISIONID}}" ) == "" then<br />
unknown = preview<br />
end<br />
for _, 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 />
-- avoid error with v = 'example%2' ("invalid capture index")<br />
local r = unknown:gsub('_VALUE_', {_VALUE_ = v})<br />
table.insert(res, r)<br />
end<br />
end<br />
<br />
return table.concat(res)<br />
end<br />
<br />
return p</div>Template>Johnuniq