Modul:Saison: Unterschied zwischen den Versionen

Aus LASK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(8 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)
    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)
function p.main(frame)


    -- Parameter der Vorlage holen
     local args = frame:getParent().args
     local args = frame:getParent().args


     -- Parameter auslesen
 
     -- 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 ""
    local beruf = args.beruf or ""
    local geburt = args.geburt or ""
    local geburtsort = args.geburtsort or ""
    local land = args.land or ""


     -- Infobox erstellen
 
     -- Tabelle erstellen
     local box = mw.html.create("table")
     local box = mw.html.create("table")
         :addClass("infobox")
         :addClass("infobox")


     -- Titel
     -- Titel
     if titel ~= "" then
     if titel ~= "" then
         box
         box
             :tag("caption")
             :tag("caption")
            :wikitext(titel)
                :wikitext(titel)
            :done()
                :done()
 
     end
     end


     -- Bild
     -- Bild
     if bild ~= "" then
     if bild ~= "" then


         local bildzeile = box
         box
             :tag("tr")
             :tag("tr")
 
                :tag("td")
        bildzeile
                    :attr("colspan", "2")
            :tag("td")
                    :addClass("infobox-bild")
            :attr("colspan", "2")
                    :wikitext("[[Datei:" .. bild .. "|250px]]")
            :addClass("infobox-bild")
                    :done()
            :wikitext("[[Datei:" .. bild .. "|250px]]")
             :done()
             :done()


        bildzeile:done()


         -- Bildbeschreibung
         -- Bildbeschreibung
         if bildbeschreibung ~= "" then
         if bildbeschreibung ~= "" then
             box
             box
                 :tag("tr")
                 :tag("tr")
                     :tag("td")
                     :tag("td")
                    :attr("colspan", "2")
                        :attr("colspan", "2")
                    :addClass("infobox-bild")
                        :addClass("infobox-bild")
                    :wikitext(bildbeschreibung)
                        :wikitext(bildbeschreibung)
                    :done()
                        :done()
                 :done()
                 :done()
         end
         end
     end
     end


    -- Beruf
    if beruf ~= "" then
        box
            :tag("tr")
                :tag("th")
                    :wikitext("Beruf")
                    :done()
                :tag("td")
                    :wikitext(beruf)
                    :done()
            :done()
    end


     -- Geburtsdatum
     -- Alle Felder automatisch hinzufügen
     if geburt ~= "" then
     for _, field in ipairs(fields) do
        box
 
            :tag("tr")
        local parameter = field[1]
                :tag("th")
        local label = field[2]
                    :wikitext("Geboren")
 
                    :done()
        local value = args[parameter]
                :tag("td")
 
                    :wikitext(geburt)
        addRow(box, label, value)
                    :done()
            :done()
    end


    -- Geburtsort
    if geburtsort ~= "" then
        box
            :tag("tr")
                :tag("th")
                    :wikitext("Geburtsort")
                    :done()
                :tag("td")
                    :wikitext(geburtsort)
                    :done()
            :done()
     end
     end


    -- Land
addSeasonLinks(box, titel)
    if land ~= "" then
        box
            :tag("tr")
                :tag("th")
                    :wikitext("Land")
                    :done()
                :tag("td")
                    :wikitext(land)
                    :done()
            :done()
    end


    -- 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