Este módulo pode ser anexado a uma predefinição para verificar o uso de parâmetros desconhecidos. Diferentemente de muitos outros módulos, este módulo não é implementado por uma predefinição.
Uso
Uso básico
{{#invoke:Check for unknown parameters/Testes|check
|unknown=[[Categoria:Alguma categoria de manutenção]]|arg1|arg2|arg3|argN}}
ou para classificar as entradas na categoria de manutenção por parâmetro com uma mensagem de erro de visualização
{{#invoke:Check for unknown parameters/Testes|check
|unknown=[[Categoria:Alguma categoria de manutenção|_VALUE_]]|preview=parâmetro desconhecido "_VALUE_"
|arg1|arg2|...|argN}}
ou para uma mensagem de erro vermelha explícita
{{#invoke:Check for unknown parameters/Testes|check
|unknown=<spanclass="error">Desculpe, eu não reconheço _VALUE_</span>|arg1|arg2|...|argN}}
Aqui, arg1, arg2, ..., argN, são os parâmetros conhecidos. Parâmetros sem nome (posicionais) também podem ser adicionados: |1|2|nomedoarg1|nomedoarg12|.... Qualquer parâmetro que for usado, mas não estiver nesta lista, fará com que o módulo retorne o que for passado com o parâmetro unknown. A palavra-chave _VALUE_, se for utilizada, será alterada para o nome do parâmetro. Isso é útil tanto para classificar as entradas em uma categoria de rastreamento quanto para fornecer informações mais explícitas.
Por padrão, o módulo não faz distinção entre um parâmetro definido, mas em branco, e um parâmetro que não está em branco. Isto é, tanto |foo=x quanto |foo=, se não forem listados, são reportados. Para rastrear somente parâmetros que não estiverem em branco, use |ignoreblank=1.
Por padrão, o módulo ignora os parâmetros posicionais em branco. Ou seja, um |2= que estiver não listado é ignorado. Para incluir parâmetros posicionais em branco no rastreamento use |showblankpositional=1.
Padrões Lua
Este módulo suporta padrões Lua (semelhante a expressões regulares), que são úteis quando existem muitos parâmetros conhecidos que usam um padrão sistemático. Por exemplo, Infobox3cols usa
para corresponder a todos os parâmetros do formulário headerNUM, labelNUM, dataNUM, dataNUMa, dataNUMb, dataNUMc, ..., rowcellstyleNUM, onde NUM é uma sequência (string) de dígitos.
Exemplo
{{Infobox| above ={{{name|{{{nome|}}}}}}| label1 = Altura
| data1 ={{{height|{{{altura|}}}}}}| label2 = Peso
| data2 ={{{weight|{{{peso|}}}}}}| label3 = Website
| data3 ={{{website|}}}}}<!-- Término da caixa de informações, início do rastreamento-->{{#invoke:Check for unknown parameters/Testes|check
| unknown ={{Testes outro|[[Categoria:Alguma categoria de manutenção|_VALUE_]]}}| preview = parâmetro "_VALUE_" desconhecido
| name | nome
| height | altura
| weight | peso
| website
}}
Chamada de dentro de código Lua
Veja o final de Rugby box para um exemplo simples ou Infobox3cols ou Flag para exemplos mais complicados.
-- Este módulo pode ser usado para comparar os argumentos passados para o parental (superior)-- com uma lista de argumentos, retornando um resultado especificado se um argumento -- não estiver na listalocalp={}localfunctiontrim(s)returns:match('^%s*(.-)%s*$')endlocalfunctionisnotempty(s)returnsands:match('%S')endlocalfunctionclean(text)-- Retorna o texto limpo para exibição e truncado se for muito longo.-- Os marcadores de faixa são substituídos por um texto fictício que-- representa o texto wiki original.localpos,truncatedlocalfunctiontruncate(text)iftruncatedthenreturn''endifmw.ustring.len(text)>25thentruncated=truetext=mw.ustring.sub(text,1,25)..'...'endreturnmw.text.nowiki(text)endlocalparts={}forbefore,tag,remainderintext:gmatch('([^\127]*)\127[^\127]*%-(%l+)%-[^\127]*\127()')dopos=remaindertable.insert(parts,truncate(before)..'<'..tag..'>...</'..tag..'>')endtable.insert(parts,truncate(text:sub(posor1)))returntable.concat(parts)endfunctionp._check(args,pargs)iftype(args)~="table"ortype(pargs)~="table"then-- TODO: Manipulação de errosreturnend-- cria a lista de argumentos conhecidos, expressões regulares e a sequência-- ('string') de retornolocalknownargs={}localregexps={}fork,vinpairs(args)doiftype(k)=='number'thenv=trim(v)knownargs[v]=1elseifk:find('^regexp[1-9][0-9]*$')thentable.insert(regexps,'^'..v..'$')endend-- faz um "loop" sobre os argumentos parentais (superiores) e verifica -- se eles estão na listalocalignoreblank=isnotempty(args['ignoreblank'])localshowblankpos=isnotempty(args['showblankpositional'])localvalues={}fork,vinpairs(pargs)doiftype(k)=='string'andknownargs[k]==nilthenlocalknownflag=falsefor_,regexpinipairs(regexps)doifmw.ustring.match(k,regexp)thenknownflag=truebreakendendifnotknownflagand(notignoreblankorisnotempty(v))thentable.insert(values,clean(k))endelseiftype(k)=='number'andknownargs[tostring(k)]==nilthenlocalknownflag=falsefor_,regexpinipairs(regexps)doifmw.ustring.match(tostring(k),regexp)thenknownflag=truebreakendendifnotknownflagand(showblankposorisnotempty(v))thentable.insert(values,k..' = '..clean(v))endendend-- adiciona os resultados às tabelas de saídalocalres={}if#values>0thenlocalunknown_text=args['unknown']or'Found _VALUE_, 'ifmw.getCurrentFrame():preprocess("{{REVISIONID}}")==""thenlocalpreview_text=args['preview']ifisnotempty(preview_text)thenpreview_text=require('Módulo:If preview')._warning({preview_text})elseifpreview==nilthenpreview_text=unknown_textendunknown_text=preview_textendfor_,vinpairs(values)do-- Corrige (contorna) a falha ('bug') estranha para | = que é removido para-- a sequência ('string') vazia e quebra as ligações ('links') para categoriasifv==''thenv=' 'end-- evita erro com v = 'example%2' ("índice de captura inválido")localr=unknown_text:gsub('_VALUE_',{_VALUE_=v})table.insert(res,r)endendreturntable.concat(res)endfunctionp.check(frame)localargs=frame.argslocalpargs=frame:getParent().argsreturnp._check(args,pargs)endreturnp