Module:Check for unknown parameters: Difference between revisions
gsub trick to avoid "Lua error in Module:Check_for_unknown_parameters at line 78: invalid capture index" at Brian Smith (rugby league, born 1954) due to |coachwin%2=64
(less aggressive encoding per request on the talk page) |
(gsub trick to avoid "Lua error in Module:Check_for_unknown_parameters at line 78: invalid capture index" at Brian Smith (rugby league, born 1954) due to |coachwin%2=64) |
||
Line 34: | Line 34: | ||
end | end | ||
end | end | ||
if isnotempty(preview) then | if isnotempty(preview) then | ||
preview = '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview).</div>' | preview = '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview).</div>' | ||
elseif preview == nil then | elseif preview == nil then | ||
Line 54: | Line 54: | ||
table.insert(values, k) | table.insert(values, k) | ||
end | end | ||
elseif type(k) == 'number' and | elseif type(k) == 'number' and | ||
knownargs[tostring(k)] == nil and | knownargs[tostring(k)] == nil and | ||
( showblankpos or isnotempty(v) ) | ( showblankpos or isnotempty(v) ) | ||
then | then | ||
local vlen = mw.ustring.len(v) | local vlen = mw.ustring.len(v) | ||
v = mw.ustring.sub(v, 1, (vlen < 25) and vlen or 25) | v = mw.ustring.sub(v, 1, (vlen < 25) and vlen or 25) | ||
v = mw.text.encode(mw.text.encode(v),'%c%[%]=') | v = mw.text.encode(mw.text.encode(v),'%c%[%]=') | ||
table.insert(values, k .. ' = ' .. v .. ((vlen >= 25) and ' ...' or '')) | table.insert(values, k .. ' = ' .. v .. ((vlen >= 25) and ' ...' or '')) | ||
Line 72: | Line 72: | ||
for k, v in pairs(values) do | for k, v in pairs(values) do | ||
if v == '' then | if v == '' then | ||
-- Fix odd bug for | = which gets stripped to the empty string and | |||
-- breaks category links | |||
v = ' ' | |||
end | end | ||
local r = unknown:gsub('_VALUE_', v) | local r = unknown:gsub('_VALUE_', {_VALUE_ = v}) -- avoid error with v = 'example%2' ("invalid capture index") | ||
table.insert(res, r) | table.insert(res, r) | ||
end | end |