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

הוסרו 521 בתים ,  01:41, 22 בדצמבר 2021
ביטול גרסה 19053 של מוטל'ה (שיחה)
תגית: שוחזרה
(ביטול גרסה 19053 של מוטל'ה (שיחה))
תגית: ביטול
 
שורה 113: שורה 113:
end
end
,  
,  
extract_options = function( frame, optionsPrefix )
extract_options = function ( frame, optionsPrefix )
optionsPrefix = optionsPrefix or 'options'  
optionsPrefix = optionsPrefix or 'options'  
שורה 180: שורה 180:
-- 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 tempalte page will be searched for templatedata.
-- if second parameter is nil, only tempalte page will be searched for templatedata.
local function calculateViolations( frame, subpages )
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
local function list_empty_or_contains(ar, searched)
if not ar or #ar == 0 then return true end
for _, val in ipairs(ar) do if val == searched then return true end end
return false
end
end
שורה 203: שורה 196:
local td_params = templatedata and templatedata.params
local td_params = templatedata and templatedata.params
local all_aliases, all_series = {}, {}
local all_aliases, all_series = {}, {}
if not td_params then return { ['no-templatedata'] = { [''] = '' } } end
if not td_params then return { ['no-templatedata'] = { [''] = '' } } end
שורה 244: שורה 236:
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'
or hasval and not list_empty_or_contains(tp_param.suggestedvalues , value) and 'unsuggested-value'
already_seen[tp_param] = hasval
already_seen[tp_param] = hasval
שורה 255: שורה 245:
end
end
end
end
 
-- test for empty/missing paraeters declared "required"  
-- test for empty/missing paraeters declared "required"  
for p_name, param in pairs( td_params ) do  
for p_name, param in pairs( td_params ) do  
שורה 272: שורה 262:


-- wraps report in hidden frame
-- wraps report in hidden frame
local function wrapReport(report, template_name, options)
function wrapReport(report, template_name, options)
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']  
שורה 287: שורה 277:


-- 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
local function validateParams( frame )
function validateParams( frame )
-- for purple pages:
if frame:getParent().args['skip parameters validation'] then return '[[ קטגוריה:דפים עם שגיאות פרמטריות שקיבלו חנינה]]' end
local options, report, template_name = util.extract_options( frame ), '', frame:getParent():getTitle()
local options, report, template_name = util.extract_options( frame ), '', frame:getParent():getTitle()


שורה 301: שורה 288:


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