Jump to content

Module:Parameter validation: Difference between revisions

From cernipedia
fix typo per tper
 
m 1 revision imported from wikipedia:Module:Parameter_validation
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local util = {
local util = {
empty = function( s )  
empty = function( s )
return s == nil or type( s ) == 'string' and mw.text.trim( s ) == ''  
return s == nil or type( s ) == 'string' and mw.text.trim( s ) == ''
end
end,
,
 
extract_options = function ( frame, optionsPrefix )
extract_options = function ( frame, optionsPrefix )
optionsPrefix = optionsPrefix or 'options'  
optionsPrefix = optionsPrefix or 'options'


local options, n, more = {}
local options, n = {}
if frame.args['module_options'] then
if frame.args.module_options then
local module_options = mw.loadData( frame.args['module_options'] )  
local module_options = mw.loadData( frame.args.module_options )
if type( module_options ) ~= 'table' then return {} end
if type( module_options ) ~= 'table' then return {} end
local title = mw.title.getCurrentTitle()
local title = mw.title.getCurrentTitle()
local local_ptions = module_options[ title.namespace ] or module_options[ title.nsText ] or {}  
local local_ptions = module_options[ title.namespace ] or module_options[ title.nsText ] or {}
for k, v in pairs( local_ptions ) do options[k] = v end
for k, v in pairs( local_ptions ) do options[k] = v end
end
end
 
repeat
repeat
ok, more = pcall( mw.text.jsonDecode, frame.args[optionsPrefix .. ( n or '' )] )
local ok, more = pcall( mw.text.jsonDecode, frame.args[optionsPrefix .. ( n or '' )] )
if ok and type( more ) == 'table' then
if ok and type( more ) == 'table' then
for k, v in pairs( more ) do options[k] = v end
for k, v in pairs( more ) do options[k] = v end
Line 25: Line 25:


return options
return options
end
end,
,
 
build_namelist = function ( template_name, sp )
build_namelist = function ( template_name, sp )
local res = { template_name }
local res = { template_name }
Line 34: Line 34:
end
end
return res
return res
end
end,
,
 
table_empty = function( t ) -- normally, test if next(t) is nil, but for some perverse reason, non-empty tables returned by loadData return nil...
table_empty = function( t ) -- normally, test if next(t) is nil, but for some perverse reason, non-empty tables returned by loadData return nil...
if type( t ) ~= 'table' then return true end
if type( t ) ~= 'table' then return true end
for a, b in pairs( t ) do return false end
if #t > 0 then return false end
return true
return true
end
end,
,
}
}


local function _readTemplateData( templateName )  
local function _readTemplateData( templateName )
local title = mw.title.makeTitle( 0, templateName )
local title = mw.title.makeTitle( 0, templateName )
local templateContent = title and title.exists and title:getContent() -- template's raw content
local templateContent = title and title.exists and title:getContent() -- template's raw content
local capture = templateContent and mw.ustring.match( templateContent, '<templatedata%s*>(.*)</templatedata%s*>' ) -- templatedata as text
local capture = templateContent and mw.ustring.match( templateContent, '<templatedata%s*>(.*)</templatedata%s*>' ) -- templatedata as text
-- capture = capture and mw.ustring.gsub( capture, '"(%d+)"', tonumber ) -- convert "1": {} to 1: {}. frame.args uses numerical indexes for order-based params.
-- capture = capture and mw.ustring.gsub( capture, '"(%d+)"', tonumber ) -- convert "1": {} to 1: {}. frame.args uses numerical indexes for order-based params.
local trailingComma = capture and mw.ustring.find( capture, ',%s*[%]%}]' ) -- look for ,] or ,} : jsonDecode allows it, but it's verbotten in json
local trailingComma = capture and mw.ustring.find( capture, ',%s*[%]%}]' ) -- look for ,] or ,} : jsonDecode allows it, but it's verbotten in json
Line 55: Line 54:


local function readTemplateData( templateName )
local function readTemplateData( templateName )
if type( templateName ) == 'string' then
for _, name in ipairs( templateName ) do
templateName = { templateName, templateName .. '/' .. docSubPage }
local td, result = _readTemplateData( name )
end
if td then return result end
if type( templateName ) == "table" then
for _, name in ipairs( templateName ) do
local td, result = _readTemplateData( name )  
if td then return result end
end
end
end
return nil
return nil
end
end


