Modul:Vorlage:SeitenKoordinaten
Zur Navigation springen
Zur Suche springen
Vorlagenprogrammierung | Diskussionen | Lua | Unterseiten | ||
Modul | Deutsch
|
Modul: | Dokumentation |
Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus
-- Modul:Vorlage:SeitenKoordinaten
-- Temporär zur Migration im ANR für Vorlage:SeitenKoordinaten (2023)
-- 2024-02-18
local THIS = { }
THIS.sCat = "Wikipedia:Vorlagenfehler/SeitenKoordinaten"
THIS.schrei = "vermutlich an einer ungeeigneten Stelle eingebunden"
THIS.show = "Hinweis Seiten-Koordinaten"
THIS.support = "seitenkoordinaten-platzierung"
THIS.pages = { }
THIS.vorlagen = { All = { say = "All Coordinates",
seek = "all[ _]+coordinates",
xcl = { "|%s*pos%s*=%s*right",
"|%s*pos%s*=%s*inline" }
},
Linked = { say = "Linked Coordinates",
seek = "linked[ _]+coordinates",
xcl = { "|%s*pos%s*=%s*right",
"|%s*pos%s*=%s*inline" }
},
Coordinate = { say = "Coordinate",
seek = "[ck]oordinate",
xcl = { } }
}
THIS.davor = { "*",
"<references",
"</references>",
"</gallery>",
"<small",
"{{commonscat",
"{{commons",
"{{wikisource",
"{{wikivoyage",
"{{wiktionary",
"{{wikiquote",
"{{wikibooks",
"{{wikiatlas",
"{{wikinews",
"{{wikispecies",
"{{schwesterprojekte",
"{{portal",
"|}" }
THIS.danach = { geschweift = { "naviblock",
"navigationsleiste",
"folgeleiste",
"folgenleiste",
"personenleiste",
"artikelfolge",
"gesundheitshinweis",
"rechtshinweis",
"bildrechtshinweis",
"hinweis ",
"begriffsklärung",
"lesenswert",
"exzellent",
"informativ",
"kandidat",
"review",
"gesprochene version",
"gesprochener artikel",
"normdaten",
"sortierung",
"defaultsort",
"personendaten" },
eckig = { "%l%l%l?", "kategorie" } }
local fehler = function ( about, after, alert )
local r = true
local s = THIS.title.prefixedText
for j = 1, #THIS.pages do
if THIS.pages[ j ] == s then
r = false
break -- for j
end
end -- j
if r then
local e = mw.html.create( "code" )
local v = THIS.vorlagen[ about ]
local say = v.say
s = "[[Kategorie:%s/%s]]%s"
r = about
if after then
r = string.format( "%s/%s", r, after )
end
if alert then
say = string.format( "[[Vorlage:%s|%s]]", say, say )
end
say = string.format( "{{%s}}", say )
e:wikitext( say )
:css( "white-space", "nowrap" )
if alert then
local e2 = e
e = mw.html.create( "div" )
:css( "border", "2px solid #FF0000" )
:css( "margin", "1em" )
:css( "padding", "0.5em" )
:node( e2 )
:wikitext( " ", THIS.schrei )
else
e:css( "display", "none" )
end
e:addClass( "error" )
:addClass( THIS.support )
r = string.format( s, THIS.sCat, r, tostring( e ) )
end
return r
end -- fehler()
local first = function ( all, at, ask, always )
local i = at
local k, r
while i do
k = all:find( ask, i, always )
if k == i then
r = k
break -- while i
elseif i > 1 then
i = i - 1
else
break -- while i
end
end -- while i
return r
end -- first()
local flat = function ( all )
local r = mw.text.trim( all )
local i = r:find( "<!--", 1, true )
local j, line, s, suffix
while i do
j = r:find( "-->", i + 3, true )
if j then
suffix = r:sub( j + 3 )
if i == 1 then
s = ""
else
s = r:sub( 1, i - 1 )
if s:match( "%S%s*\n%s*$" ) or
suffix:match( "^%s*\n" ) then
line = true
end
s = mw.text.trim( s )
if line then
s = s .. "\n"
line = false
end
end
r = s .. mw.text.trim( suffix )
i = r:find( "<!--", i, true )
else
break -- while i
end
end -- while i
return mw.ustring.lower( r )
end -- flat()
local focus = function ( all, about )
local i = 1
local k, r1, r2, s
while i do
i, r2 = all:find( about.seek, i )
if i and i > 2 then
s = mw.text.trim( all:sub( 1, i - 1 ) )
s = s:gsub( "[_ ]+", "" )
if s:match( "{{$" ) or s:match( "{{vorlage:$" ) then
r2 = r2 + 1
s = all:sub( r2 )
k = s:find( "}}" )
if k then
if k > 1 then
s = s:sub( 1, k )
for j = 1, #about.xcl do
if s:match( about.xcl[ j ] ) then
k = false
break -- for j
end
end -- j
end
if k then
r1 = first( all, i - 1, "{{", true )
if r1 then
r1 = r1 - 1
r2 = r2 + k + 2
else
r1 = false
r2 = false
end
break -- while i
else
i = r2 + 1
end
else
break -- while i
end
else
i = r2 + 1
end
else
break -- while i
end
end -- while i
return r1, r2
end -- focus()
local follows = function ( after )
local s = mw.text.trim( after )
local r = true
if s == "" then
r = false
else
local start = s:sub( 1, 2 )
local l, w
if start == "{{" then
w = THIS.danach.geschweift
l = true
elseif start == "[[" then
w = THIS.danach.eckig
end
if w then
local i
s = mw.text.trim( s:sub( 3 ) )
for j = 1, #w do
i = mw.ustring.find( s, w[ j ], 1, l )
if i == 1 then
r = false
break -- for j
end
end -- j
end
end
return r
end -- follows()
local fore = function ( all, at )
local r = true
if at > 2 then
local s = mw.text.trim( all:sub( 1, at - 1 ) )
local i
s = s:match( "\n([^\n]+)$" )
if s then
for j = 1, #THIS.davor do
i = mw.ustring.find( s, THIS.davor[ j ], 1, true )
if i == 1 then
r = false
break -- for j
end
end -- j
if r and
mw.ustring.find( s, "^[a-zßäöü]" ) then
r = false
end
end
end
return r
end -- fore()
-- Export
local p = { }
p.f = function ( frame )
local sign = frame.args[ 1 ] or "Coordinate"
local v = THIS.vorlagen[ sign ]
local r
if v then
local launch = frame.args.launch
local laut = frame.args.laut
local max = frame.args.max
local i, k, s
THIS.title = mw.title.getCurrentTitle()
s = THIS.title:getContent()
if laut == "1" then
laut = true
else
laut = false
end
if launch == "1" then
launch = true
laut = true
else
launch = false
end
if max then
max = tonumber( max )
if max and max > 100 then
s = mw.ustring.sub( s, - max )
end
end
s = flat( s )
i, k = focus( s, v )
if i then
if not max and i < 200 then
r = fehler( sign, "Anfang", laut )
elseif max and i == 0 then
elseif follows( s:sub( k ) ) or
fore( s, i ) then
r = fehler( sign, false, laut )
end
end
if launch then
if sign == "Coordinate" then
s = frame.args.coordinates
else
s = false
end
if r then
if s then
r = r .. s
end
else
local params
if sign == "Coordinate" then
params = { coordinates = s }
elseif sign == "Linked" then
params = { linked = "1" }
end
r = frame:expandTemplate{ title = THIS.show,
args = params }
end
end
end
return r or ""
end -- p.f
return p