יחידה:ParamValidator – הבדלי גרסאות
חלוקת קונטרסים (שיחה | תרומות) עדכון |
חלוקת קונטרסים (שיחה | תרומות) אין תקציר עריכה |
||
| (גרסת ביניים אחת של משתמש אחר אחד אינה מוצגת) | |||
| שורה 1: | שורה 1: | ||
require('strict') | |||
--[=[ | --[=[ | ||
This module is based on idea and original code of | This module is based on idea and original code of User:IKhitron. | ||
the source of this module is in //he.wikipedia.org/wiki/Module:ParamValidator | the source of this module is in //he.wikipedia.org/wiki/Module:ParamValidator | ||
| שורה 110: | שורה 111: | ||
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 ) == '' or s == '-') -- compatible with module:תבנית מידע | ||
end | end | ||
, | , | ||
| שורה 117: | שורה 118: | ||
local options, n | 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'] ) | ||
| שורה 127: | שורה 128: | ||
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 | ||
| שורה 148: | שורה 149: | ||
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 | for _, _ in pairs( t ) do return false end | ||
return true | return true | ||
end | end | ||