Modul:Chronik: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
(revert zu 27. August 2025, 11:09 Uhr aufgrund Skriptfehler)
Markierungen: Manuelle Zurücksetzung Zurückgesetzt
Keine Bearbeitungszusammenfassung
 
(18 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local p = {}
local p = {}
local c = require("Modul:Common")
local str = require("Modul:String")
local str = require("Modul:String")
local srf = require("Modul:Subrefs")
local com = require("Modul:Common")
local lfd = require("Modul:LinkFormDatum")
local lfd = require("Modul:LinkFormDatum")
local lsd = require("Modul:LinkSubformDatum")
local lsd = require("Modul:LinkSubformDatum")


function p.Eintrag(frame)
function p.Abfrage(frame)
local args = frame.args
local title = mw.title.getCurrentTitle().text
local title = mw.title.getCurrentTitle()
local page = frame.args[1] or title
local titlename = title.text
local t = p.abfrage(page)
local fulltitle = title.fullText
return frame:preprocess(t)
local year
end
local data = {
 
["Beschreibung"] = args[2],
function p.abfrage(page)
["Thema"] = "Ereignis",
local results = mw.smw.ask(
["Artikel"] = fulltitle
'[[Startjahr::' .. page .. ']] ' ..
}
--'[[Artikel::!' .. page .. ']] ' ..
-- Wenn das Lemma eine Jahreszahl ist, merken
[[
if c.istJahreszahl(titlename) then
|?Schlagzeile
year = titlename
|?Beschreibung
    end
|?Startdatum
    local data_date = p.dateParsing(args[1], year)
|?Starttag
    local all_data = c.merge_tables(data, data_date)
|?Startjahr
return data_date["Startdatum"] .. ": " .. args[2] --.. '<br>' ..
|?Enddatum
--tableToString(all_data)
|?Endtag
|?Endjahr
|?Artikel
|?Option
|?Thema
]])
local t = ''
for i, r in ipairs(results or {}) do
t = t .. '* ' .. r["Startdatum"] .. ' - '
t = t .. r["Beschreibung"]
t = t .. "\n"
end
return t
end
 
function p.AbfrageJahrestag(frame)
return p.abfrageJahrestag(frame.args[1])
end
 
function p.abfrageJahrestag(year_day)
return year_day
end
 
function p.AbfrageJahr(frame)
return p.abfrageJahr(frame.args[1])
end
 
function p.abfrageJahr(year)
return year
end
end


function p.dateParsing(s, year)
function p.Eintrag(frame)
-- Parses a date down where s is the datestring and year can be nil or string
local title = mw.title.getCurrentTitle().text
local daterange = frame.args[1]
local text = frame.args[2] or ""
local option = frame.args[3]
local thema = frame.args["Thema"] or "Ereignis"
local year = nil
if com.istJahreszahl(title) then
year = title
end
local data = p.dateParser(daterange, year)
local ds = ''
if not com.isEmpty(data['Starttag']) then
if data['Starttag']:match("^%d") then
ds = '[[' .. data['Starttag'] .. ']] '
else
ds = data['Starttag'] .. ' '
end
end
if not year then
ds = ds .. '[[' .. data['Startjahr'] .. ']]'
end
if data['Enddatum'] then
ds = ds .. "- [[" .. data['Endtag'] .. "]]"
if not year then
ds = ds .. "[[" .. data['Endjahr'] .. "]]"
end
end
data['Beschreibung'] = text
data['Option'] = option
data['Thema'] = thema
data['Artikel'] = title
mw.smw.subobject(data)
-- Wenn s eine Zeitspanne ist, teile bei "-" oder "bis"
local t
local dates = str.split(s, 'bis') -- split hatte in Modul:Commons einen bug(!)
if option == "nodate" then
if c.len(dates) == 1 then
t = srf.subrefs(text)
dates=str.split(s, 'bis')
else
t = ds .. ': ' .. srf.subrefs(text)
end
end
return frame:preprocess(t)
-- Ist eine Zeitspanne wie "3. bis 5. Mai" angegeben, kopiere Monat aus Enddatum
end
local sds = p.checkYear(dates[1], year)
 
local sd = lfd.humanToFormDate(dates[1])
function p.dateParser(s, year)
local start_date, end_date = p.splitDateString(s, year)
start_date, end_date = p.completeDates(start_date, end_date, year)
local sdf = lfd.humanToFormDate(start_date)
local data = {
local data = {
-- Erstmal das Startdatum schreiben
['Startdatum'] = sdf,
["SDstring"] = dates[1],
['Startjahr'] = lsd.getYear(sdf),
["Startdatum"] = sd,
['Starttag'] = lsd.getMonthday(sdf)
["Startjahr"] = lsd.getYear(sd),
["Starttag"] = lsd.getMonthday(sd),
["length"] = c.len(dates),
["year"] = year,
}
}
if end_date then
local ed
local edf = lfd.humanToFormDate(end_date)
if c.len(dates) >= 2 then
data['Enddatum'] = edf
-- War eine Zeitspanne angegeben gibt es ein Endatum
data['Endjahr'] = lsd.getYear(edf)
ed=lfd.humanToFormDate(dates[2])
data['Endtag'] = lsd.getMonthday(edf)
data["EDstring"] = dates[2]
data["Enddatum"] = ed
data["Endjahr"] = lsd.getYear(ed)
data["Endtag"] = lsd.getMonthday(ed)
end
if c.len(dates) >= 3 then
data["3 is"] = dates[3]
end
end
mw.logObject(data)
return data
return data
end
end


function p.checkYear(s, year)
function p.completeDates(start_date, end_date, year)
-- Wenn s nicht auf eine Jahreszahl endet, dann füge diese hinzu
--[[Jetzt müssen die gesplitteten Datum vervollständigt werden. Kann ja
    return s
sein, daß etwas wie 6. - 10. Januar angegeben ist. Und das Jahr, wenn nicht
gegeben, muß auch aus dem year entnommen werden können.]]
--start_date = str.strip(start_date)
--end_date = str.strip(end_date)
local sd = str.split(start_date, ' ')
if not com.isEmpty(end_date) then
-- Wenn ein Enddatum gegeben ist
local ed = str.split(end_date, ' ')
mw.logObject(ed)
if com.len(ed) == 2 then
-- Wenn das Enddatum kein Jahr enthält, füge es aus year hinzu
ed[3] = year
end_date = end_date .. " " .. ed[3]
end
if com.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum
start_date = start_date .. " " .. ed[3]
elseif com.len(sd) == 1 then
-- Startdatum enthält weder Monat noch Jahr, hole sie von Enddatum
start_date = start_date .. " " .. ed[2] .. " " .. ed[3]
end
else
-- Wenn nur ein Startdatum gegeben ist
if year == nil then
return start_date, end_date
end
if com.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es aus year
sd[3] = year
start_date = start_date .. " " .. sd[3]
elseif com.len(sd) == 1 then
sd[3] = year
start_date = start_date .. " " .. sd[3]
end
end
return start_date, end_date
end
end


function p.checkMonth(s, month)
function p.splitDateString(s)
-- Aua
-- Teilt ein von/bis Datum in Start- und End-Datum auf.
return s
local dates = str.split(s, "-")
-- Wenn splitten mit "-" nur ein Ergebnis bringt, splitte mit "bis"
if com.len(dates) == 1 then
dates = str.split(s, "bis")
end
-- Alle Leerzeichen links und rechts in den Ergebnissen entfernen
for i, v in ipairs(dates) do
dates[i] = str.strip(dates[i])
end
return dates[1], dates[2]
end
end


return p
return p