-- this is the function to be called by other modules. it expects the frame, and then an optional list of subpages, e.g. { "Documentation" }.
-- this is the function to be called by other modules. it expects the frame, and then an optional list of subpages, e.g. { "Documentation" }.
-- if second parameter is nil, only template page will be searched for templatedata.
-- if second parameter is nil, only template page will be searched for templatedata.
function calculateViolations( frame, subpages )
local function calculateViolations( frame, subpages )
-- used for parameter type validy test. keyed by TD 'type' string. values are function(val) returning bool.
-- used for parameter type validy test. keyed by TD 'type' string. values are function(val) returning bool.
local type_validators = {  
local type_validators = {
['number'] = function( s ) return mw.language.getContentLanguage():parseFormattedNumber( s ) end
['number'] = function( s ) return mw.language.getContentLanguage():parseFormattedNumber( s ) end
}
}
function compatible( typ, val )
local function compatible( typ, val )
local func = type_validators[typ]
local func = type_validators[typ]
return type( func ) ~= 'function' or util.empty( val ) or func( val )
return type( func ) ~= 'function' or util.empty( val ) or func( val )
end
end
 
local t_frame = frame:getParent()
local t_frame = frame:getParent()
local t_args, template_name = t_frame.args, t_frame:getTitle()
local t_args, template_name = t_frame.args, t_frame:getTitle()
template_name = mw.ustring.gsub( template_name, '/sandbox', '', 1 )
template_name = mw.ustring.gsub( template_name, '/sandbox', '', 1 )
local td_source = util.build_namelist( template_name, subpages )
local td_source = util.build_namelist( template_name, subpages )
if frame.args['td_source'] then
if frame.args.td_source then
table.insert(td_source, frame.args['td_source'])
table.insert(td_source, frame.args.td_source)
end
end


local templatedata = readTemplateData( td_source )
local templatedata = readTemplateData( td_source )
local td_params = templatedata and templatedata.params
local td_params = templatedata and templatedata.params
local all_aliases, all_series = {}, {}
local all_aliases = {}


if not td_params then return { ['no-templatedata'] = { [''] = '' } } end
if not td_params then return { ['no-templatedata'] = { [''] = '' } } end
Line 98: Line 91:


-- allow for aliases
-- allow for aliases
for x, p in pairs( td_params ) do for y, alias in ipairs( p.aliases or {} ) do
for x, p in pairs( td_params ) do
p['primary'] = x
for y, alias in ipairs( p.aliases or {} ) do
td_params[x] = p
p.primary = x
all_aliases[alias] = p
td_params[x] = p
if tonumber(alias) then all_aliases[tonumber(alias)] = p end
all_aliases[alias] = p
end end
if tonumber(alias) then all_aliases[tonumber(alias)] = p end
end
end


-- handle undeclared and deprecated
-- handle undeclared and deprecated
local already_seen = {}
local already_seen = {}
local series = frame.args['series']
local series = frame.args.series
for p_name, value in pairs( t_args ) do
for p_name, value in pairs( t_args ) do
local tp_param, noval, numeric, table_name = td_params[p_name] or all_aliases[p_name], util.empty( value ), tonumber( p_name )
local tp_param, noval, numeric = td_params[p_name] or all_aliases[p_name], util.empty( value ), tonumber( p_name )
local table_name
local hasval = not noval
local hasval = not noval


if not tp_param and series then -- 2nd chance. check to see if series
if not tp_param and series then -- 2nd chance. check to see if series
for s_name, p in pairs(td_params) do  
for s_name, p in pairs(td_params) do
if mw.ustring.match( p_name, '^' .. s_name .. '%d+' .. '$') then  
if mw.ustring.match( p_name, '^' .. s_name .. '%d+' .. '$') then
-- mw.log('found p_name '.. p_name .. ' s_name:' .. s_name, ' p is:', p) debugging series support
-- mw.log('found p_name ' .. p_name .. ' s_name:' .. s_name, ' p is:', p) debugging series support
tp_param = p  
tp_param = p
end -- don't bother breaking. td always correct.
end -- don't bother breaking. td always correct.
end
end
end
end


