« Module:Liste » : différence entre les versions
De Nefald
Autres actions
Page créée avec « local p = {} function p.main(frame) local args = frame:getParent().args -- Paramètres local categorie = args.categorie or args[1] or '' local colonnes = tonumber(args.colonnes) or 3 local ordre = args.ordre or 'alpha' -- alpha, récent, taille local format = args.format or 'liste' -- liste, tableau, cartes local afficherDescription = args.description or 'oui' local afficherImage = args.image or 'non' if categorie ==... » |
mAucun résumé des modifications |
||
| Ligne 22 : | Ligne 22 : | ||
end | end | ||
-- Récupérer les pages de la catégorie | -- Récupérer les pages de la catégorie directement | ||
local | local pages = {} | ||
-- Méthode 1 : Via mw.site.stats (simple mais limité) | |||
for _, page in ipairs(catTitle:getContent() and {} or {}) do | |||
-- Cette méthode ne fonctionne pas directement | |||
end | |||
-- Méthode 2 : Construire la requête DPL comme string | |||
local dplQuery = '<dpl>\n' | |||
dplQuery = dplQuery .. 'category=' .. categorie .. '\n' | |||
dplQuery = dplQuery .. 'namespace=\n' | |||
if ordre == 'récent' then | if ordre == 'récent' then | ||
dplQuery = dplQuery .. 'ordermethod=lastedit\n' | |||
dplQuery = dplQuery .. 'order=descending\n' | |||
elseif ordre == 'taille' then | elseif ordre == 'taille' then | ||
dplQuery = dplQuery .. 'ordermethod=size\n' | |||
dplQuery = dplQuery .. 'order=descending\n' | |||
else | |||
dplQuery = dplQuery .. 'ordermethod=title\n' | |||
end | end | ||
dplQuery = dplQuery .. 'mode=userformat\n' | |||
dplQuery = dplQuery .. 'listseparators=@@START@@,@@PAGE@@,@@END@@\n' | |||
dplQuery = dplQuery .. 'format=,%PAGE%,\n' | |||
dplQuery = dplQuery .. '</dpl>' | |||
-- Parser le | -- Parser le DPL | ||
local pages | local dplResult = frame:preprocess(dplQuery) | ||
-- Extraire les pages | |||
for page in dplResult:gmatch('@@PAGE@@([^@]+)') do | for page in dplResult:gmatch('@@PAGE@@([^@]+)') do | ||
page = mw.text.trim(page) | |||
if page ~= '' then | if page ~= '' then | ||
table.insert(pages, | table.insert(pages, page) | ||
end | end | ||
end | end | ||
| Ligne 76 : | Ligne 85 : | ||
if afficherDescription == 'oui' then | if afficherDescription == 'oui' then | ||
local desc = frame: | local desc = frame:expandTemplate{ | ||
if desc and desc ~= '' and desc | title = 'Invoke:PageInfo', | ||
args = {'getDescription', page} | |||
} | |||
if desc and desc ~= '' and not desc:match("Aucune description") then | |||
table.insert(result, "<br/><small>" .. desc .. "</small>") | table.insert(result, "<br/><small>" .. desc .. "</small>") | ||
end | end | ||
| Ligne 109 : | Ligne 121 : | ||
if afficherImage == 'oui' then | if afficherImage == 'oui' then | ||
local image = frame: | local image = frame:expandTemplate{ | ||
if image and image ~= '' and image | title = 'Invoke:PageInfo', | ||
args = {'getMainImage', page} | |||
} | |||
if image and image ~= '' and not image:match("Aucune image") then | |||
table.insert(cells, '| [[Fichier:' .. image .. '|100px]]') | table.insert(cells, '| [[Fichier:' .. image .. '|100px]]') | ||
else | else | ||
| Ligne 118 : | Ligne 133 : | ||
if afficherDescription == 'oui' then | if afficherDescription == 'oui' then | ||
local desc = frame: | local desc = frame:expandTemplate{ | ||
if desc and desc ~= '' and desc | title = 'Invoke:PageInfo', | ||
args = {'getDescription', page} | |||
} | |||
if desc and desc ~= '' and not desc:match("Aucune description") then | |||
table.insert(cells, '| ' .. desc) | table.insert(cells, '| ' .. desc) | ||
else | else | ||
| Ligne 137 : | Ligne 155 : | ||
function p.formatCartes(frame, pages, colonnes, afficherDescription, afficherImage) | function p.formatCartes(frame, pages, colonnes, afficherDescription, afficherImage) | ||
local result = {} | local result = {} | ||
local pageInfo = require('Module:PageInfo') | |||
-- CSS inline pour les cartes | -- CSS inline pour les cartes | ||
| Ligne 142 : | Ligne 161 : | ||
for _, page in ipairs(pages) do | for _, page in ipairs(pages) do | ||
table.insert(result, '<div style="border: 1px solid #ddd; border-radius: 8px; padding: 1em; background: #f9f9f9 | table.insert(result, '<div style="border: 1px solid #ddd; border-radius: 8px; padding: 1em; background: #f9f9f9;">') | ||
-- Image si demandée | -- Image si demandée | ||
if afficherImage == 'oui' then | if afficherImage == 'oui' then | ||
local | local imageFrame = frame:newChild{ | ||
if image and image ~= '' and image | title = 'temp', | ||
args = {page} | |||
} | |||
local image = pageInfo.getMainImage(imageFrame) | |||
if image and image ~= '' and not image:match("Aucune image") then | |||
table.insert(result, '<div style="text-align: center; margin-bottom: 0.5em;">[[Fichier:' .. image .. '|150px]]</div>') | table.insert(result, '<div style="text-align: center; margin-bottom: 0.5em;">[[Fichier:' .. image .. '|150px]]</div>') | ||
end | end | ||
| Ligne 157 : | Ligne 180 : | ||
-- Description si demandée | -- Description si demandée | ||
if afficherDescription == 'oui' then | if afficherDescription == 'oui' then | ||
local | local descFrame = frame:newChild{ | ||
if desc and desc ~= '' and desc | title = 'temp', | ||
args = {page} | |||
} | |||
local desc = pageInfo.getDescription(descFrame) | |||
if desc and desc ~= '' and not desc:match("Aucune description") then | |||
table.insert(result, '<div style="color: #666; font-size: 0.9em;">' .. desc .. '</div>') | table.insert(result, '<div style="color: #666; font-size: 0.9em;">' .. desc .. '</div>') | ||
end | end | ||