Module:Check for unknown parameters

Documentation for this module may be created at Module:Check for unknown parameters/doc

-- This module may be used to compare the arguments passed to the parent-- with a list of arguments, returning a specified result if an argument is-- not on the listlocal p = {}local function trim(s)return s:match('^%s*(.-)%s*$')endlocal function isnotempty(s)return s and trim(s) ~= ''endfunction p.check (frame)local args = frame.argslocal pargs = frame:getParent().argslocal ignoreblank = isnotempty(frame.args['ignoreblank'])local checkpos = isnotempty(frame.args['checkpositional'])local knownargs = {}local unknown = frame.args['unknown'] or 'Found _VALUE_, 'local preview = frame.args['preview']local res = {}local regexps = {}local comments = {}local commentstr = ''local ispreview = frame:preprocess( "{{REVISIONID}}" ) == "" and 1 or 0-- create the list of known args, regular expressions, and the return stringfor k, v in pairs(args) doif type(k) == 'number' thenv = trim(v)knownargs[v] = 1elseif k:find('^regexp[1-9][0-9]*$') thentable.insert(regexps, '^' .. v .. '$')endendif 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 thenpreview = unknownendif ispreview == 1 then unknown = previewignoreblank = falseend-- adds one result to the output tableslocal function addresult(k)if k == '' then-- Fix odd bug for | = which gets stripped to the empty string and-- breaks category linksk = ' 'endlocal r = unknown:gsub('_VALUE_', k)table.insert(res, r)table.insert(comments, '"' .. k .. '"')end-- loop over the parent args, and make sure they are on the listfor k, v in pairs(pargs) doif type(k) == 'string' and knownargs[k] == nil thenlocal knownflag = falsefor i, regexp in ipairs(regexps) doif mw.ustring.match(k, regexp) thenknownflag = truebreakendendif not knownflag and ( not ignoreblank or isnotempty(v) )  thenk = mw.ustring.gsub(k, '[^%w\-_ ]', '?')addresult(k)endelseif checkpos andtype(k) == 'number' and knownargs[tostring(k)] == nil and( not ignoreblank or isnotempty(v) )thenaddresult(k)endendif #comments > 0 thencommentstr = '<!-- Module:Check for unknown parameters results: ' ..table.concat(comments, ', ') .. '-->'endreturn table.concat(res) .. commentstrendreturn p