Modul:Arhiva
Izgled
Modul ispisuje poveznice na slijedne arhive. Modul je dio predloška {{ArhivPočetak}}.
Pogreške u modulu svrstavaju se u Kategorija:Pogreške u modulu Arhiva
Wikipedija:Kafić/Arhiv 2019 6 => Wikipedija:Izabrani članci/Prijedlozi za izabrane članke/11. 2009. => Wikipedija:Izabrani članci/Prijedlozi za izabrane članke/51. 2015. (53 tjedna) => Razgovor sa suradnikom:Ivi104/Arhiv 3 => Wikipedija:Jubilarni članci/224 000 članaka =>Arhive: 221 000 članaka • 222 000 članaka • 223 000 članaka • 224 000 članaka • 225 000 članaka • 226 000 članaka • 227 000 članaka
Wikipedija:Članak tjedna/Prijedlozi za tjedne članke/51. 2022. =>
Wikipedija:Članak tjedna/Prijedlozi za tjedne članke/02. 2023. =>
Predložak:Novosti/Arhiv/2020. =>
Wikipedija:Na pažnju administratorima/Arhiv 2023. – 2024. | Arh (lista) =>
local p = {}
-- automatski traži kombinacije tjedna, mjeseca i godine
-- i popisuje slijedne vrijednosti sukladno uočenom uzorku
function p.main(frame)
local initialText = '<div style="text-align: center;">Arhive: '
-- TODO: leading zeroes
local naslov = mw.title.getCurrentTitle()
local hc = mw.getCurrentFrame().args[1]
or mw.getCurrentFrame():getParent().args[1]
or naslov.nsText .. ":" .. naslov.text
hc = mw.title.new(hc)
--pretraži samo zadnju podstranicu (za slučaj da sur.ime ima broj)
--(ne-brojevi+razmak)(brojevi)(ne-slova)(brojevi)(ne-slova+slova)
local pref, n1, sep1, n2, sep2 = hc.subpageText:match("([%D%s]*)([%d]*)([%W]*)([%d]*)([%W%w]*)")
-- ako nema poklapanja svaki dio vraća ''
-- ponovno sastavi puni naslov stranice
local prefix = hc.nsText .. ":" .. hc.baseText .. "/" .. pref
n1 = mw.text.trim(n1)
--n2 = mw.text.trim(n2)
mw.log("p=" .. prefix .. " n1=" .. n1 .. " sep1=" .. sep1 .. " n2=" .. n2 .. " sep2=" .. sep2)
if n1 == "" then
return '[[Kategorija:Pogreške u modulu Arhiva|A]]'
end
if #n2 == 0 then
-- u naslovu je jedan broj, n1
return initialText .. printIncrements(prefix, n1, sep1) .. '</div>'
else
-- oba broja postoje (mjesec i godins. Ako je separator povlaka
-- tada će broj biti negativan => preseli minus u sep
if tonumber(n1) < 0 then
n1 = abs(tonumber(n1))
sep = "-"
elseif tonumber(n2) < 0 then
n2 = abs(tonumber(n2))
sep = "-"
end
-- uncertain if other is week or month
local other, year, otherFirst, continuous, week
if #n1 > 3 then
year = n1
other = n2
otherFirst = false
continuous = mw.title.new( prefix .. year .. sep1 .. 54 .. sep2).exists
week = mw.title.new( prefix .. year .. sep1 .. 52 .. sep2).exists
else
year = n2
other = n1
otherFirst = true
continuous = mw.title.new( prefix .. 54 .. sep1 .. year .. sep2).exists
week = mw.title.new( prefix .. 52 .. sep1 .. year .. sep2).exists
end
if continuous then
return initialText .. printContinuous(prefix, other, sep1, year, sep2, otherFirst) .. '</div>'
elseif week then
return initialText .. printWeek(prefix, other, sep1, year, sep2, otherFirst) .. '</div>'
else
return initialText.. printMonthYearIncrements(prefix, other, sep1, year, sep2, otherFirst) .. '</div>'
end
--return hc .. '<br>'
end
end
-- koristiti za nejednaka imenovanja
-- popisuje sve podstranice naslova prijašnje razine kao sklopivi popis
function p.lista(frame)
local naslov = mw.title.getCurrentTitle()
local hc = mw.getCurrentFrame().args[1]
or mw.getCurrentFrame():getParent().args[1]
or naslov.nsText .. ":" .. naslov.text
hc = mw.title.new(hc)
local prefix = hc.nsText .. ":" .. hc.baseText .. "/"
local suffix = mw.getCurrentFrame().args['sufiks']
or mw.getCurrentFrame():getParent().args['sufiks'] or ''
local pages = frame:preprocess( '{{:Posebno:PrefixIndex/' .. prefix .. suffix .. '}}')
local ret = mw.html.create('table')
:addClass('arhiva-lista')
:addClass('mw-collapsible')
:addClass('mw-collapsed')
:cssText('width:100%;')
ret:tag('caption')
:cssText('text-align: center; font-weight: 700;')
:wikitext('Popis arhiva: '):done()
ret:tag('tr'):tag('td'):node(pages)
:wikitext('[[Kategorija:Pogreške u modulu Arhiva|P]]')
:allDone()
return tostring(ret)
end
function printIncrements(prefix, br, sep1)
mw.log('increments', prefix, br, sep1)
local result = ""
local broj = tonumber(br)
local start = math.max(1, broj - 3) -- Ensure numbers before don't go below 1
local finish = broj + 3
-- Print the range
for i = start, finish do
local paddedi = "0" .. tostring(i)
if not mw.title.new(prefix .. i).exists and mw.title.new(prefix .. paddedi).exists then
result = result .. "[[" .. prefix .. paddedi .. sep1 .. "|" .. paddedi .. sep1 .. "]] • "
else
result = result .. "[[" .. prefix .. i .. sep1 .. "|" .. i .. sep1 .. "]] • "
end
end
return result:sub(1, -14) .. "<br>"
end
function printContinuous(prefix, month, sep1, year, sep2, monthFirst)
-- Helper function to adjust month and year properly
local function adjustMonthYear(month, year, increment)
local newMonth = month + increment
local newYear = year
-- Adjust the month and year when crossing December or January
while newMonth > 99 and tonumber(month) < 100 do
newMonth = newMonth - 99
newYear = newYear + 1
end
while newMonth < 1 and tonumber(month) < 100 do
newMonth = newMonth + 99
newYear = newYear - 1
end
return newMonth, newYear
end
local result = ""
-- Iterate through the range from -3 months to +3 months
for i = -3, 3 do
local newMonth, newYear = adjustMonthYear(month, year, i)
mw.log("cont", month, year, i, "=>", newMonth, newYear)
local paddedMonth = "0" .. tostring(newMonth)
local checkedMonth = newMonth
local linkPage = ""
local linkText = ""
if monthFirst then
if
not mw.title.new(prefix .. newMonth .. sep1 .. newYear .. sep2).exists
and mw.title.new(prefix .. paddedMonth .. sep1 .. newYear .. sep2).exists
then
checkedMonth = paddedMonth
end
linkPage = prefix .. checkedMonth .. sep1 .. newYear .. sep2
linkText = checkedMonth .. sep1 .. newYear .. sep2
else
if
not mw.title.new(prefix .. newYear .. sep1 .. newMonth .. sep2).exists
and mw.title.new(prefix .. newYear .. sep1 .. paddedMonth .. sep2).exists
then
checkedMonth = paddedMonth
end
linkPage = prefix .. newYear .. sep1 .. checkedMonth .. sep2
linkText = newYear .. sep1 .. checkedMonth .. sep2
end
result = result .. "[[" .. linkPage .. "|" .. linkText .. "]]"
if checkDateInPast(newMonth, newYear) == "OK" and not mw.title.new(linkPage).exists then
result = result .. "[[Kategorija:Pogreške u modulu Arhiva|B]]"
end
result = result .. " • "
end
return result:sub(1, -14) .. "<br>"
end
function printWeek(prefix, week, sep1, year, sep2, weekFirst)
-- Helper function to adjust week and year properly
local function adjustWeekYear(week, year, increment)
local newWeek = week + increment
local newYear = year
-- Loop to handle week adjustments when crossing year boundaries
while true do
local maxWeeks = has53Weeks(newYear) and 53 or 52
-- If weeks go beyond the current year's max weeks
if newWeek > maxWeeks then
newWeek = newWeek - maxWeeks
newYear = newYear + 1
-- If weeks go below 1
elseif newWeek < 1 then
newYear = newYear - 1
maxWeeks = has53Weeks(newYear) and 53 or 52
newWeek = newWeek + maxWeeks
else
break
end
end
return newWeek, newYear
end
local result = ""
-- Iterate through the range from -3 weeks to +3 weeks
for i = -3, 3 do
local newWeek, newYear = adjustWeekYear(week, year, i)
mw.log("week", week, year, i, "=>", newWeek, newYear)
local paddedWeek = "0" .. tostring(newWeek)
local checkedWeek = newWeek
local linkPage = ""
local linkText = ""
if weekFirst then
if
not mw.title.new(prefix .. newWeek .. sep1 .. newYear .. sep2).exists
and mw.title.new(prefix .. paddedWeek .. sep1 .. newYear .. sep2).exists
then
checkedWeek = paddedWeek
end
linkPage = prefix .. checkedWeek .. sep1 .. newYear .. sep2
linkText = checkedWeek .. sep1 .. newYear .. sep2
else
if
not mw.title.new(prefix .. newYear .. sep1 .. newWeek .. sep2).exists
and mw.title.new(prefix .. newYear .. sep1 .. paddedWeek .. sep2).exists
then
checkedWeek = paddedWeek
end
linkPage = prefix .. newYear .. sep1 .. checkedWeek .. sep2
linkText = newYear .. sep1 .. checkedWeek .. sep2
end
result = result .. "[[" .. linkPage .. "|" .. linkText .. "]]"
if checkDateInPast(newWeek, newYear) == "OK" and not mw.title.new(linkPage).exists then
result = result .. "[[Kategorija:Pogreške u modulu Arhiva|B]]"
end
result = result .. " • "
end
return result:sub(1, -14) .. "<br>"
end
function printMonthYearIncrements(prefix, month, sep1, year, sep2, monthFirst)
-- Helper function to adjust month and year properly
local function adjustMonthYear(month, year, increment)
local newMonth = month + increment
local newYear = year
-- Adjust the month and year when crossing December or January
while newMonth > 12 and tonumber(month) < 13 do
newMonth = newMonth - 12
newYear = newYear + 1
end
while newMonth < 1 and tonumber(month) < 13 do
newMonth = newMonth + 12
newYear = newYear - 1
end
return newMonth, newYear
end
local result = ""
-- Iterate through the range from -3 months to +3 months
for i = -3, 3 do
local newMonth, newYear = adjustMonthYear(month, year, i)
mw.log("MonthYear", month, year, i, "=>", newMonth, newYear)
local paddedMonth = "0" .. tostring(newMonth)
local checkedMonth = newMonth
local linkPage = ""
local linkText = ""
if monthFirst then
if
not mw.title.new(prefix .. newMonth .. sep1 .. newYear .. sep2).exists
and mw.title.new(prefix .. paddedMonth .. sep1 .. newYear .. sep2).exists
then
checkedMonth = paddedMonth
end
linkPage = prefix .. checkedMonth .. sep1 .. newYear .. sep2
linkText = checkedMonth .. sep1 .. newYear .. sep2
else
if
not mw.title.new(prefix .. newYear .. sep1 .. newMonth .. sep2).exists
and mw.title.new(prefix .. newYear .. sep1 .. paddedMonth .. sep2).exists
then
checkedMonth = paddedMonth
end
linkPage = prefix .. newYear .. sep1 .. checkedMonth .. sep2
linkText = newYear .. sep1 .. checkedMonth .. sep2
end
result = result .. "[[" .. linkPage .. "|" .. linkText .. "]]"
if checkDateInPast(newMonth, newYear) == "OK" and not mw.title.new(linkPage).exists then
result = result .. "[[Kategorija:Pogreške u modulu Arhiva|B]]"
end
result = result .. " • "
end
return result:sub(1, -14) .. "<br>"
end
function checkDateInPast(newMonth, newYear)
-- Get the current date and subtract one month
local currentTime = os.time()
local oneMonthAgo = os.time({
year = os.date("*t", currentTime).year,
month = os.date("*t", currentTime).month - 1,
day = 1, -- Start of the month ensures validity
})
-- Get the timestamp for the provided newMonth and newYear
local inputTime = os.time({
year = newYear,
month = newMonth,
day = 1, -- Ensure it's the start of the given month
})
-- Check if the input date is one month ago or earlier
if inputTime < oneMonthAgo then
return "OK"
else
return "FAIL"
end
end
-- Function to determine if a year has 53 weeks
function has53Weeks(year)
-- Determine the day of the week for January 1st (1 = Sunday, 2 = Monday, ..., 7 = Saturday)
local jan1 = os.date("*t", os.time{year = year, month = 1, day = 1}).wday
-- Check if the year is a leap year
local isLeap = (year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0))
-- A year has 53 weeks if it starts on a Thursday (jan1 == 5)
-- or if it is a leap year and starts on a Wednesday (jan1 == 4)
return jan1 == 5 or (isLeap and jan1 == 4)
end
return p