Moduł:Lista newsów: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
(nowa strona) |
M (byłyby bugi w lata przestępne) |
||
(Nie pokazano 16 wersji utworzonych przez 2 użytkowników) | |||
Linia 1: | Linia 1: | ||
local monthNames = {"styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień"} |
|||
local daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} |
|||
local function tfind(t, what) |
|||
⚫ | |||
⚫ | |||
return k |
|||
end |
|||
end |
|||
return nil |
|||
end |
|||
local function leapYear(year) |
|||
return (year % 400 == 0 or (year % 100 ~= 0 and year % 4 == 0)) |
|||
end |
|||
local function prevDate(obj) |
|||
obj.day = obj.day - 1 |
|||
if obj.day < 1 then |
|||
obj.month = obj.month - 1 |
|||
if obj.month < 1 then |
|||
obj.year = obj.year - 1 |
|||
obj.month = 12 |
|||
end |
|||
obj.day = daysInMonth[obj.month] |
|||
if obj.month == 2 and leapYear(obj.year) then |
|||
obj.day = obj.day + 1 |
|||
end |
|||
end |
|||
end |
|||
local p = {} |
local p = {} |
||
function p.list(frame) |
function p.list(frame) |
||
local day = frame.args[1] |
local day = frame.args[1] |
||
local |
local rawMonth = frame.args[2] |
||
local month |
|||
⚫ | |||
local limit = frame.args[5] |
|||
⚫ | |||
⚫ | |||
if rawMonth == "+" then |
|||
⚫ | |||
month = rawMonth |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local n = tonumber(rawMonth) |
|||
⚫ | |||
if n ~= nil then |
|||
⚫ | |||
if n > 0 and n <= #monthNames then |
|||
month = n |
|||
else |
|||
return mw.smw.info('Niepoprawny numer miesiąca', 'error') |
|||
end |
|||
else |
|||
local find = tfind(monthNames, mw.ustring.lower(rawMonth)) |
|||
if find ~= nil then |
|||
month = find |
|||
else |
|||
return mw.smw.info('Niepoprawna nazwa miesiąca', 'error') |
|||
end |
|||
end |
|||
end |
|||
local eyear = frame.args[3] |
|||
⚫ | |||
local year = frame.args[4] |
|||
⚫ | |||
local date = {year = year, month = month, day = day} |
|||
while true do |
|||
⚫ | |||
if query then |
|||
⚫ | |||
for k, v in pairs(query) do |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
local wikitext = "" |
local wikitext = "" |
||
Linia 24: | Linia 84: | ||
end |
end |
||
end |
end |
||
mw.log(wikitext) |
|||
return frame:preprocess(wikitext) |
return frame:preprocess(wikitext) |
||
end |
end |
||
if date.month == "+" or date.day == "+" then |
|||
⚫ | |||
return "(brak wyników)" |
|||
mw.log("Błąd w zapytaniu SMW") |
|||
end |
|||
return mw.smw.info('Błąd w zapytaniu SMW w module "Lista newsów z danego dnia".', 'error') |
|||
prevDate(date) |
|||
end |
end |
||
end |
end |
Aktualna wersja na dzień 00:19, 29 sie 2022
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Lista newsów/opis
local monthNames = {"styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień"}
local daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
local function tfind(t, what)
for k, v in ipairs(t) do
if v == what then
return k
end
end
return nil
end
local function leapYear(year)
return (year % 400 == 0 or (year % 100 ~= 0 and year % 4 == 0))
end
local function prevDate(obj)
obj.day = obj.day - 1
if obj.day < 1 then
obj.month = obj.month - 1
if obj.month < 1 then
obj.year = obj.year - 1
obj.month = 12
end
obj.day = daysInMonth[obj.month]
if obj.month == 2 and leapYear(obj.year) then
obj.day = obj.day + 1
end
end
end
local p = {}
function p.list(frame)
local day = frame.args[1]
local rawMonth = frame.args[2]
local month
local limit = frame.args[5]
if rawMonth == "+" then
month = rawMonth
else
local n = tonumber(rawMonth)
if n ~= nil then
if n > 0 and n <= #monthNames then
month = n
else
return mw.smw.info('Niepoprawny numer miesiąca', 'error')
end
else
local find = tfind(monthNames, mw.ustring.lower(rawMonth))
if find ~= nil then
month = find
else
return mw.smw.info('Niepoprawna nazwa miesiąca', 'error')
end
end
end
local eyear = frame.args[3]
local year = frame.args[4]
local date = {year = year, month = month, day = day}
while true do
local query = mw.smw.ask{"[[NonNews:+]] [[Ma rok::<<" .. date.year .. "]] [[Ma dzień::" .. date.day .. "]] [[Ma miesiąc::" .. (monthNames[date.month] or "+") .. "]]", "?Ma dzień=dzień", "?Ma miesiąc=miesiąc", "?Ma rok=rok", limit = limit, order = 'rand'}
if query then
local map = {}
for k, v in pairs(query) do
--[[
mw.log(k)
mw.logObject(v)
--]]
map[v.rok] = map[v.rok] or {}
table.insert(map[v.rok], v)
end
local wikitext = ""
for i = 2005, eyear do
if #(map[i] or {}) ~= 0 then
wikitext = wikitext .. "'''" .. i .. "'''\n"
for k, v in pairs(map[i]) do
wikitext = wikitext .. "* " .. v[1] .. "\n"
end
end
end
return frame:preprocess(wikitext)
end
if date.month == "+" or date.day == "+" then
return "(brak wyników)"
end
prevDate(date)
end
end
return p