יחידה:ParamValidator: הבדלים בין גרסאות בדף
יותר נכון |
ignorelist |
||
| שורה 101: | שורה 101: | ||
local args = frame.args | local args = frame.args | ||
local base = args.base or 'default' | local base = args.base or 'default' | ||
local ignore_list | |||
local options = not empty( args.options ) and mw.text.jsonDecode( args.options ) or {} | local options = not empty( args.options ) and mw.text.jsonDecode( args.options ) or {} | ||
| שורה 109: | שורה 109: | ||
options[k] = options[k] or v | options[k] = options[k] or v | ||
end | end | ||
return options | if args.ignore then | ||
ignore_list = mw.text.jsonDecode( args.ignore ) | |||
end | |||
return options, ignore_list | |||
end | end | ||
| שורה 125: | שורה 129: | ||
function validateParams( frame ) | function validateParams( frame ) | ||
local report = '' | local report = '' | ||
local options = extract_options( frame ) | local options, ignorelist = extract_options( frame ) | ||
local t_frame = frame:getParent() | local t_frame = frame:getParent() | ||
| שורה 137: | שורה 141: | ||
local ignope = function( p_name ) | |||
for _, p in ipairs( ignorelist or {} ) do | |||
if p == p_name then return true end | |||
end | |||
return false | |||
end | |||
local replace_macros = function( s, param_names ) | local replace_macros = function( s, param_names ) | ||
s = mw.ustring.gsub( s, 'templatename', template_name ) | s = mw.ustring.gsub( s, 'templatename', template_name ) | ||
| שורה 171: | שורה 182: | ||
for p_name, value in pairs( t_args ) do | for p_name, value in pairs( t_args ) do | ||
if not td_p[p_name] then | if not td_p[p_name] and not ignore( p_name ) then | ||
if empty( value ) then | if empty( value ) then | ||
if not empty( options['empty-undeclared'] ) then | if not empty( options['empty-undeclared'] ) then | ||
| שורה 185: | שורה 196: | ||
-- and optionally (if options.deprecated exists), use of non-empty deprecated parameters. | -- and optionally (if options.deprecated exists), use of non-empty deprecated parameters. | ||
for p_name, param in pairs( td_p ) do | for p_name, param in pairs( td_p ) do | ||
if param.required and empty( t_args[p_name] ) then | if param.required and empty( t_args[p_name] ) and not ignore( p_name ) then | ||
table.insert( empty_required, p_name ) | table.insert( empty_required, p_name ) | ||
end | end | ||
if options.deprecated and param.deprecated and not empty( t_args[p_name] ) then | if options.deprecated and param.deprecated and not empty( t_args[p_name] ) and not ignore( p_name ) then | ||
table.insert( deprecated, p_name ) | table.insert( deprecated, p_name ) | ||
end | end | ||