Mòdul:POTD: diferència entre les revisions

Contingut suprimit Contingut afegit
Es desfà la revisió 25861933 de FranSisPac (Discussió) per la sospita que el problema que s'intentava resoldre no s'origina en la denominació de l'espai de noms
Etiqueta: Desfés
protecció en la càrrega de submòduls
 
Línia 1:
local p = {}
 
-- Loading themodules of pictures moduleby --year
local absolutetime = os.time() -- now
local current_year = os.date("%Y", absolutetime)
 
local pictures_curr = mw.loadData("Module:POTD/" .. current_year)
local exist
local pictures_prev = mw.loadData("Module:POTD/" .. current_year - 1)
local pictures = {}
local pictures_ant = mw.loadData("Module:POTD/" .. current_year - 2)
 
local pictures_next = mw.loadData("Module:POTD/" .. current_year + 1)
local function tryLoad(m)
return mw.loadData(m)
end
 
for first_year = 0, -10, -1 do
current_year = current_year + first_year
local exist, pictures_currpictures["0"] = mw.loadDatapcall(tryLoad, "Module:POTD/" .. current_year)
if exist then
for prev_year = -1, -5, -1 do
exist, pictures[tostring(prev_year)] = pcall(tryLoad, "Module:POTD/" .. current_year + prev_year)
if not exist then
break
end
end
break
end
end
 
local function getFile(daymonth)
local filename, description
for years = 0, -5, -1 do
local picts = pictures[tostring(years)]
if picts then
if pictures_currpicts.file[daymonth] ~= nil then
filename = pictures_antpicts.file[daymonth]
local description = pictures_currpicts.footer[daymonth] or ''
break
end
else
return
end
end
return filename, description
end
 
-- Building a gallery for requested number of pictures --
Linha 22 ⟶ 56:
absolutetime = os.time() -- now
current_year = os.date("%Y", absolutetime)
local daymonth = ""
local exist, pictures_next = mw.loadDatapcall(tryLoad, "Module:POTD/" .. current_yearos.date("%Y", absolutetime) + 1)
if filenamenot == nilexist then
pictures_next = {}
end
local filename, description
for days = iter, range, iter do
Linha 28 ⟶ 68:
daymonth = os.date( "%d/%m" , absolutetime )
if os.date("%Y", absolutetime) > current_year then
if pictures_next.file and pictures_next.file[daymonth] ~= nil then
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_next.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_next.footer[daymonth] or '')
elseif pictures_curr.file[daymonth] ~= nil then
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_curr.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_curr.footer[daymonth] or '')
elseif pictures_prev.file[daymonth] ~= nil then
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_prev.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_prev.footer[daymonth] or '')
else
filename, description = pictures_prev.footer[getFile(daymonth])
buildgallery = buildgallery .. '\n' .. 'File:Empty set.svg' .. '|' .. daymonth
if filename == nil then
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_prev.file[daymonth]filename .. '|' .. daymonth .. ': ' .. (pictures_prev.footer[daymonth] or '')description
else
buildgallery = buildgallery .. '\n' .. 'File:Empty set.svg' .. '|' .. daymonth
end
end
else
filename, description = getFile(daymonth)
if pictures_curr.file[daymonth] ~= nil then
if filename then
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_curr.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_curr.footer[daymonth] or '')
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_curr.file[daymonth]filename .. '|' .. daymonth .. ': ' .. (pictures_curr.footer[daymonth] or '')description
elseif pictures_prev.file[daymonth] ~= nil then
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_prev.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_prev.footer[daymonth] or '')
elseif pictures_ant.file[daymonth] ~= nil then
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_ant.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_ant.footer[daymonth] or '')
else
buildgallery = buildgallery .. '\n' .. 'File:Empty set.svg' .. '|' .. daymonth
Linha 65 ⟶ 103:
daymonth = option
end
while not pictures_curr.file[daymonth] and not pictures_prev.file[daymonth] and not pictures_ant.file[daymonth] do
local filename, description = pictures_curr.file[getFile(daymonth])
while not filename do
absolutetime = absolutetime - 86400 -- previous day
daymonth = os.date("%d/%m", absolutetime)
filename, description = pictures_ant.footer[getFile(daymonth])
end
local filename = pictures_curr.file[daymonth]
local description = pictures_curr.footer[daymonth] or ''
--- Take file from previous year if needed
if filename == nil then
filename = pictures_prev.file[daymonth]
description = pictures_prev.footer[daymonth]
if filename == nil then
filename = pictures_ant.file[daymonth]
description = pictures_ant.footer[daymonth]
end
end