Modul:Saison: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| (7 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
-- Erstellt Links zur Vor- und Folgesaison aus dem Titel | |||
local function addSeasonLinks(box, titel) | |||
-- Saison aus dem Titel auslesen | |||
local jahr1, jahr2 = titel:match("Saison%s+(%d%d%d%d)/(%d%d)") | |||
if not jahr1 or not jahr2 then | |||
return | |||
end | |||
jahr1 = tonumber(jahr1) | |||
jahr2 = tonumber(jahr2) | |||
-- Vor- und Folgesaison berechnen | |||
local vor1 = jahr1 - 1 | |||
local vor2 = (jahr2 - 1) % 100 | |||
local folge1 = jahr1 + 1 | |||
local folge2 = (jahr2 + 1) % 100 | |||
local vorsaison = string.format("Saison %d/%02d", vor1, vor2) | |||
local folgesaison = string.format("Saison %d/%02d", folge1, folge2) | |||
-- Zeile hinzufügen | |||
box | |||
:tag("tr") | |||
:tag("td") | |||
:attr("colspan", "2") | |||
:wikitext( | |||
"[[" .. vorsaison .. "|←" .. vorsaison .. "]]" .. | |||
" · " .. | |||
"[[" .. folgesaison .. "|" .. folgesaison .. "➜]]" | |||
) | |||
:done() | |||
:done() | |||
end | |||
local p = {} | local p = {} | ||
-- Erstellt eine Zeile der Infobox | |||
local function addRow(box, label, value) | local function addRow(box, label, value) | ||
| Zeile 20: | Zeile 61: | ||
-- Liste der möglichen Felder | |||
local fields = { | |||
{"table_place", "Tabellen Platz"}, | |||
{"points", "Punkte"}, | |||
{"goals", "Tore"}, | |||
{"coach", "Trainer"}, | |||
{"date_start", "Erste Runde"}, | |||
{"date_finish", "Letzte Runde"}, | |||
} | |||
-- Hauptfunktion | |||
function p.main(frame) | function p.main(frame) | ||
-- Parameter der Vorlage holen | |||
local args = frame:getParent().args | local args = frame:getParent().args | ||
-- Grundparameter | |||
local titel = args.titel or "" | local titel = args.titel or "" | ||
local bild = args.bild or "" | local bild = args.bild or "" | ||
local bildbeschreibung = args.bildbeschreibung or "" | local bildbeschreibung = args.bildbeschreibung or "" | ||
-- Tabelle erstellen | |||
local box = mw.html.create("table") | local box = mw.html.create("table") | ||
:addClass("infobox") | :addClass("infobox") | ||
| Zeile 34: | Zeile 92: | ||
-- Titel | -- Titel | ||
if titel ~= "" then | if titel ~= "" then | ||
box | box | ||
:tag("caption") | :tag("caption") | ||
:wikitext(titel) | |||
:done() | |||
end | end | ||
| Zeile 47: | Zeile 107: | ||
:tag("tr") | :tag("tr") | ||
:tag("td") | :tag("td") | ||
:attr("colspan", "2") | |||
:addClass("infobox-bild") | |||
:wikitext("[[Datei:" .. bild .. "|250px]]") | |||
:done() | |||
:done() | :done() | ||
-- Bildbeschreibung | |||
if bildbeschreibung ~= "" then | if bildbeschreibung ~= "" then | ||
box | box | ||
:tag("tr") | :tag("tr") | ||
:tag("td") | :tag("td") | ||
:attr("colspan", "2") | |||
:addClass("infobox-bild") | |||
:wikitext(bildbeschreibung) | |||
:done() | |||
:done() | :done() | ||
end | end | ||
end | end | ||
-- | -- Alle Felder automatisch hinzufügen | ||
for _, field in ipairs(fields) do | |||
local parameter = field[1] | |||
local label = field[2] | |||
local value = args[parameter] | |||
addRow(box, label, value) | |||
end | |||
addSeasonLinks(box, titel) | |||
-- HTML zurückgeben | |||
return tostring(box) | return tostring(box) | ||
end | end | ||
return p | return p | ||
Aktuelle Version vom 2. September 2026, 18:10 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Saison/Doku erstellt werden
-- Erstellt Links zur Vor- und Folgesaison aus dem Titel
local function addSeasonLinks(box, titel)
-- Saison aus dem Titel auslesen
local jahr1, jahr2 = titel:match("Saison%s+(%d%d%d%d)/(%d%d)")
if not jahr1 or not jahr2 then
return
end
jahr1 = tonumber(jahr1)
jahr2 = tonumber(jahr2)
-- Vor- und Folgesaison berechnen
local vor1 = jahr1 - 1
local vor2 = (jahr2 - 1) % 100
local folge1 = jahr1 + 1
local folge2 = (jahr2 + 1) % 100
local vorsaison = string.format("Saison %d/%02d", vor1, vor2)
local folgesaison = string.format("Saison %d/%02d", folge1, folge2)
-- Zeile hinzufügen
box
:tag("tr")
:tag("td")
:attr("colspan", "2")
:wikitext(
"[[" .. vorsaison .. "|←" .. vorsaison .. "]]" ..
" · " ..
"[[" .. folgesaison .. "|" .. folgesaison .. "➜]]"
)
:done()
:done()
end
local p = {}
-- Erstellt eine Zeile der Infobox
local function addRow(box, label, value)
if value and value ~= "" then
box
:tag("tr")
:tag("th")
:wikitext(label)
:done()
:tag("td")
:wikitext(value)
:done()
:done()
end
end
-- Liste der möglichen Felder
local fields = {
{"table_place", "Tabellen Platz"},
{"points", "Punkte"},
{"goals", "Tore"},
{"coach", "Trainer"},
{"date_start", "Erste Runde"},
{"date_finish", "Letzte Runde"},
}
-- Hauptfunktion
function p.main(frame)
-- Parameter der Vorlage holen
local args = frame:getParent().args
-- Grundparameter
local titel = args.titel or ""
local bild = args.bild or ""
local bildbeschreibung = args.bildbeschreibung or ""
-- Tabelle erstellen
local box = mw.html.create("table")
:addClass("infobox")
-- Titel
if titel ~= "" then
box
:tag("caption")
:wikitext(titel)
:done()
end
-- Bild
if bild ~= "" then
box
:tag("tr")
:tag("td")
:attr("colspan", "2")
:addClass("infobox-bild")
:wikitext("[[Datei:" .. bild .. "|250px]]")
:done()
:done()
-- Bildbeschreibung
if bildbeschreibung ~= "" then
box
:tag("tr")
:tag("td")
:attr("colspan", "2")
:addClass("infobox-bild")
:wikitext(bildbeschreibung)
:done()
:done()
end
end
-- Alle Felder automatisch hinzufügen
for _, field in ipairs(fields) do
local parameter = field[1]
local label = field[2]
local value = args[parameter]
addRow(box, label, value)
end
addSeasonLinks(box, titel)
-- HTML zurückgeben
return tostring(box)
end
return p