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 = "2019- | serial = "2019-02-20" }; | ||
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 92: | Zeile 62: | ||
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 154: | Zeile 108: | ||
return r; | return r; | ||
end -- TemplUtl.faculty() | end -- TemplUtl.faculty() | ||
TemplUtl.failsafe = function ( assert ) | |||
local r | |||
if not assert or assert <= TemplUtl.serial then | |||
r = TemplUtl.serial | |||
else | |||
r = false | |||
end | |||
return r | |||
end -- TemplUtl.failsafe() | |||
Zeile 202: | Zeile 168: | ||
TemplUtl.fake = function ( access ) | TemplUtl.fake = function ( access, frame ) | ||
-- Simulation of template transclusion | -- Simulation of template transclusion | ||
-- Precondition: | -- Precondition: | ||
-- access -- string; page name (template) | -- access -- string, or nil; page name (template) | ||
-- frame -- object, or nil | |||
local s; | |||
if type( access ) == "string" then | if type( access ) == "string" then | ||
s = mw.text.trim( access ); | |||
if s | if s == "" then | ||
local | s = false; | ||
end | |||
end | |||
if not s then | |||
local cnf, lucky; | |||
s = string.format( "Module:%s/self", TemplUtl.suite ); | |||
lucky, cnf = pcall( mw.loadData, s ); | |||
if type( cnf ) == "table" and | |||
cnf.loop == true then | |||
s = mw.title.getCurrentTitle().text; | |||
else | |||
s = false; | |||
end | end | ||
end | |||
if s then | |||
local f = function () | |||
framing( frame ):expandTemplate{ title = s }; | |||
end | |||
pcall( f ); | |||
end | end | ||
end -- TemplUtl.fake() | end -- TemplUtl.fake() | ||
Zeile 228: | Zeile 209: | ||
-- answer -- true, or nil, for list creation | -- answer -- true, or nil, for list creation | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns string, if answer requested | ||
local e = framing( frame ); | local e = framing( frame ); | ||
local f = function ( a ) | local f = function ( a ) | ||
Zeile 260: | Zeile 241: | ||
-- 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 271: | ||
-- 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 408: | ||
-- 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 475: | ||
-- 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 506: | ||
-- no colon (:) | -- no colon (:) | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns ustring position of "{{" in area, or false | ||
-- Requires: | -- Requires: | ||
-- fiatTitleRegExp() | -- fiatTitleRegExp() | ||
Zeile 591: | Zeile 572: | ||
-- 3 4 5 6 | -- 3 4 5 6 | ||
-- more like 2 | -- more like 2 | ||
Zeile 608: | Zeile 578: | ||
-- 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 644: | ||
return r; | return r; | ||
end -- TemplUtl.flat() | end -- TemplUtl.flat() | ||
Zeile 767: | Zeile 682: | ||
return r or ""; | return r or ""; | ||
end -- p.fakes | end -- p.fakes | ||
function p.isRedirect() | function p.isRedirect() | ||
return mw.title.getCurrentTitle().isRedirect and "1" or ""; | return mw.title.getCurrentTitle().isRedirect and "1" or ""; | ||
end -- p.isRedirect | end -- p.isRedirect | ||
p.failsafe = function ( frame ) | p.failsafe = function ( frame ) | ||
Zeile 817: | Zeile 702: | ||
end | end | ||
end | end | ||
return | return TemplUtl.failsafe( since ) or "" | ||
end -- p.failsafe | end -- p.failsafe() | ||
p.TemplUtl = function () | p.TemplUtl = function () |