Module:HeroList
From Heroes of Might and Magic: Olden Era Official Wiki
Description
This module generates an automated table of heroes belonging to a specific faction. It dynamically retrieves localization for hero names, classes, and specializations, and formats the starting skills and spells into a clean, sortable layout.
Usage
The module is invoked via the display function:
{{#invoke:HeroList|display|faction=...|language=...}}
Parameters
| Parameter | Description | Example |
|---|---|---|
faction |
The name of the faction (as stored in the Translation table). | faction=Necropolis
|
language |
Forces the Wiki language (if omitted, it detects the page suffix). | language=fr
|
Key Features
- Dynamic Localization: Translates headers (Name, Class, etc.) and hero-specific data (Names, Skills, Spells) based on the provided language.
- Automatic Formatting:
- Displays hero portraits and icons.
- Formats specializations with tooltips showing descriptions.
- Lists starting skills and spells as link-lists with icons.
- Sorting Support: The table uses the
sortableclass, allowing users to reorder heroes based on columns. - Data Cleanup: Automatically filters out campaign, tutorial, and internal testing heroes (e.g.,
cm_fun).
Implementation Example
To display all heroes of the "Necropolis" faction:
== Necropolis Heroes ==
{{#invoke:HeroList|display|faction=Necropolis}}
Technical Notes
- The module queries the
Herotable and joins data with theTranslationtable. - It uses
sortabletables; ensure the MediaWiki "Sortable" extension is active for full functionality. - Specialization icons are automatically inferred from the
HeroSpecializationtable and formatted to match faction naming conventions.
Examples
{{#invoke:HeroList|display|faction=Necropolis}}
Aucun héros trouvé pour : Necropolis
{{#invoke:HeroList|display|faction=Grove|language=ja}}
Aucun héros trouvé pour : Grove
local p = {}
local function getTrans(target_ids, lang)
local results = {}
if #target_ids == 0 then return results end
-- Requête Cargo
local query = mw.ext.cargo.query("Translation", "target_id, language, name, description", {
where = string.format("target_id IN ('%s')", table.concat(target_ids, "','")),
})
for _, row in ipairs(query) do
if not results[row.target_id] then results[row.target_id] = {} end
results[row.target_id][row.language] = {name = row.name, desc = row.description}
end
return results
end
function p.display(frame)
local faction = frame.args.faction
local lang = frame.args.lang or mw.language.getContentLanguage():getCode()
-- Récupération des héros
local heroes = mw.ext.cargo.query("Hero", "id, name_sid, class_id, specialization_id, start_skills, start_magics", {
where = string.format("faction = '%s'", faction), orderBy = "id"
})
if not heroes or #heroes == 0 then return "Aucun héros trouvé pour : " .. faction end
-- Préparation des IDs
local ids_to_translate = {}
for _, h in ipairs(heroes) do
table.insert(ids_to_translate, h.name_sid)
table.insert(ids_to_translate, h.specialization_id)
if h.start_skills then
for skill in string.gmatch(h.start_skills, "([^,]+)") do
table.insert(ids_to_translate, skill .. "_name")
end
end
end
local trans = getTrans(ids_to_translate, lang)
local html = {'{| class="wikitable sortable"', '! Portrait !! Nom !! Classe !! Icône !! Spécialisation !! Compétences'}
for _, h in ipairs(heroes) do
-- DEBUG : On récupère les traductions avec un garde-fou
local name_en = (trans[h.name_sid] and trans[h.name_sid]['en']) and trans[h.name_sid]['en'].name or ("ERR_NAME_" .. h.name_sid)
local name_loc = (trans[h.name_sid] and trans[h.name_sid][lang]) and trans[h.name_sid][lang].name or name_en
table.insert(html, "|-")
table.insert(html, string.format('| [[File:%s.png|70px]]', name_en))
table.insert(html, string.format('| [[%s|%s]]', name_en, name_loc))
table.insert(html, string.format('| %s', h.class_id))
table.insert(html, string.format('| [[File:%s Specialization Icon.png|64px]]', h.id))
local spec_name = (trans[h.specialization_id] and trans[h.specialization_id][lang]) and trans[h.specialization_id][lang].name or ("ERR_SPEC_" .. h.specialization_id)
table.insert(html, string.format('| %s', spec_name))
-- ... suite du code
end
return table.concat(html, "\n") .. "|}"
end
return p


