Module:Liste2 : Différence entre versions
Ligne 25 : | Ligne 25 : | ||
end | end | ||
− | local tbl | + | local tbl = {} |
for _, row in ipairs(result) do | for _, row in ipairs(result) do | ||
row['annee'] = tonumber(row['annee']) | row['annee'] = tonumber(row['annee']) | ||
Ligne 40 : | Ligne 40 : | ||
for _,row in ipairs(result) do | for _,row in ipairs(result) do | ||
+ | if not tbl[1] then | ||
+ | retour = retour .. texte_periode .. d..'-'..f .. '\n\n' | ||
+ | end | ||
if row['annee'] > d and row['annee'] < f then | if row['annee'] > d and row['annee'] < f then | ||
− | + | tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row } | |
− | + | elseif f < fin then | |
− | |||
− | |||
− | |||
retour = retour .. table.concat(tbl,args.delimiter or '') | retour = retour .. table.concat(tbl,args.delimiter or '') | ||
− | |||
d,f,msg,tbl = f,f+periode,1,{} | d,f,msg,tbl = f,f+periode,1,{} | ||
else | else | ||
+ | retour = retour .. table.concat(tbl,args.delimiter or '') | ||
d,f,msg,tbl = f,f+100,1,{} | d,f,msg,tbl = f,f+100,1,{} | ||
end | end | ||
+ | |||
+ | |||
end | end |
Version du 11 décembre 2018 à 18:49
La documentation pour ce module peut être créée à Module:Liste2/doc
local p = {} function p.main(frame) if frame == mw.getCurrentFrame() then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame() end local query = {} for k, v in pairs(args) do if string.sub(k, 0, 2) == 'q?' then query[string.sub(k, 3)] = v end end supports={} local result = mw.ext.cargo.query('Supports','idSupport,video',{groupBy = 'idSupport',limit=3000}) for d, row in ipairs(result) do supports[row['idSupport']] = row['video'] end result = mw.ext.cargo.query(query.tables, query.fields, query) if not next(result) then return frame:preprocess(args.default or '') end local tbl = {} for _, row in ipairs(result) do row['annee'] = tonumber(row['annee']) if row['video'] == '' then if supports[row['idSupport']] then row['video']=supports[row['idSupport']] end end end local debut, fin = 1900, 1980 local periode, nperiode = 10, 0 local d,f = debut-100,debut+periode local texte_periode = '\n Texte période' local retour, msg = '', 1 for _,row in ipairs(result) do if not tbl[1] then retour = retour .. texte_periode .. d..'-'..f .. '\n\n' end if row['annee'] > d and row['annee'] < f then tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row } elseif f < fin then retour = retour .. table.concat(tbl,args.delimiter or '') d,f,msg,tbl = f,f+periode,1,{} else retour = retour .. table.concat(tbl,args.delimiter or '') d,f,msg,tbl = f,f+100,1,{} end end local intro = frame:preprocess(args.intro or '') local outro = frame:preprocess(args.outro or '') return intro .. retour .. outro end return p