Module:ClassNav: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
Created page with "local p = {} -- Fonction utilitaire pour récupérer une traduction local function getTrans(target_id, lang, type, field) field = field or "name" if not target_id or target_id == "" then return nil end local query = mw.ext.cargo.query("Translation", field, { where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, type), limit = 1 }) if not query or #query == 0 then query = mw.ext.cargo.qu..." |
No edit summary |
||
| Line 25: | Line 25: | ||
table.insert(html, '! colspan=10 style="text-align:center; letter-spacing:.3px;"| ' .. (getTrans("wiki_classes", lang, "ui") or "Classes")) | table.insert(html, '! colspan=10 style="text-align:center; letter-spacing:.3px;"| ' .. (getTrans("wiki_classes", lang, "ui") or "Classes")) | ||
-- Fonction | -- Fonction pour créer les lignes | ||
local function addRow(category_id, | local function addRow(category_id, class_type) | ||
table.insert(html, "|-") | table.insert(html, "|-") | ||
table.insert(html, "! style='width:8em;'| " .. (getTrans(category_id, lang, "ui") or category_id)) | table.insert(html, "! style='width:8em;'| " .. (getTrans(category_id, lang, "ui") or category_id)) | ||
-- Requête | -- Requête corrigée avec 'class_type' | ||
local classes = mw.ext.cargo.query("HeroClass", "id", {where = " | local classes = mw.ext.cargo.query("HeroClass", "id", {where = "class_type = '" .. class_type .. "'"}) | ||
for _, c in ipairs(classes) do | for _, c in ipairs(classes) do | ||
local name = getTrans(c.id, lang, "hero_class") or c.id | local name = getTrans(c.id, lang, "hero_class") or c.id | ||
| Line 39: | Line 39: | ||
end | end | ||
-- Appel avec les bonnes valeurs (might ou magic) | |||
addRow("might_heroes", "might") | addRow("might_heroes", "might") | ||
addRow("magic_heroes", "magic") | addRow("magic_heroes", "magic") | ||
Revision as of 09:37, 31 May 2026
Documentation for this module may be created at Module:ClassNav/doc
local p = {}
-- Fonction utilitaire pour récupérer une traduction
local function getTrans(target_id, lang, type, field)
field = field or "name"
if not target_id or target_id == "" then return nil end
local query = mw.ext.cargo.query("Translation", field, {
where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, type),
limit = 1
})
if not query or #query == 0 then
query = mw.ext.cargo.query("Translation", "name", {
where = string.format("target_id = '%s' AND language = 'en' AND type = '%s'", target_id, type),
limit = 1
})
end
return (query and #query > 0) and query[1][field] or nil
end
function p.render(frame)
local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
local html = {'{| class="wikitable" style="width:100%; text-align:left;"'}
-- Titre
table.insert(html, '! colspan=10 style="text-align:center; letter-spacing:.3px;"| ' .. (getTrans("wiki_classes", lang, "ui") or "Classes"))
-- Fonction pour créer les lignes
local function addRow(category_id, class_type)
table.insert(html, "|-")
table.insert(html, "! style='width:8em;'| " .. (getTrans(category_id, lang, "ui") or category_id))
-- Requête corrigée avec 'class_type'
local classes = mw.ext.cargo.query("HeroClass", "id", {where = "class_type = '" .. class_type .. "'"})
for _, c in ipairs(classes) do
local name = getTrans(c.id, lang, "hero_class") or c.id
table.insert(html, string.format('| style="display:inline-block; border:0px;"| [[File:%s.png|30px|link=%s/%s]] [[%s/%s|%s]]',
c.id, c.id, lang, c.id, lang, name))
end
end
-- Appel avec les bonnes valeurs (might ou magic)
addRow("might_heroes", "might")
addRow("magic_heroes", "magic")
table.insert(html, "|-")
table.insert(html, '| colspan=10 style="text-align: center;"| [[Heroes/' .. lang .. '|' .. (getTrans("all_heroes", lang, "ui") or "Tous les Héros") .. ']]')
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


