Mòdul:POTD: diferència entre les revisions
Contingut suprimit Contingut afegit
amplio a dos anys anteriors si no n'hi ha cap en l'actual |
Intent d'arreglar el missatge d'error de la portada Etiqueta: Revertida |
||
Línia 7: | Línia 7: | ||
local pictures_prev = mw.loadData("Module:POTD/" .. current_year - 1) |
local pictures_prev = mw.loadData("Module:POTD/" .. current_year - 1) |
||
local pictures_ant = mw.loadData("Module:POTD/" .. current_year - 2) |
local pictures_ant = mw.loadData("Module:POTD/" .. current_year - 2) |
||
local pictures_next = mw.loadData(" |
local pictures_next = mw.loadData("Mòdul:POTD/" .. current_year + 1) |
||
-- Building a gallery for requested number of pictures -- |
-- Building a gallery for requested number of pictures -- |
Revisió del 02:45, 1 gen 2021
Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Aquest mòdul dóna suport a la selecció de la imatge del dia (POTD, sigles en anglès) mostrada en portada entre les imatges prèviament proposades. Vegeu {{FotoDelDia}} per a les instruccions d'ús.
La llista d'imatges proposades és a Mòdul:POTD/2024 per a l'any actual, o bé al mòdul de l'any que s'indiqui amb la funció "archive". Si en un dia determinat no hi ha imatge proposada, el mòdul mostra la primera imatge del mateix dia que troba cercant successivament els cinc anys anteriors. Vegeu els criteris a Viquipèdia:Imatge del dia.
local p = {}
-- Loading the pictures module --
local absolutetime = os.time() -- now
local current_year = os.date("%Y", absolutetime)
local pictures_curr = mw.loadData("Module:POTD/" .. current_year)
local pictures_prev = mw.loadData("Module:POTD/" .. current_year - 1)
local pictures_ant = mw.loadData("Module:POTD/" .. current_year - 2)
local pictures_next = mw.loadData("Mòdul:POTD/" .. current_year + 1)
-- Building a gallery for requested number of pictures --
local function gallerator(scope)
local buildgallery = ""
local range = 0
local iter = 1
if scope == "all" then
range = 365
elseif tonumber(scope) then
range = tonumber(scope)
iter = range < 0 and -1 or 1
end
absolutetime = os.time() -- now
local daymonth = ""
for days = iter, range, iter do
absolutetime = absolutetime + (86400 * iter) -- one day
daymonth = os.date( "%d/%m" , absolutetime )
if os.date("%Y", absolutetime) > current_year then
if 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
buildgallery = buildgallery .. '\n' .. 'File:Empty set.svg' .. '|' .. daymonth
end
else
if 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 '')
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
end
end
end
return buildgallery
end
-- Matching pictures with day of year --
function p.todayspics(frame)
local args = frame:getParent().args
local option = args[1] or ""
-- Which date is today? --
local daymonth = os.date("%d/%m", absolutetime)
-- Which picture and description should we use today? --
if option:find("%d%d/%d%d") then
daymonth = option
end
while not pictures_curr.file[daymonth] and not pictures_prev.file[daymonth] and not pictures_ant.file[daymonth] 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 ''
--- 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
-- Any template in footer? Expand it
if string.match(description, '%b{}') then
description = frame:preprocess(description)
end
-- Which output is desired, text or description? --
local show = ""
if option == "filename" then
show = filename
elseif option == "description" then
show = description
else
show = '[[File:' .. filename .. '|350x350px]]<br />' .. description
end
-- Which pictures should we display in addition of today's? --
local gallery = ""
if option == "all" or tonumber(option) then
gallery = frame:extensionTag{name = 'gallery', content = gallerator(option), args = {mode='packed-hover', heights='150px'}}
end
return show .. gallery
end
-- Generates an archive of a year. Use it {{subst:#invoke:POTD|archive|<YYYY>}}
function p.archive(frame)
local year = frame.args[1]
if mw.title.new("Module:POTD/" .. year).exists then
local pictures = mw.loadData("Module:POTD/" .. year)
local buildgallery = {}
local absolutetime = os.time({year=year, month=1, day=1})
for iter = 0, 365 do
day = absolutetime + (86400 * iter)
daymonth = os.date("%d/%m", day)
if pictures.file[daymonth] ~= nil then
table.insert(buildgallery, 'File:' .. pictures.file[daymonth] .. '|' .. daymonth .. ': ' .. (pictures.footer[daymonth] or ''))
end
end
return frame:extensionTag{name = 'gallery', content = table.concat(buildgallery, '\n'), args = {mode='packed', heights='150px'}}
end
return
end
return p