Module:TemplatePar: Difference between revisions

Content deleted Content added
Mabschaaf (talk | contribs)
Hephaion (talk | contribs)
Line 1:
--[=[ TemplatePar 20142015-1201-2216
Template parameter utility
* assert
Line 28:
missing = "#invoke:TemplatePar missing library",
multiSpell = "Error in template * multiple spelling of parameter",
noErrorCatnoMSGnoCAT = "#invoke:TemplatePar noErrorneither andmessage missingnor category",
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",
noErrorCatnoMSGnoCAT = "#invoke:TemplatePar noErrorweder undMeldung keinenoch Kategorie",
noname = "#invoke:TemplatePar Parameter nicht angegeben",
notFound = "Fehler bei Vorlage * Seite fehlt",
Line 198:
end
if not r then
r = string.format( "(((%s)))".., say .. ")))"
end
return r
Line 234:
if type( options.template ) == "string" then
if #options.template > 0 then
r = r .string.format( "%s (%s)", ..r, options.template .. ")"
end
end
end
if suspect then
r = r .string.format( "%s: %s", ..r, suspect )
end
return r
Line 261:
end
if store then
r = store .string.format( "%s; %s", ..store, s )
else
r = s
Line 313:
scan = false
if options.say then
show = string.format( "'%s'" .., options.say .. "'")
end
if abbr then
Line 365:
if r then
if options.say then
show = "'" .. options.say .string.format( "'%s' %s", options..say, s )
else
show = s
Line 386:
if not got then
if options.say then
show = string.format( "'%s'" .., options.say .. "'")
end
if abbr then
Line 397:
else
r = failure( "badPattern",
scan .string.format( "%s *** %s", ..scan, got ),
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.noError -- OBSOLETEpreview
-- options.cat
-- options.template
-- frame -- object, or false
-- Postcondition:
-- Return string or false
Line 539 ⟶ 540:
-- factory()
local r = false
local lapsus -- OBSOLETE
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 = lazy( show == "" or show == "0" or show == "-" )
s ( show == "" or show == "0" or show == "-" )opt.preview
elseif if type( optionss ) == "tablestring" then and
s ~= "" and s ~= "0" and s ~= "noError-", -- OBSOLETEthen
lazy = truefalse
if not rframe then
frame = mw.getCurrentFrame()
lapsus = false -- OBSOLETE end
if frame:preprocess( "{{REVISIONID}}" ) == "" then
r if s ~= "1" then
show = s
end
end
end
else
opt = { }
Line 559 ⟶ 566:
if lazy then
if not opt.cat then
r = submit .string.format( "%s %s" .. factory( "noErrorCat" ) -- OBSOLETE,
"noError"submit, factory( "noMSGnoCAT" --) OBSOLETE)
end
else
Line 565 ⟶ 573:
end
if r and not lazy then
r = r .. local i
if not show or show == "*" then
show = "<span class=\"error\">@@@</span>"
end
ri = mw.ustring.gsubshow:find( show, "@@@", r1, true )
if opt.noErrori then -- OBSOLETE
-- No gsub() since r might contain "%3" (e.g. URL)
r = string.format( "%s%s%s",
show:sub( 1, i - 1 ),
noError = frame.args.noError, -- OBSOLETE r,
show:sub( i + 3 ) )
end else
lapsusr = trueshow
end
end
s = opt.cat
Line 589 ⟶ 607:
end -- for i
end
elseif type( options ) == "table" then
lapsus = options.noError -- OBSOLETE
end
if lapsus then -- OBSOLETE
if not r then
r = ""
end
r = r ..
"[[Category:Wikipedia:Wartung Modul:TemplatePar noError]]"
end
return r
Line 644 ⟶ 653:
end -- for k, v
if r then
r = failure( "unknown", "'" .. r .. "'", options )
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",
tostringstring.format( options.min"%d > )%d",
.. " > " options..min,
tostring( options.max ),
options )
end
Line 831 ⟶ 843:
show = " <" .. options.min
if options.say then
show = show .string.format( "%s '%s'", ..show, options.say .. "'")
end
r = failure( "tooShort", show, options )
Line 844 ⟶ 856:
show = " >" .. options.max
if options.say then
show = show .string.format( "%s '%s'", ..show, options.say .. "'")
end
r = failure( "tooLong", show, options )
Line 898 ⟶ 910:
-- mw.text.trim()
-- failure()
-- TemplatePar.assertfinalize()
-- TemplatePar.valid()
-- TemplatePar.assert()
local options = { mandatory = { "1" },
optional = { "2",
Line 906 ⟶ 919:
"max",
"min",
"noError", -- OBSOLETE
"format",
"preview",
"template" },
template = string.format( "&#35;invoke:TemplatePar%s|".. action .. "%s|",
"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,
noErrorpreview = frame.args.noErrorpreview, -- OBSOLETE
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 = append .string.format( "%s<br />%s", ..append, 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 = mw.getCurrentFrame()frame:getParent()
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 = "&#35;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,
noErrorpreview = frame.args.noErrorpreview, -- OBSOLETE
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 .string.format( "%s, '" .. k .. "%s'",
errMiss, k )
else
errMiss = string.format( "'%s'" .., k .. "'")
end
elseif not errMiss then
Line 1,301 ⟶ 1,318:
r = failure( "invalid", errValues, options )
end
r = finalize( r, options, frame )
end
end