Modul:TemplatePar: Unterschied zwischen den Versionen
Migration zur Umparametrisierung abgeschlossen; keine Einbindungen mehr
wp>PerfektesChaos (Migrations-Version zur Umparametrisierung) |
wp>PerfektesChaos (Migration zur Umparametrisierung abgeschlossen; keine Einbindungen mehr) |
||
Zeile 1: | Zeile 1: | ||
--[=[ TemplatePar 2013- | --[=[ TemplatePar 2013-06-01 | ||
Template parameter utility | Template parameter utility | ||
* check | * check | ||
Zeile 80: | Zeile 80: | ||
[ "base64" ] = "^[A-Za-z0-9%+/]*$", | [ "base64" ] = "^[A-Za-z0-9%+/]*$", | ||
[ "base64+" ] = "^[A-Za-z0-9%+/]+$", | [ "base64+" ] = "^[A-Za-z0-9%+/]+$", | ||
[ "aa" ] = "[%a%a].*[%a%a]", | |||
[ "+" ] = "%S" | [ "+" ] = "%S" | ||
} | } | ||
local patternCJK = false | |||
local function containsCJK( s ) | |||
-- Is any CJK character present? | |||
-- Precondition: | |||
-- s -- string | |||
-- Postcondition: | |||
-- Return false iff no CJK present | |||
-- Uses: | |||
-- >< patternCJK | |||
-- mw.ustring.char() | |||
-- mw.ustring.match() | |||
local r = false | |||
if not patternCJK then | |||
patternCJK = mw.ustring.char( 91, | |||
13312, 45, 40959, | |||
131072, 45, 178207, | |||
93 ) | |||
end | |||
if mw.ustring.match( s, patternCJK ) then | |||
r = true | |||
end | |||
return r | |||
end -- factory() | |||
Zeile 118: | Zeile 145: | ||
local function failsafe( story, scan ) | local function failsafe( story, scan ) | ||
-- Test for match (possibly user-defined with | -- Test for match (possibly user-defined with syntax error) | ||
-- Precondition: | -- Precondition: | ||
-- story -- string; parameter value | -- story -- string; parameter value | ||
Zeile 539: | Zeile 566: | ||
-- mw.text.trim() | -- mw.text.trim() | ||
-- failsafe() | -- failsafe() | ||
-- containsCJK() | |||
local r = false | local r = false | ||
local s | local s | ||
Zeile 586: | Zeile 614: | ||
if legal then | if legal then | ||
if not got then | if not got then | ||
if s == "aa" then | |||
got = containsCJK( story ) | |||
end | |||
if not got then | |||
seek = "'" .. seek .. "'" | |||
r = failure( "invalid", seek, options ) | |||
end | |||
end | end | ||
else | else | ||
Zeile 762: | Zeile 796: | ||
-- form() | -- form() | ||
-- fill() | -- fill() | ||
local options = { optional = { | local options = { optional = { "all", | ||
"opt", | "opt", | ||
"cat", | "cat", | ||
Zeile 773: | Zeile 806: | ||
local r = form( false, options ) | local r = form( false, options ) | ||
if not r then | if not r then | ||
options = { mandatory = fill( frame.args.all | options = { mandatory = fill( frame.args.all ), | ||
optional = fill( frame.args.opt | optional = fill( frame.args.opt ), | ||
cat = frame.args.cat, | cat = frame.args.cat, | ||
low = frame.args.low, | low = frame.args.low, | ||
Zeile 819: | Zeile 852: | ||
-- mw.text.trim() | -- mw.text.trim() | ||
-- TemplatePar.valid() | -- TemplatePar.valid() | ||
local options = { mandatory = { }, | local options = { mandatory = { "1" }, | ||
optional = { | optional = { "2", | ||
"cat", | "cat", | ||
"low", | "low", | ||
Zeile 833: | Zeile 864: | ||
local r = form( false, options ) | local r = form( false, options ) | ||
if not r then | if not r then | ||
local s = mw.text.trim( | local s = mw.text.trim( frame.args[ 2 ] ) | ||
options = { cat = frame.args.cat, | options = { cat = frame.args.cat, | ||
low = frame.args.low, | low = frame.args.low, | ||
Zeile 873: | Zeile 904: | ||
r = finalize( r, options ) | r = finalize( r, options ) | ||
else | else | ||
s = | s = frame.args[ 1 ] or "" | ||
r = TemplatePar.valid( s, options ) | r = TemplatePar.valid( s, options ) | ||
end | end |