יחידה:ParamValidator: הבדלים בין גרסאות בדף

מ תקלדה
ניסוי, הצליח
שורה 106: שורה 106:


local options, n, more = {}
local options, n, more = {}
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 = frame:getTitle()
local title = mw.title.getCurrentTitle()
options = module_options[ title.namespace ] or module_options[ title.nsText ] or {}  
return module_options[ title.namespace ] or module_options[ title.nsText ] or {}  
if not next( options ) then return options end
end
end
שורה 134: שורה 132:
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...
if type( t ) ~= 'table' then return true end
for a, b in pairs( t ) do return false end
return true
end
,
}
}


שורה 269: שורה 274:
return res
return res
end
end
 
-- no option no work.
-- no option no work.
if next( options ) == nil then return '' end
if util.table_empty( options ) then return '' end
 
-- get the errors.
-- get the errors.
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  
שורה 289: שורה 293:
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
-- prune empty violations
-- prune empty violations
if next( tab ) == nil then violations[name] = nil end
if util.table_empty( tab ) then violations[name] = nil end
-- WORK IS DONE. report the errors.
-- WORK IS DONE. report the errors.
-- if report then count it.
-- if report then count it.
שורה 297: שורה 301:
if offenders > 1 then report_params( 'multiple' ) 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...
if offenders ~= 0 then report_params( 'any' ) end -- could have tested for empty( report ), but since we count them anyway...
return wrap_report()
return wrap_report()
end
end