if not tp_param then -- not in TD: this is called undeclared
if not tp_param then -- not in TD: this is called undeclared
-- calculate the relevant table for this undeclared parameter, based on parameter and value types
-- calculate the relevant table for this undeclared parameter, based on parameter and value types
table_name =  
table_name =
noval and numeric and 'empty-undeclared-numeric' or
noval and numeric and 'empty-undeclared-numeric' or
noval and not numeric and 'empty-undeclared' or
noval and not numeric and 'empty-undeclared' or
Line 129: Line 125:
'undeclared' -- tzvototi nishar.
'undeclared' -- tzvototi nishar.
else -- in td: test for deprecation and mistype. if deprecated, no further tests
else -- in td: test for deprecation and mistype. if deprecated, no further tests
table_name = tp_param.deprecated and hasval and 'deprecated'  
table_name = tp_param.deprecated and hasval and 'deprecated'
or tp_param.deprecated and noval and 'empty-deprecated'  
or tp_param.deprecated and noval and 'empty-deprecated'
or not compatible( tp_param.type, value ) and 'incompatible'
or not compatible( tp_param.type, value ) and 'incompatible'
or not series and already_seen[tp_param] and hasval and 'duplicate'
or not series and already_seen[tp_param] and hasval and 'duplicate'
Line 138: Line 134:
end
end
end
end
 
-- report it.
-- report it.
if table_name then
if table_name then
res[table_name] = res[table_name] or {}
res[table_name] = res[table_name] or {}
if table_name == 'duplicate' then
if table_name == 'duplicate' then
local primary_param = tp_param['primary']
local primary_param = tp_param.primary
local primaryData = res[table_name][primary_param]
local primaryData = res[table_name][primary_param]
if not primaryData then
if not primaryData then
Line 157: Line 153:
end
end


-- check for empty/missing parameters declared "required"  
-- check for empty/missing parameters declared "required"
for p_name, param in pairs( td_params ) do  
for p_name, param in pairs( td_params ) do
if param.required and util.empty( t_args[p_name] ) then
if param.required and util.empty( t_args[p_name] ) then
local is_alias
local is_alias
for _, alias in ipairs( param.aliases or {} ) do is_alias = is_alias or not util.empty( t_args[alias] ) end
for _, alias in ipairs( param.aliases or {} ) do is_alias = is_alias or not util.empty( t_args[alias] ) end
if not is_alias then
if not is_alias then
res['empty-required'] = res['empty-required'] or {}  
res['empty-required'] = res['empty-required'] or {}
res['empty-required'][p_name] = ''  
res['empty-required'][p_name] = ''
end
end
end
end
end
end
 
mw.logObject(res)
mw.logObject(res)
 
return res
return res
end
end


-- wraps report in hidden frame
-- wraps report in hidden frame
function wrapReport(report, template_name, options)
local function wrapReport(report, template_name, options)
mw.logObject(report)
mw.logObject(report)
if util.empty( report ) then return '' end
if util.empty( report ) then return '' end
local naked = mw.title.new( template_name )['text']
local naked = mw.title.new( template_name ).text
naked = mw.ustring.gsub(naked, 'Infobox', 'infobox', 1)
naked = mw.ustring.gsub(naked, 'Infobox', 'infobox', 1)
 
report = ( options['wrapper-prefix'] or "<div class = 'paramvalidator-wrapper'><span class='paramvalidator-error'>" )
report = ( options['wrapper-prefix'] or '<div class="paramvalidator-wrapper"><span class="paramvalidator-error">' )
.. report
.. report
.. ( options['wrapper-suffix'] or "</span></div>" )
.. ( options['wrapper-suffix'] or '</span></div>' )
 
report = mw.ustring.gsub( report, 'tname_naked', naked )
report = mw.ustring.gsub( report, 'tname_naked', naked )
report = mw.ustring.gsub( report, 'templatename', template_name )
report = mw.ustring.gsub( report, 'templatename', template_name )
Line 192: Line 188:


