Modul:Chronik: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(14 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local p = {}
local p = {}
local str = require("Modul:String")
local str = require("Modul:String")
local sr = require("Modul:Subrefs")
local srf = require("Modul:Subrefs")
local c = require("Modul:Common")
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.Abfrage(frame)
local title = mw.title.getCurrentTitle().text
local page = frame.args[1] or title
local t = p.abfrage(page)
return frame:preprocess(t)
end
function p.abfrage(page)
local results = mw.smw.ask(
'[[Startjahr::' .. page .. ']] ' ..
--'[[Artikel::!' .. page .. ']] ' ..
[[
|?Schlagzeile
|?Beschreibung
|?Startdatum
|?Starttag
|?Startjahr
|?Enddatum
|?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


function p.Eintrag(frame)
function p.Eintrag(frame)
Zeile 13: Zeile 62:
local thema = frame.args["Thema"] or "Ereignis"
local thema = frame.args["Thema"] or "Ereignis"
local year = nil
local year = nil
if c.istJahreszahl(title) then
if com.istJahreszahl(title) then
year = title
year = title
end
end
local data = p.dateParser(daterange, year)
local data = p.dateParser(daterange, year)
local ds = '[[' .. data['Starttag'] .. ']]'
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
if not year then
ds = ds .. ' [[' .. data['Startjahr'] .. ']]'
ds = ds .. '[[' .. data['Startjahr'] .. ']]'
end
end
if data['Enddatum'] then
if data['Enddatum'] then
ds = ds .. " - [[" .. data['Endtag'] .. "]]"
ds = ds .. "- [[" .. data['Endtag'] .. "]]"
if not year then
if not year then
ds = ds .. " [[" .. data['Endjahr'] .. "]]"
ds = ds .. "[[" .. data['Endjahr'] .. "]]"
end
end
end
end
Zeile 30: Zeile 86:
data['Option'] = option
data['Option'] = option
data['Thema'] = thema
data['Thema'] = thema
data['Artikel'] = title
mw.smw.subobject(data)
mw.smw.subobject(data)
local t
local t
if option == "nodate" then
if option == "nodate" then
t = sr.subrefs(text)
t = srf.subrefs(text)
else
else
t = ds .. ': ' .. sr.subrefs(text)
t = ds .. ': ' .. srf.subrefs(text)
end
end
return frame:preprocess(t)
return frame:preprocess(t)
Zeile 65: Zeile 122:
gegeben, muß auch aus dem year entnommen werden können.]]
gegeben, muß auch aus dem year entnommen werden können.]]
start_date = str.strip(start_date)
--start_date = str.strip(start_date)
end_date = str.strip(end_date)
--end_date = str.strip(end_date)
local sd = str.split(start_date, ' ')
local sd = str.split(start_date, ' ')
if not c.isEmpty(end_date) then
if not com.isEmpty(end_date) then
-- Wenn ein Enddatum gegeben ist
-- Wenn ein Enddatum gegeben ist
local ed = str.split(end_date, ' ')
local ed = str.split(end_date, ' ')
mw.logObject(ed)
mw.logObject(ed)
if c.len(ed) == 2 then
if com.len(ed) == 2 then
-- Wenn das Enddatum kein Jahr enthält, füge es aus year hinzu
-- Wenn das Enddatum kein Jahr enthält, füge es aus year hinzu
ed[3] = year
ed[3] = year
end_date = end_date .. " " .. ed[3]
end_date = end_date .. " " .. ed[3]
end
end
if c.len(sd) == 2 then
if com.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum
-- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum
start_date = start_date .. " " .. ed[3]
start_date = start_date .. " " .. ed[3]
elseif c.len(sd) == 1 then
elseif com.len(sd) == 1 then
-- Startdatum enthält weder Monat noch Jahr, hole sie von Enddatum
-- Startdatum enthält weder Monat noch Jahr, hole sie von Enddatum
start_date = start_date .. " " .. ed[2] .. " " .. ed[3]
start_date = start_date .. " " .. ed[2] .. " " .. ed[3]
Zeile 87: Zeile 144:
else
else
-- Wenn nur ein Startdatum gegeben ist
-- Wenn nur ein Startdatum gegeben ist
if c.len(sd) == 2 then
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
-- Wenn das Startdatum kein Jahr enthält, hole es aus year
sd[3] = year
sd[3] = year
start_date = start_date .. " " .. sd[3]
start_date = start_date .. " " .. sd[3]
elseif c.len(sd) == 1 then
elseif com.len(sd) == 1 then
sd[3] = year
sd[3] = year
start_date = start_date .. " " .. sd[3]
start_date = start_date .. " " .. sd[3]
Zeile 103: Zeile 163:
local dates = str.split(s, "-")
local dates = str.split(s, "-")
-- Wenn splitten mit "-" nur ein Ergebnis bringt, splitte mit "bis"
-- Wenn splitten mit "-" nur ein Ergebnis bringt, splitte mit "bis"
if c.len(dates) == 1 then
if com.len(dates) == 1 then
dates = str.split(s, "bis")
dates = str.split(s, "bis")
end
end