Broken/Personenleiste
Zur Navigation springen
Zur Suche springen
local p = {};
local LuaWiki = require( "Modul:LuaWiki" );
function p.Execute(frame)
local T_Prev = {};
local T_Amt = {};
local T_Zeit = {};
local T_Next = {};
local Tabellenkopf = LuaWiki.transclude("Vorlage:Personenleiste/Kopf");
local Tabellenzeile = LuaWiki.transclude("Vorlage:Personenleiste/Zeile");
local Tabellenende = LuaWiki.transclude("Vorlage:Personenleiste/Ende");
local idx = 0;
local Zeile = "";
local sidx = ""; -- Nimmt benannte Argumentnamen auf
local Anzahl = 0; -- Anzahl der Zeilen
local VG = frame.args['VG'] or "";
local VW = frame.args['VW'] or "";
local VWW = frame.args['VWW'] or "";
local NG = frame.args['NG'] or "";
local NW = frame.args['NW'] or "";
local NWW = frame.args['NWW'] or "";
local Titel = frame.args['TI'] or "";
if Titel == "" then Titel = "Amt"; end;
-- Zeilenparameter einlesen
for idx = 1, 9 do
sidx = 'A'..tostring(idx);
table.insert(T_Amt, frame.args[sidx] or "");
sidx = 'V'..tostring(idx);
table.insert(T_Prev, frame.args[sidx] or "");
sidx = 'Z'..tostring(idx);
table.insert(T_Zeit, frame.args[sidx] or "");
sidx = 'N'..tostring(idx);
table.insert(T_Next, frame.args[sidx] or "");
end;
for idx = 1, 9 do
if mw.ustring.len(T_Amt[idx]) > 0 then
Anzahl = idx;
if mw.ustring.len(T_Zeit[idx]) > 0 then
T_Zeit[idx] = "<br".." />" .. T_Zeit[idx];
else
T_Zeit[idx] = "";
end;
end;
end; -- for idx
-- Abwärtskompatiblität: weibliche Wikiparameter auswerten.
-- Zuerst Wikilogik einstellen: Auch Leerstring ist false
local B_VG = string.len(VG) > 0;
local B_VW = string.len(VW) > 0;
local B_VWW = string.len(VWW) > 0;
local B_NG = string.len(NG) > 0;
local B_NW = string.len(NW) > 0;
local B_NWW = string.len(NWW) > 0;
-- .WW überschreibt .W und dieses das Maskulinum
-- Reihenfolge einhalten!
if B_VW then T_Prev[1] = VW; end;
if B_VWW then T_Prev[1] = VWW; end;
if B_NW then T_Next[1] = NW; end;
if B_NWW then T_Next[1] = NWW; end;
-- Ermitteln der Kopftexte
local KopfV = "Vorgänger";
local KopfN = "Nachfolger";
local DifferntPersonV = false;
local DifferntPersonN = false;
if B_VW or B_VG then KopfV = "Vorgängerin"; end;
if B_VWW then KopfV = "Vorgängerinnen"; end;
if B_NW or B_NG then KopfN = "Nachfolgerin"; end;
if B_NWW then KopfN = "Nachfolgerinnen"; end;
-- Wenn VG/NG gesetzt, aber verschiedene Personen, dann doch Plural
if Anzahl > 1 then
for idx = 2, Anzahl do
if T_Prev[1] ~= T_Prev[idx] then DifferntPersonV = true; end;
if T_Next[1] ~= T_Next[idx] then DifferntPersonN = true; end;
end;
end;
if B_VG and DifferntPersonV then KopfV = "Vorgängerinnen"; end;
if B_NG and DifferntPersonN then KopfN = "Nachfolgerinnen"; end;
-- Zusammenbau der Leiste, zuerst der Kopf
local HTML = Tabellenkopf;
local sPrev = "";
local sNext = "";
local sAmt = "";
local sZeit = "";
HTML = mw.ustring.gsub(HTML,'{Kopf_L}',KopfV);
HTML = mw.ustring.gsub(HTML,'{Titel}' ,Titel);
HTML = mw.ustring.gsub(HTML,'{Kopf_R}',KopfN);
-- Jetzt "Anzahl" Zeilen ergänzen
for idx = 1, Anzahl do
-- Kopien anfertigen, da sonst rekursiv
sZeile = Tabellenzeile;
sPrev = T_Prev[idx];
sNext = T_Next[idx];
sAmt = T_Amt[idx];
sZeit = T_Zeit[idx];
-- Substitution der Platzhalter
sZeile = mw.ustring.gsub(sZeile,'{Prev}',sPrev);
sZeile = mw.ustring.gsub(sZeile,'{Next}',sNext);
sZeile = mw.ustring.gsub(sZeile,'{Amt}' ,sAmt);
sZeile = mw.ustring.gsub(sZeile,'{Zeit}',sZeit);
-- Fertige Zeile anhängen
HTML = HTML .. sZeile;
end; -- for idx
-- Tabellenende dazu. Einlesen, um ggf. extern ändern zu können.
HTML = HTML .. Tabellenende;
return HTML;
end; -- function p.Execute()
return p;