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
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 = {}
local pictures_next = mw.loadData("Module:POTD/" .. current_year + 1)▼
local function tryLoad(m)
return mw.loadData(m)
for first_year = 0, -10, -1 do
current_year = current_year + first_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
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 =
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]
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_next.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_next.footer[daymonth] or '')
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_curr.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_curr.footer[daymonth] or '')▼
buildgallery = buildgallery .. '\n' .. 'File:' .. pictures_prev.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures_prev.footer[daymonth] or '')▼
else
buildgallery = buildgallery .. '\n' .. 'File:Empty set.svg' .. '|' .. daymonth▼
▲ buildgallery = buildgallery .. '\n' .. 'File:' ..
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:' ..
else
buildgallery = buildgallery .. '\n' .. 'File:Empty set.svg' .. '|' .. daymonth
Linha 65 ⟶ 103:
daymonth = option
end
while not filename do
absolutetime = absolutetime - 86400 -- previous day
daymonth = os.date("%d/%m", absolutetime)
▲ end
▲ local filename = pictures_curr.file[daymonth]
▲ local description = pictures_curr.footer[daymonth] or ''
▲ if filename == nil then
▲ description = pictures_prev.footer[daymonth]
▲ if filename == nil then
▲ filename = pictures_ant.file[daymonth]
▲ description = pictures_ant.footer[daymonth]
▲ end
end
|