Module:Check for unknown parameters: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
m
(Undid revision 880284391 by Frietjes (talk) didn't work)
m (44 revisions imported from wikipedia:Module:Check_for_unknown_parameters)
 
(4 intermediate revisions by 4 users not shown)
Line 9:
 
local function isnotempty(s)
return s and trim(s) ~= :match('%S')
end
 
local function clean(text)
function p.check (frame)
-- Return text cleaned for display and truncated if too long.
local args = frame.args
-- Strip markers are replaced with dummy text representing the original wikitext.
local pargs = frame:getParent().args
local pos, truncated
local ignoreblank = isnotempty(frame.args['ignoreblank'])
local function truncate(text)
local showblankpos = isnotempty(frame.args['showblankpositional'])
if truncated then
local knownargs = {}
return ''
local unknown = frame.args['unknown'] or 'Found _VALUE_, '
end
local preview = frame.args['preview']
local vlen =if mw.ustring.len(vtext) > 25 then
truncated = true
vtext = mw.ustring.sub(vtext, 1, (vlen < 25) and.. vlen or 25)'...'
end
return mw.text.nowiki(text)
end
local resparts = {}
for before, tag, remainder in text:gmatch('([^\127]*)\127[^\127]*%-(%l+)%-[^\127]*\127()') do
pos = remainder
table.insert(parts, truncate(before) .. '&lt;' .. tag .. '&gt;...&lt;/' .. tag .. '&gt;')
end
table.insert(parts, truncate(text:sub(pos or 1)))
return table.concat(parts)
end
 
function p._check(args, pargs)
local values = {}
if type(args) ~= "table" or type(pargs) ~= "table" then
local res = {}
-- TODO: error handling
local regexps = {}
return
end
 
-- create the list of known args, regular expressions, and the return string
local knownargs = {}
local regexps = {}
for k, v in pairs(args) do
if type(k) == 'number' then
Line 33 ⟶ 51:
table.insert(regexps, '^' .. v .. '$')
end
end
if isnotempty(preview) then
preview = '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview).</div>'
elseif preview == nil then
preview = unknown
end
 
-- loop over the parent args, and make sure they are on the list
local ignoreblank = isnotempty(frame.args['ignoreblank'])
local showblankpos = isnotempty(frame.args['showblankpositional'])
local values = {}
for k, v in pairs(pargs) do
if type(k) == 'string' and knownargs[k] == nil then
local knownflag = false
for i_, regexp in ipairs(regexps) do
if mw.ustring.match(k, regexp) then
knownflag = true
Line 51 ⟶ 67:
end
if not knownflag and ( not ignoreblank or isnotempty(v) ) then
table.insert(values, clean(k))
k = mw.text.encode(mw.text.encode(k),'%c%[%]=')
end
table.insert(values, k)
elseif type(k) == 'number' and knownargs[tostring(k)] == nil then
local knownflag = false
for k_, vregexp in pairsipairs(valuesregexps) do
if mw.ustring.match(tostring(k), regexp) then
knownflag = true
break
end
end
if not knownflag and ( showblankpos or isnotempty(v) ) then
table.insert(values, k .. ' = ' .. clean(v .. ((vlen >= 25) and ' ...' or ''))
end
elseif type(k) == 'number' and
knownargs[tostring(k)] == nil and
( showblankpos or isnotempty(v) )
then
local vlen = mw.ustring.len(v)
v = mw.ustring.sub(v, 1, (vlen < 25) and vlen or 25)
v = mw.text.encode(mw.text.encode(v),'%c%[%]=')
table.insert(values, k .. ' = ' .. v .. ((vlen >= 25) and ' ...' or ''))
end
end
 
-- add resulsresults to the output tables
local res = {}
if #values > 0 then
local unknownunknown_text = frame.args['unknown'] or 'Found _VALUE_, '
if frame:preprocess( "{{REVISIONID}}" ) == "" then
 
unknown = preview
if framemw.getCurrentFrame():preprocess( "{{REVISIONID}}" ) == "" then
end
local previewpreview_text = frame.args['preview']
for k, v in pairs(values) do
if v == ''isnotempty(preview_text) then
preview_text = require('Module:If preview')._warning({preview_text})
-- Fix odd bug for | = which gets stripped to the empty string and
elseif preview == nil then
-- breaks category links
vpreview_text = ' 'unknown_text
end
unknown_text = preview_text
end
for _, v in pairs(values) do
-- Fix odd bug for | = which gets stripped to the empty string and
-- breaks category links
if v == '' then v = ' ' end
 
-- avoid error with v = 'example%2' ("invalid capture index")
local r = unknownunknown_text:gsub('_VALUE_', {_VALUE_ = v})
table.insert(res, r)
end
Line 83 ⟶ 109:
 
return table.concat(res)
end
 
function p.check (frame)
local args = frame.args
local pargs = frame:getParent().args
return p._check(args, pargs)
end
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu