Jump to content

Module:Check for unknown parameters

Tikang ha Wikipedia

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 listlocalp={}localfunctionisnotempty(s)returnsands:match('^%s*(.-)%s*$')~=''endfunctionp.check(frame)localargs=frame.argslocalpargs=frame:getParent().argslocalignoreblank=isnotempty(frame.args['ignoreblank'])localknownargs={}localunknown='Found _VALUE_, 'localres={}-- create the list of known args, and the return stringfork,vinpairs(args)doiftype(k)=='number'thenv=mw.ustring.gsub(v,'^%s*(.-)%s*$','%1')knownargs[v]=1elseif(k=='unknown'andtype(v)=='string')thenunknown=vendendend-- loop over the parent args, and make sure they are on the listfork,vinpairs(pargs)doif(knownargs[k]==nilandtype(k)=='string')thenif((notignoreblank)or(ignoreblankandisnotempty(v)))thenk=mw.ustring.gsub(k,'[^%w\-_ ]','?')localr=mw.ustring.gsub(unknown,'_VALUE_',k)table.insert(res,r)endendendreturntable.concat(res)endreturnp
close