Bearbeiten von „Modul:TemplUtl“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
local TemplUtl = { suite = "TemplUtl", | local TemplUtl = { suite = "TemplUtl", | ||
serial = " | serial = "2017-11-11" }; | ||
Zeile 39: | Zeile 9: | ||
-- accept -- string; trimmed title | -- accept -- string; trimmed title | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns string with pattern | ||
local start = mw.ustring.sub( accept, 1, 1 ); | local start = mw.ustring.sub( accept, 1, 1 ); | ||
local r; | local r; | ||
Zeile 69: | Zeile 39: | ||
end | end | ||
end | end | ||
end -- framing() | end -- framing() | ||
Zeile 85: | Zeile 54: | ||
if r == "" then | if r == "" then | ||
r = TemplUtl.faculty( another, nil ); | r = TemplUtl.faculty( another, nil ); | ||
elseif r | elseif r == "1" then | ||
r = true; | r = true; | ||
elseif r | elseif r == "0" then | ||
r = false; | r = false; | ||
else | else | ||
r = r:lower(); | r = r:lower(); | ||
if r == "y" or | if r == "y" or r == "yes" or r == "true" then | ||
r = true; | r = true; | ||
elseif r == "n" or | elseif r == "n" or r == "no" or r == "false" then | ||
r = false; | r = false; | ||
else | else | ||
if not TemplUtl. | if not TemplUtl.L10N then | ||
local lucky; | |||
s = string.format( "Module:%s/local", | |||
TemplUtl.suite ); | |||
lucky, TemplUtl.L10N = pcall( mw.loadData, s ); | |||
end | |||
if type( TemplUtl.L10N ) == "table" then | |||
local entry; | |||
if not TemplUtl.lang then | |||
-- TODO: page language | |||
TemplUtl.lang = | |||
mw.language.getContentLanguage():getCode(); | |||
TemplUtl. | |||
end | end | ||
entry = TemplUtl.L10N[ TemplUtl.lang ]; | |||
if type( entry ) == "table" then | |||
s = entry[ r ]; | |||
if type( s ) == "boolean" then | |||
r = s; | |||
end | |||
end | end | ||
else | |||
TemplUtl.L10N = true; | |||
end | end | ||
if type( r ) ~= "boolean" then | if type( r ) ~= "boolean" then | ||
if type( another ) ~= "nil" then | |||
r = TemplUtl.faculty( another ); | |||
else | |||
r = true; | r = true; | ||
end | end | ||
end | end | ||
Zeile 167: | Zeile 119: | ||
:addClass( "error" ) | :addClass( "error" ) | ||
:wikitext( alert ); | :wikitext( alert ); | ||
local live | local live; | ||
framing( frame ); | |||
live = ( TemplUtl.frame:preprocess( "{{REVISIONID}}" ) == "" ); | |||
if type( addClass ) == "string" then | if type( addClass ) == "string" then | ||
err:addClass( addClass ) | err:addClass( addClass ) | ||
Zeile 188: | Zeile 141: | ||
sign = string.format( "[[#%s|%s]]", sign, tostring( btn ) ); | sign = string.format( "[[#%s|%s]]", sign, tostring( btn ) ); | ||
top:wikitext( sign, " ", alert ); | top:wikitext( sign, " ", alert ); | ||
mw.addWarning( tostring( top | mw.addWarning( tostring( top ) ); | ||
elseif not always then | elseif not always then | ||
err:css( { ["display"] = "none" } ); | err:css( { ["display"] = "none" } ); | ||
Zeile 199: | Zeile 152: | ||
return tostring( err ); | return tostring( err ); | ||
end -- TemplUtl.failure() | end -- TemplUtl.failure() | ||
Zeile 260: | Zeile 160: | ||
-- address -- string; what to inspect, URL presumed | -- address -- string; what to inspect, URL presumed | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns true, if URL beginning | ||
local start, r = address:match( "^%s*((%a*:?)//)" ); | local start, r = address:match( "^%s*((%a*:?)//)" ); | ||
if start then | if start then | ||
Zeile 290: | Zeile 190: | ||
-- after -- true, if only to search for "}}" | -- after -- true, if only to search for "}}" | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns | ||
-- -- number; byte position in area | -- -- number; byte position in area | ||
-- -- before "|" or "}}", may be at end | -- -- before "|" or "}}", may be at end | ||
Zeile 427: | Zeile 327: | ||
-- at -- optional number; byte position in area of "{{" | -- at -- optional number; byte position in area of "{{" | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns | ||
-- -- table | -- -- table | ||
-- [0] -- template, page, parser function name | -- [0] -- template, page, parser function name | ||
Zeile 494: | Zeile 394: | ||
-- ask -- string; parameter name | -- ask -- string; parameter name | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns string with trimmed parameter value, or nil | ||
-- Does not return value if template inside | -- Does not return value if template inside | ||
local r; | local r; | ||
Zeile 525: | Zeile 425: | ||
-- no colon (:) | -- no colon (:) | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns ustring position of "{{" in area, or false | ||
-- Requires: | -- Requires: | ||
-- fiatTitleRegExp() | -- fiatTitleRegExp() | ||
Zeile 591: | Zeile 491: | ||
-- 3 4 5 6 | -- 3 4 5 6 | ||
-- more like 2 | -- more like 2 | ||
Zeile 608: | Zeile 497: | ||
-- Remove syntax elements that hide effective syntax only | -- Remove syntax elements that hide effective syntax only | ||
-- Precondition: | -- Precondition: | ||
-- area -- string; | -- area -- string; wikitext to be reduced | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns cleared wikitext | ||
local delimiters = { { "<%s*NOWIKI%s*>", "<%s*/%s*NOWIKI%s*>" }, | local delimiters = { { "<%s*NOWIKI%s*>", "<%s*/%s*NOWIKI%s*>" }, | ||
{ "<!--", "-->", true }, | { "<!--", "-->", true }, | ||
Zeile 674: | Zeile 563: | ||
return r; | return r; | ||
end -- TemplUtl.flat() | end -- TemplUtl.flat() | ||
Zeile 753: | Zeile 587: | ||
return TemplUtl.failure( scream, loud, select, frame ); | return TemplUtl.failure( scream, loud, select, frame ); | ||
end -- p.failure | end -- p.failure | ||
function p.isRedirect() | function p.isRedirect() | ||
Zeile 791: | Zeile 592: | ||
end -- p.isRedirect | end -- p.isRedirect | ||
function p. | function p.failsafe() | ||
return TemplUtl.serial; | |||
end -- p.failsafe() | |||
end -- | |||
p.failsafe | |||
p.TemplUtl = function () | p.TemplUtl = function () |