-- this is the "user" version, called with {{#invoke:}} returns a string, as defined by the options parameter
-- this is the "user" version, called with {{#invoke:}} returns a string, as defined by the options parameter
function validateParams( frame )
local function validateParams( frame )
local options, report, template_name = util.extract_options( frame ), '', frame:getParent():getTitle()
local options, report, template_name = util.extract_options( frame ), '', frame:getParent():getTitle()


local ignore = function( p_name )
local ignore = function( p_name )
for _, pattern in ipairs( options['ignore'] or {} ) do
for _, pattern in ipairs( options.ignore or {} ) do
if mw.ustring.match( p_name, '^' .. pattern .. '$' ) then return true end
if mw.ustring.match( p_name, '^' .. pattern .. '$' ) then return true end
end
end
Line 203: Line 199:


local replace_macros = function( error_type, s, param_names )
local replace_macros = function( error_type, s, param_names )
function concat_and_escape( t , sep )
local function concat_and_escape( t , sep )
sep = sep or ', '
sep = sep or ', '
local s = table.concat( t, sep )
return ( mw.ustring.gsub( table.concat( t, sep ), '%%', '%%%%' ) )
return ( mw.ustring.gsub( s, '%%', '%%%%' ) )
end
end
 
if s and ( type( param_names ) == 'table' ) then
if s and ( type( param_names ) == 'table' ) then
local k_ar, kv_ar = {}, {}
local k_ar, kv_ar = {}, {}
Line 216: Line 211:
v = table.concat(v, ', ')
v = table.concat(v, ', ')
end
end
 
if error_type == 'duplicate' then
if error_type == 'duplicate' then
table.insert( kv_ar, v)
table.insert( kv_ar, v)
Line 223: Line 218:
end
end
end
end
 
s = mw.ustring.gsub( s, 'paramname', concat_and_escape( k_ar ) )
s = mw.ustring.gsub( s, 'paramname', concat_and_escape( k_ar ) )
s = mw.ustring.gsub( s, 'paramandvalue', concat_and_escape( kv_ar, ' AND ' ) )
s = mw.ustring.gsub( s, 'paramandvalue', concat_and_escape( kv_ar, ' AND ' ) )


if mw.getCurrentFrame():preprocess( "{{REVISIONID}}" ) ~= "" then
if mw.getCurrentFrame():preprocess( '{{REVISIONID}}' ) ~= '' then
s = mw.ustring.gsub( s, "<div.*<%/div>", "", 1 )
s = mw.ustring.gsub( s, '<div.*<%/div>', '', 1 )
end
end
end
end
Line 237: Line 232:
local res = replace_macros( key, options[key], param_names )
local res = replace_macros( key, options[key], param_names )
res = frame:preprocess(res or '')
res = frame:preprocess(res or '')
report = report .. ( res or '' )
report = report .. ( res or '' )
return res
return res
end
end
Line 247: Line 242:
local violations = calculateViolations( frame, options['doc-subpage'] )
local violations = calculateViolations( frame, options['doc-subpage'] )
-- special request of bora: use skip_empty_numeric
-- special request of bora: use skip_empty_numeric
if violations['empty-undeclared-numeric'] then  
if violations['empty-undeclared-numeric'] then
for i = 1, tonumber( options['skip-empty-numeric'] ) or 0 do  
for i = 1, tonumber( options['skip-empty-numeric'] ) or 0 do
violations['empty-undeclared-numeric'][i] = nil  
violations['empty-undeclared-numeric'][i] = nil
end
end
end
end
 
-- handle ignore list, and prune empty violations - in that order!
-- handle ignore list, and prune empty violations - in that order!
local offenders = 0
local offenders = 0
for name, tab in pairs( violations ) do  
for name, tab in pairs( violations ) do
-- remove ignored parameters from all violations
-- remove ignored parameters from all violations
for pname in pairs( tab ) do if ignore( pname ) then tab[pname] = nil end end
for pname in pairs( tab ) do if ignore( pname ) then tab[pname] = nil end end
Line 262: Line 257:
-- WORK IS DONE. report the errors.
-- WORK IS DONE. report the errors.
-- if report then count it.
-- if report then count it.
if violations[name] and report_params( name, tab ) then offenders = offenders + 1 end  
if violations[name] and report_params( name, tab ) then offenders = offenders + 1 end
end
end



Latest revision as of 08:04, 10 November 2026

Documentation for this module may be created at Module:Parameter validation/doc

local util = {
	empty = function( s )
		return s == nil or type( s ) == 'string' and mw.text.trim( s ) == ''
	end,

	extract_options = function ( frame, optionsPrefix )
		optionsPrefix = optionsPrefix or 'options'

		local options, n = {}
		if frame.args.module_options then
			local module_options = mw.loadData( frame.args.module_options )
			if type( module_options ) ~= 'table' then return {} end
			local title = mw.title.getCurrentTitle()
			local local_ptions = module_options[ title.namespace ] or module_options[ title.nsText ] or {}
			for k, v in pairs( local_ptions ) do options[k] = v end
		end

		repeat
			local ok, more = pcall( mw.text.jsonDecode, frame.args[optionsPrefix .. ( n or '' )] )
			if ok and type( more ) == 'table' then
				for k, v in pairs( more ) do options[k] = v end
			end
			n = ( n or 0 ) + 1
		until not ok

		return options
	end,

	build_namelist = function ( template_name, sp )
		local res = { template_name }
		if sp then
			if type( sp ) == 'string' then sp = { sp } end
			for _, p in ipairs( sp ) do table.insert( res, template_name .. '/' .. p ) end
		end
		return res
	end,

	table_empty = function( t ) -- normally, test if next(t) is nil, but for some perverse reason, non-empty tables returned by loadData return nil...
		if type( t ) ~= 'table' then return true end
		if #t > 0 then return false end
		return true
	end,
}

local function _readTemplateData( templateName )
	local title = mw.title.makeTitle( 0, templateName )
	local templateContent = title and title.exists and title:getContent() -- template's raw content
	local capture = templateContent and mw.ustring.match( templateContent, '<templatedata%s*>(.*)</templatedata%s*>' ) -- templatedata as text
--	capture = capture and mw.ustring.gsub( capture, '"(%d+)"', tonumber ) -- convert "1": {} to 1: {}. frame.args uses numerical indexes for order-based params.
	local trailingComma = capture and mw.ustring.find( capture, ',%s*[%]%}]' ) -- look for ,] or ,} : jsonDecode allows it, but it's verbotten in json
	if capture and not trailingComma then return pcall( mw.text.jsonDecode, capture ) end
	return false
end

local function readTemplateData( templateName )
	for _, name in ipairs( templateName ) do
		local td, result = _readTemplateData( name )
		if td then return result end
	end
	return nil
end

-- this is the function to be called by other modules. it expects the frame, and then an optional list of subpages, e.g. { "Documentation" }.
-- if second parameter is nil, only template page will be searched for templatedata.
local function calculateViolations( frame, subpages )
-- used for parameter type validy test. keyed by TD 'type' string. values are function(val) returning bool.
	local type_validators = {
		['number'] = function( s ) return mw.language.getContentLanguage():parseFormattedNumber( s ) end
	}
	local function compatible( typ, val )
		local func = type_validators[typ]
		return type( func ) ~= 'function' or util.empty( val ) or func( val )
	end

	local t_frame = frame:getParent()
	local t_args, template_name = t_frame.args, t_frame:getTitle()
	template_name = mw.ustring.gsub( template_name, '/sandbox', '', 1 )
	local td_source = util.build_namelist( template_name, subpages )
	if frame.args.td_source then
		table.insert(td_source, frame.args.td_source)
	end

	local templatedata = readTemplateData( td_source )
	local td_params = templatedata and templatedata.params
	local all_aliases = {}

	if not td_params then return { ['no-templatedata'] = { [''] = '' } } end
	-- from this point on, we know templatedata is valid.

	local res = {} -- before returning to caller, we'll prune empty tables

	-- allow for aliases
	for x, p in pairs( td_params ) do
		for y, alias in ipairs( p.aliases or {} ) do
			p.primary = x
			td_params[x] = p
			all_aliases[alias] = p
			if tonumber(alias) then all_aliases[tonumber(alias)] = p end
		end
	end

	-- handle undeclared and deprecated
	local already_seen = {}
	local series = frame.args.series
	for p_name, value in pairs( t_args ) do
		local tp_param, noval, numeric = td_params[p_name] or all_aliases[p_name], util.empty( value ), tonumber( p_name )
		local table_name
		local hasval = not noval

		if not tp_param and series then -- 2nd chance. check to see if series
			for s_name, p in pairs(td_params) do
				if mw.ustring.match( p_name, '^' .. s_name .. '%d+' .. '$') then
					-- mw.log('found p_name ' .. p_name .. ' s_name:' .. s_name, ' p is:', p) debugging series support
					tp_param = p
				end -- don't bother breaking. td always correct.
			end
		end

		if not tp_param then -- not in TD: this is called undeclared
			-- calculate the relevant table for this undeclared parameter, based on parameter and value types
			table_name =
				noval and numeric and 'empty-undeclared-numeric' or
				noval and not numeric and 'empty-undeclared' or
				hasval and numeric and 'undeclared-numeric' or
				'undeclared' -- tzvototi nishar.
		else -- in td: test for deprecation and mistype. if deprecated, no further tests
			table_name = tp_param.deprecated and hasval and 'deprecated'
				or tp_param.deprecated and noval and 'empty-deprecated'
				or not compatible( tp_param.type, value ) and 'incompatible'
				or not series and already_seen[tp_param] and hasval and 'duplicate'

			if hasval and table_name ~= 'duplicate' then
				already_seen[tp_param] = p_name
			end
		end

		-- report it.
		if table_name then
			res[table_name] = res[table_name] or {}
			if table_name == 'duplicate' then
				local primary_param = tp_param.primary
				local primaryData = res[table_name][primary_param]
				if not primaryData then
					primaryData = {}
					table.insert(primaryData, already_seen[tp_param])
				end
				table.insert(primaryData, p_name)
				res[table_name][primary_param] = primaryData
			else
				res[table_name][p_name] = value
			end
		end
	end

	-- check for empty/missing parameters declared "required"
	for p_name, param in pairs( td_params ) do
		if param.required and util.empty( t_args[p_name] ) then
			local is_alias
			for _, alias in ipairs( param.aliases or {} ) do is_alias = is_alias or not util.empty( t_args[alias] ) end
			if not is_alias then
				res['empty-required'] = res['empty-required'] or {}
				res['empty-required'][p_name] = ''
			end
		end
	end

	mw.logObject(res)

	return res
end

-- wraps report in hidden frame
local function wrapReport(report, template_name, options)
	mw.logObject(report)
	if util.empty( report ) then return '' end
	local naked = mw.title.new( template_name ).text
	naked = mw.ustring.gsub(naked, 'Infobox', 'infobox', 1)

	report = ( options['wrapper-prefix'] or '<div class="paramvalidator-wrapper"><span class="paramvalidator-error">' )
			.. report
			.. ( options['wrapper-suffix'] or '</span></div>' )

	report = mw.ustring.gsub( report, 'tname_naked', naked )
	report = mw.ustring.gsub( report, 'templatename', template_name )

	return report
end

-- this is the "user" version, called with {{#invoke:}} returns a string, as defined by the options parameter
local function validateParams( frame )
	local options, report, template_name = util.extract_options( frame ), '', frame:getParent():getTitle()

	local ignore = function( p_name )
		for _, pattern in ipairs( options.ignore or {} ) do
			if mw.ustring.match( p_name, '^' .. pattern .. '$' ) then return true end
		end
		return false
	end

	local replace_macros = function( error_type, s, param_names )
		local function concat_and_escape( t , sep )
			sep = sep or ', '
			return ( mw.ustring.gsub( table.concat( t, sep ), '%%', '%%%%' ) )
		end

		if s and ( type( param_names ) == 'table' ) then
			local k_ar, kv_ar = {}, {}
			for k, v in pairs( param_names ) do
				table.insert( k_ar, k )
				if type(v) == 'table' then
					v = table.concat(v, ', ')
				end

				if error_type == 'duplicate' then
					table.insert( kv_ar, v)
				else
					table.insert( kv_ar, k .. ': ' .. v)
				end
			end

			s = mw.ustring.gsub( s, 'paramname', concat_and_escape( k_ar ) )
			s = mw.ustring.gsub( s, 'paramandvalue', concat_and_escape( kv_ar, ' AND ' ) )

			if mw.getCurrentFrame():preprocess( '{{REVISIONID}}' ) ~= '' then
				s = mw.ustring.gsub( s, '<div.*<%/div>', '', 1 )
			end
		end
		return s
	end

	local report_params = function( key, param_names )
		local res = replace_macros( key, options[key], param_names )
		res = frame:preprocess(res or '')
		report = report .. ( res or '' )
		return res
	end

	-- no option no work.
	if util.table_empty( options ) then return '' end

	-- get the errors.
	local violations = calculateViolations( frame, options['doc-subpage'] )
	-- special request of bora: use skip_empty_numeric
	if violations['empty-undeclared-numeric'] then
		for i = 1, tonumber( options['skip-empty-numeric'] ) or 0 do
			violations['empty-undeclared-numeric'][i] = nil
		end
	end

	-- handle ignore list, and prune empty violations - in that order!
	local offenders = 0
	for name, tab in pairs( violations ) do
		-- remove ignored parameters from all violations
		for pname in pairs( tab ) do if ignore( pname ) then tab[pname] = nil end end
		-- prune empty violations
		if util.table_empty( tab ) then violations[name] = nil end
	-- WORK IS DONE. report the errors.
	-- if report then count it.
		if violations[name] and report_params( name, tab ) then offenders = offenders + 1 end
	end

	if offenders > 1 then report_params( 'multiple' ) end
	if offenders ~= 0 then report_params( 'any' ) end -- could have tested for empty( report ), but since we count them anyway...
	return wrapReport(report, template_name, options)
end

return {
	['validateparams'] = validateParams,
	['calculateViolations'] = calculateViolations,
	['wrapReport'] = wrapReport
}