Content deleted Content added
m per Adminnanfrage |
|||
Line 1:
--[=[ TemplatePar
Template parameter utility
* assert
Line 28:
missing = "#invoke:TemplatePar missing library",
multiSpell = "Error in template * multiple spelling of parameter",
noname = "#invoke:TemplatePar missing parameter name",
notFound = "Error in template * missing page",
Line 46:
minmax = "#invoke:TemplatePar min > max",
multiSpell = "Fehler bei Vorlage * Mehrere Parameter-Schreibweisen",
noname = "#invoke:TemplatePar Parameter nicht angegeben",
notFound = "Fehler bei Vorlage * Seite fehlt",
Line 198:
end
if not r then
r = string.format( "(((%s)))"
end
return r
Line 234:
if type( options.template ) == "string" then
if #options.template > 0 then
r =
end
end
end
if suspect then
r =
end
return r
Line 261:
end
if store then
r =
else
r = s
Line 313:
scan = false
if options.say then
show = string.format( "'%s'"
end
if abbr then
Line 365:
if r then
if options.say then
show =
else
show = s
Line 386:
if not got then
if options.say then
show = string.format( "'%s'"
end
if abbr then
Line 397:
else
r = failure( "badPattern",
options )
end
Line 525:
local function finalize( submit, options, frame )
-- Finalize message
-- Precondition:
-- submit -- string or false or nil; non-empty error message
-- options -- table or nil; optional details
-- options.noError -- OBSOLETE▼
-- options.format
-- options.cat
-- options.template
-- frame -- object, or false
-- Postcondition:
-- Return string or false
Line 539 ⟶ 540:
-- factory()
local r = false
if submit then
local opt, s
local lazy = false
local show = false
lapsus = false -- OBSOLETE▼
if type( options ) == "table" then
opt = options
if opt.noError then -- OBSOLETE▼
lazy = true▼
lapsus = true▼
end▼
show = opt.format
lazy =
s
frame = mw.getCurrentFrame()
if frame:preprocess( "{{REVISIONID}}" ) == "" then
show = s
end
end
▲ end
else
opt = { }
Line 559 ⟶ 566:
if lazy then
if not opt.cat then
r =
end
else
Line 565 ⟶ 573:
end
if r and not lazy then
if not show or show == "*" then
show = "<span class=\"error\">@@@</span>"
end
-- No gsub() since r might contain "%3" (e.g. URL)
r = string.format( "%s%s%s",
show:sub( 1, i - 1 ),
show:sub( i + 3 ) )
end▼
end
s = opt.cat
Line 589 ⟶ 607:
end -- for i
end
▲ elseif type( options ) == "table" then
▲ end
▲ if not r then
▲ r = ""
▲ end
▲ r = r ..
end
return r
Line 644 ⟶ 653:
end -- for k, v
if r then
r = failure( "unknown",
string.format( "'%s'", r ),
options )
else -- all names valid
local i, s
Line 758 ⟶ 769:
local function form( light, options, frame )
-- Run parameter analysis on current environment
-- Precondition:
Line 765 ⟶ 776:
-- options.mandatory
-- options.optional
-- frame -- object, or false
-- Postcondition:
-- Return string with error message as configured;
Line 796 ⟶ 808:
end
end
return finalize( r, options, frame )
end -- form()
Line 822 ⟶ 834:
if options.max < options.min then
r = failure( "minmax",
options )
end
Line 831 ⟶ 843:
show = " <" .. options.min
if options.say then
show =
end
r = failure( "tooShort", show, options )
Line 844 ⟶ 856:
show = " >" .. options.max
if options.say then
show =
end
r = failure( "tooLong", show, options )
Line 898 ⟶ 910:
-- mw.text.trim()
-- failure()
--
-- TemplatePar.valid()
-- TemplatePar.assert()
local options = { mandatory = { "1" },
optional = { "2",
Line 906 ⟶ 919:
"max",
"min",
▲ "noError", -- OBSOLETE
"format",
"preview",
"template" },
template = string.format( "#invoke:
"TemplatePar",
action )
}
local r = form( false, options, frame )
if not r then
local s
options = { cat = frame.args.cat,
low = frame.args.low,
noError = frame.args.noError, -- OBSOLETE▼
format = frame.args.format,
template = frame.args.template
}
Line 942 ⟶ 957:
end
if r then
r = finalize( r, options, frame )
else
s = frame.args[ 1 ] or ""
Line 950 ⟶ 965:
end
if action == "valid" then
r = TemplatePar.valid( s, options, frame )
elseif action == "assert" then
r = TemplatePar.assert( s, "", options )
Line 977 ⟶ 992:
if ( type( append ) == "string" ) then
if ( append ~= "" ) then
r =
end
else
Line 999 ⟶ 1,014:
-- Uses:
-- form()
return form( true, options, false )
end -- TemplatePar.check()
Line 1,060 ⟶ 1,075:
TemplatePar.valid = function ( access, options, frame )
-- Check validity of one particular template parameter
-- Precondition:
Line 1,066 ⟶ 1,081:
-- string or number
-- options -- table or nil; optional details
-- frame -- object; #invoke environment
-- Postcondition:
-- Return string with error message as configured;
Line 1,096 ⟶ 1,112:
params = TemplatePar.downcase( options )
else
params =
end
r = formatted( params, access, options )
Line 1,102 ⟶ 1,118:
r = failure( "noname", false, options )
end
return finalize( r, options, frame )
end -- TemplatePar.valid()
Line 1,116 ⟶ 1,132:
-- Uses:
-- form()
return form( false, options, false )
end -- TemplatePar.verify()
Line 1,152 ⟶ 1,168:
"cat",
"low",
▲ "noError", -- OBSOLETE
"format",
"preview",
"template" },
template = "#invoke:TemplatePar|check|"
}
local r = form( false, options, frame )
if not r then
options = { mandatory = fill( frame.args.all ),
Line 1,163 ⟶ 1,179:
cat = frame.args.cat,
low = frame.args.low,
noError = frame.args.noError, -- OBSOLETE▼
format = frame.args.format,
template = frame.args.template
}
r = form( true, options, frame )
end
return r or ""
Line 1,213 ⟶ 1,229:
local options = { cat = frame.args.cat,
low = frame.args.low,
▲ noError = frame.args.noError, -- OBSOLETE
format = frame.args.format,
preview = frame.args.preview,
template = frame.args.template
}
Line 1,250 ⟶ 1,266:
end -- for k, v
options.optional = s
r = form( true, options, frame )
end
if not r then
Line 1,283 ⟶ 1,299:
if lack then
if errMiss then
errMiss =
errMiss, k )
else
errMiss = string.format( "'%s'"
end
elseif not errMiss then
Line 1,301 ⟶ 1,318:
r = failure( "invalid", errValues, options )
end
r = finalize( r, options, frame )
end
end
|