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}}
| Portrait | ID Technique | Nom | Classe | Spécialisation |
|---|---|---|---|---|
| campaign_hero_4 | Lord Galthran | might_undead | campaign_hero_4_specialization | |
| File:Undead General.png | campaign_M3_hero_undead | Undead General | might_undead | necro_hero_8_specialization |
| campaign_M5_hero_undead_1 | Lord Galthran | might_undead | campaign_hero_4_specialization | |
| campaign_M5_hero_undead_2 | Thant | magic_undead | necro_hero_16_specialization | |
| campaign_M5_hero_undead_2alt | Thant | magic_undead | necro_hero_16_specialization | |
| campaign_M9_hero_necromancer_ambush | Necromancer | magic_undead | necro_hero_16_specialization | |
| campaign_M9_hero_undead_1 | Marl | might_undead | necro_hero_7_specialization | |
| campaign_M9_hero_undead_2 | Milossa the Golden | magic_undead | necro_hero_18_specialization | |
| campaign_M9_hero_undead_3 | Bulwark | might_undead | necro_hero_1_specialization | |
| campaign_M9_hero_undead_4 | Funerella | magic_undead | necro_hero_17_specialization | |
| campaign_M9_hero_undead_main | Lord Galthran | might_undead | campaign_hero_4_specialization | |
| campaign_M9_hero_undead_npc | Thant | magic_undead | necro_hero_16_specialization | |
| cm_fun_hero_1 | Funerella | magic_undead | necro_hero_17_specialization | |
| necro_hero_1 | Bulwark | might_undead | necro_hero_1_specialization | |
| necro_hero_10 | Mag | magic_undead | necro_hero_10_specialization | |
| necro_hero_11 | Adahn | magic_undead | necro_hero_11_specialization | |
| necro_hero_12 | Ethric | magic_undead | necro_hero_12_specialization | |
| necro_hero_13 | Guildmaster Klastor | magic_undead | necro_hero_13_specialization | |
| necro_hero_14 | Shadespinner Oona | magic_undead | necro_hero_14_specialization | |
| necro_hero_15 | Laura | magic_undead | necro_hero_15_specialization | |
| necro_hero_16 | Lord Rufus | magic_undead | necro_hero_16_specialization | |
| necro_hero_17 | Funerella | magic_undead | necro_hero_17_specialization | |
| necro_hero_18 | Milossa the Golden | magic_undead | necro_hero_18_specialization | |
| necro_hero_2 | King-of-Kings | might_undead | necro_hero_2_specialization | |
| necro_hero_3 | Onkos | might_undead | necro_hero_3_specialization | |
| necro_hero_4 | Kel'Ghul | might_undead | necro_hero_4_specialization | |
| necro_hero_5 | Natalida | might_undead | necro_hero_5_specialization | |
| necro_hero_6 | Artorius Veritas | might_undead | necro_hero_6_specialization | |
| necro_hero_7 | Marl | might_undead | necro_hero_7_specialization | |
| necro_hero_8 | Tarius | might_undead | necro_hero_8_specialization | |
| necro_hero_9 | Zam | might_undead | necro_hero_9_specialization | |
| tutorial_hero_4 | King-of-Kings | might_undead | necro_hero_2_specialization | |
| tutorial_hero_c1_12 | Tarius | might_undead | necro_hero_8_specialization | |
| tutorial_hero_c1_14 | Tarius | might_undead | necro_hero_8_specialization | |
| tutorial_M_hero_1 | Onkos | might_undead | necro_hero_3_specialization | |
| tutorial_M_hero_2 | Tarius | might_undead | necro_hero_8_specialization |
{{#invoke:HeroList|display|faction=Grove|language=ja}}
| Portrait | ID Technique | Nom | Classe | Spécialisation |
|---|---|---|---|---|
| campaign_hero_2 | ラフィア | magic_nature | campaign_hero_2_specialization | |
| File:???.png | campaign_M2_hero_sylvan | ??? | magic_nature | campaign_hero_2_specialization |
| campaign_M4_hero_sylvan_1 | 巡礼の老人 | might_nature | nature_hero_4_specialization | |
| File:Faun Captain.png | campaign_M4_hero_sylvan_2 | フォーンの隊長 | might_nature | nature_hero_3_specialization |
| File:Campaign M4 hero sylvan 2 alt.png | campaign_M4_hero_sylvan_2_alt | campaign_M4_hero_sylvan_2_alt | might_nature | nature_hero_3_specialization |
| File:Faun Captain.png | campaign_M4_hero_sylvan_3 | フォーンの隊長 | magic_nature | nature_hero_12_specialization |
| File:Campaign M4 hero sylvan 3 alt.png | campaign_M4_hero_sylvan_3_alt | campaign_M4_hero_sylvan_3_alt | might_nature | nature_hero_11_specialization |
| nature_hero_1 | イース | might_nature | nature_hero_1_specialization | |
| nature_hero_10 | ヴァトウナ | magic_nature | nature_hero_10_specialization | |
| nature_hero_11 | 老ツ=キッシュ | magic_nature | nature_hero_11_specialization | |
| nature_hero_12 | エアリニエル | magic_nature | nature_hero_12_specialization | |
| nature_hero_13 | グレイシア | magic_nature | nature_hero_13_specialization | |
| nature_hero_14 | ヴィム | magic_nature | nature_hero_14_specialization | |
| nature_hero_15 | ハロン | magic_nature | nature_hero_15_specialization | |
| nature_hero_16 | エコリリー | magic_nature | nature_hero_16_specialization | |
| nature_hero_17 | サリー | magic_nature | nature_hero_17_specialization | |
| nature_hero_18 | 吟遊詩人 | magic_nature | nature_hero_18_specialization | |
| nature_hero_2 | 槍頭のゴレル | might_nature | nature_hero_2_specialization | |
| nature_hero_3 | ジンジャーテール | might_nature | nature_hero_3_specialization | |
| nature_hero_4 | 巡礼の老人 | might_nature | nature_hero_4_specialization | |
| nature_hero_5 | オクタヴィア | might_nature | nature_hero_5_specialization | |
| nature_hero_6 | ニャオワ | might_nature | nature_hero_6_specialization | |
| nature_hero_7 | ファレオール | might_nature | nature_hero_7_specialization | |
| nature_hero_8 | 魅惑のシャー | might_nature | nature_hero_8_specialization | |
| nature_hero_9 | ダリアおばさん | might_nature | nature_hero_9_specialization |
local p = {}
-- Fonction utilitaire pour récupérer une traduction via Cargo
local function getTrans(target_id, lang, type)
if not target_id or target_id == "" then return nil end
local query = mw.ext.cargo.query("Translation", "name", {
where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, type),
limit = 1
})
-- Fallback sur l'anglais si rien trouvé
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].name or nil
end
function p.display(frame)
local raw_faction = frame.args.faction
local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
-- 1. Récupération dynamique de l'ID de faction
local faction_query = mw.ext.cargo.query("Translation", "target_id", {
where = string.format("name = '%s' AND type = 'faction'", raw_faction),
limit = 1
})
local faction_id = (faction_query and #faction_query > 0) and faction_query[1].target_id or raw_faction
-- 2. Récupération des héros
local heroes = mw.ext.cargo.query("Hero", "id, name_sid, class_id, specialization_id", {
where = string.format("faction = '%s'", faction_id),
orderBy = "id"
})
-- 3. Construction du tableau
local html = {'{| class="wikitable sortable"', '! Portrait !! ID Technique !! Nom !! Classe !! Spécialisation'}
for _, h in ipairs(heroes) do
local name = getTrans(h.name_sid, lang, 'hero') or h.name_sid
local file_name = getTrans(h.name_sid, 'en', 'hero') or h.id
local class_name = getTrans(h.class_id, lang, 'class') or h.class_id
local spec_name = getTrans(h.specialization_id, lang, 'specialization') or h.specialization_id
table.insert(html, "|-")
table.insert(html, string.format('| [[File:%s.png|70px]]', file_name))
table.insert(html, "| " .. h.id)
table.insert(html, string.format('| [[%s|%s]]', file_name, name))
table.insert(html, "| " .. class_name)
table.insert(html, "| " .. spec_name)
end
-- Fermeture unique du tableau
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


