Bearbeiten von „Modul:Vorlage:Anker“
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 | local Anchor = { suite = "AnchorTemplate", | ||
serial = "2019-12-22", | |||
item = 79414611 | |||
} | |||
--[=[ | --[=[ | ||
Template:Anchor {{Anker}} | |||
]=] | ]=] | ||
local Failsafe | local Failsafe = Anchor | ||
local Config = { | local Config = { | ||
badPattern = "[#'\"%[%]<> | badPattern = "[%%#&'\"%[%]<>]", | ||
globalPage = { | globalPage = { "bodyContent", | ||
"catlinks", | "catlinks", | ||
"centralNotice", | "centralNotice", | ||
"content", | "content", | ||
"contentSub", | "contentSub", | ||
"editform", | "editform", | ||
"editpage-copywarn", | "editpage-copywarn", | ||
Zeile 28: | Zeile 23: | ||
"fundraising", | "fundraising", | ||
"jump-to-nav", | "jump-to-nav", | ||
"page-actions", | "page-actions", | ||
"siteNotice", | "siteNotice", | ||
"siteSub", | "siteSub", | ||
"top" }, | |||
globalPatterns = { "^mw%-", | |||
"top | "^ca%-", | ||
"^n%-", | |||
globalPatterns = { "^mw%- | "^pt?%-", | ||
"^ca%- | |||
"^n%- | |||
"^pt%- | |||
"^wp%u" }, | "^wp%u" }, | ||
errCat = false, | errCat = false, | ||
Zeile 56: | Zeile 45: | ||
de = "Parameter unbekannt:" } | de = "Parameter unbekannt:" } | ||
} | } | ||
Zeile 116: | Zeile 52: | ||
-- apply -- string, with message key | -- apply -- string, with message key | ||
-- Returns message text; at least English | -- Returns message text; at least English | ||
local entry = Config[ apply ] | local entry = Config[ apply ] | ||
local r | local r | ||
Zeile 140: | Zeile 75: | ||
-- adjust -- string or nil | -- adjust -- string or nil | ||
-- Returns boolean | -- Returns boolean | ||
local r | local r = false | ||
if | if adjust then | ||
r = mw.text.trim( adjust ) | r = mw.text.trim( adjust ) | ||
if r ~= "" and r ~= "0" then | if r ~= "" and r ~= "0" then | ||
r = true | r = true | ||
end | end | ||
end | end | ||
return r | return r | ||
Zeile 156: | Zeile 89: | ||
local function fair( assembly ) | local function fair( assembly ) | ||
-- Create HTML code for anchors | -- Create HTML code for anchors | ||
-- assembly -- sequence table, with | -- assembly -- sequence table, with identtifiers | ||
-- Returns HTML string | -- Returns HTML string | ||
local collection = mw.html.create( "" ) | local collection = mw.html.create( "" ) | ||
Zeile 190: | Zeile 123: | ||
local scope = Config.errClass | local scope = Config.errClass | ||
local story = factory( alert ) | local story = factory( alert ) | ||
local TemplUtl = | local lucky, TemplUtl = pcall( require, "Module:TemplUtl" ) | ||
local r, scope, style | local r, scope, style | ||
if type( TemplUtl ) == "table | if type( TemplUtl ) == "table" then | ||
TemplUtl = TemplUtl.TemplUtl() | TemplUtl = TemplUtl.TemplUtl() | ||
end | end | ||
if Config.self then | if Config.self then | ||
Zeile 215: | Zeile 142: | ||
story = string.format( "%s %s", story, about ) | story = string.format( "%s %s", story, about ) | ||
end | end | ||
if TemplUtl then | if type( TemplUtl ) == "table" then | ||
r = TemplUtl.failure( story, | r = TemplUtl.failure( story, | ||
not Config.errHide, | not Config.errHide, | ||
Zeile 228: | Zeile 155: | ||
if Config.errCat then | if Config.errCat then | ||
if Config.errNS then | if Config.errNS then | ||
local ns = mw.title.getCurrentTitle().namespace | |||
local st = type( Config.errNS ) | local st = type( Config.errNS ) | ||
if st == " | if st == "string" then | ||
local space = string.format( ".*%%s%d%%s.*", ns ) | |||
local spaces = string.format( " %s ", Config.errNS ) | |||
if spaces:match( space ) then | |||
Config.errNS = false | |||
end | |||
elseif st == "table" then | |||
Config.errNS | |||
end | |||
for i = 1, #Config.errNS do | for i = 1, #Config.errNS do | ||
if Config.errNS[ i ] == ns then | if Config.errNS[ i ] == ns then | ||
Zeile 255: | Zeile 178: | ||
return r | return r | ||
end -- fault() | end -- fault() | ||
Zeile 276: | Zeile 187: | ||
-- Returns appropriate string | -- Returns appropriate string | ||
local r | local r | ||
if | if argsF then | ||
Config.errCat = argsF.errCat | Config.errCat = argsF.errCat | ||
Config.errClasses = argsF.errClasses | Config.errClasses = argsF.errClasses | ||
Config.errHide = faculty( argsF.errHide ) | Config.errHide = faculty( argsF.errHide ) | ||
Config.errNS = argsF.errNS | Config.errNS = argsF.errNS | ||
end | end | ||
if type( argsT ) == "table" then | if type( argsT ) == "table" then | ||
local | local checked = { } | ||
local tocheck = { } | |||
local further = function ( add ) | |||
local spacy = add:gsub( " +", "_" ) | |||
:gsub( "_+", "_" ) | |||
table.insert( checked, spacy ) | |||
end | |||
local s, unknown | |||
for k, v in pairs( argsT ) do | for k, v in pairs( argsT ) do | ||
s = type( k ) | |||
if s == "number" then | |||
v = mw.text.trim( v ) | v = mw.text.trim( v ) | ||
if v | if v ~= "" then | ||
v | table.insert( tocheck, v ) | ||
end | end | ||
k = false | k = false | ||
elseif s == "string" then | |||
if k:match( "^x[1-9]%d*" ) then | |||
further( v ) | |||
k = false | k = false | ||
end | end | ||
end | end | ||
if k then | if k then | ||
unknown = | if not unknown then | ||
unknown = { } | |||
end | |||
table.insert( unknown, k ) | table.insert( unknown, k ) | ||
end | end | ||
end -- for k, v | end -- for k, v | ||
if unknown then | if unknown then | ||
e = mw.html.create( "code" ) | local e = mw.html.create( "code" ) | ||
:css( "white-space", "nowrap" ) | |||
:wikitext( table.concat( unknown, " " ) ) | |||
s = string.format( " in [[%s]]", | s = string.format( " in [[%s]]", | ||
Config.frame:getTitle() ) | Config.frame:getTitle() ) | ||
Zeile 327: | Zeile 232: | ||
:wikitext( s ) | :wikitext( s ) | ||
r = fault( "errUnkown", tostring( e ) ) | r = fault( "errUnkown", tostring( e ) ) | ||
else | |||
local | local bad, e | ||
local flop = function ( a, alter ) | |||
if not bad then | |||
local | bad = { } | ||
for | end | ||
if | e = mw.html.create( "code" ) | ||
:wikitext( a ) | |||
if alter then | |||
e:css( "white-space", "nowrap" ) | |||
end | |||
table.insert( bad, tostring( e ) ) | |||
end | |||
local legal, s | |||
for i = 1, #tocheck do | |||
s = tocheck[ i ] | |||
if s:match( "^%d" ) or | |||
s:match( Config.badPattern ) then | |||
legal = false | |||
else | else | ||
legal = true | |||
for k = 1, #Config.globalPatterns do | |||
if s:match( Config.globalPatterns[ k ] ) then | |||
legal = false | |||
break -- k = 1, #Config.globalPatterns | |||
end | |||
end -- k = 1, #Config.globalPatterns | |||
end | end | ||
if not legal then | if not legal then | ||
flop( mw.text.encode( s ), true ) | |||
else | |||
further( s ) | |||
end | end | ||
end -- for k, | end -- i = 1, #tocheck | ||
for i = 1, #checked do | |||
s = checked[ i ] | |||
end | for k = 1, #Config.globalPage do | ||
if s == Config.globalPage[ k ] then | |||
flop( s ) | |||
break -- k = 1, #Config.globalPage | |||
end | |||
end -- k = 1, #Config.globalPage | |||
end -- i = 1, #checked | |||
if bad then | if bad then | ||
s = string.format( "%s in [[%s]]", | s = string.format( "%s in [[%s]]", | ||
table.concat( bad, ", " ), | table.concat( bad, ", " ), | ||
Config.frame:getParent():getTitle() ) | Config.frame:getParent():getTitle() ) | ||
r = | r = fault( "errInvalid", s ) | ||
elseif #checked == 0 then | |||
r = fault( "errNoFragments" ) | |||
else | |||
r = fair( checked ) | |||
end | end | ||
end | end | ||
end | end | ||
return r or "" | return r or "" | ||
end -- main() | end -- main() | ||
Zeile 521: | Zeile 354: | ||
end -- p.f() | end -- p.f() | ||
p.failsafe = function ( frame ) | p.failsafe = function ( frame ) | ||
Zeile 561: | Zeile 374: | ||
end -- p.failsafe() | end -- p.failsafe() | ||
p. | |||
return | |||
end -- p. | p.test = function ( argsF, argsT ) | ||
Config.frame = mw.getCurrentFrame() | |||
return main( argsF, argsT ) | |||
end -- p.test() | |||
return p | return p |