Aller au contenu

« Module:Ligne apparition » : différence entre les versions

De Stargate Wiki Sémantique
Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
 
(10 versions intermédiaires par le même utilisateur non affichées)
Ligne 4 : Ligne 4 :


----------------------------------------------------------------------
----------------------------------------------------------------------
-- 1) Nettoyage UTF‑8 (anti-crash)
-- Nettoyage UTF‑8
----------------------------------------------------------------------
----------------------------------------------------------------------
local function safe_utf8(str)
local function safe_utf8(str)
if type(str) ~= "string" then
if type(str) ~= "string" then return "" end
return ""
end
return mw.ustring.gsub(str, "[^\0-\x7F\xC2-\xF4][\x80-\xBF]*", " ")
return mw.ustring.gsub(str, "[^\0-\x7F\xC2-\xF4][\x80-\xBF]*", " ")
end
end


----------------------------------------------------------------------
----------------------------------------------------------------------
-- 2) Normalisation avancée
-- Normalisation
----------------------------------------------------------------------
----------------------------------------------------------------------
local function normalize(str)
local function normalize(str)
Ligne 28 : Ligne 26 :


----------------------------------------------------------------------
----------------------------------------------------------------------
-- Types d’apparition → propriété SMW
-- 3) Table des types (Type d'apparition)
----------------------------------------------------------------------
----------------------------------------------------------------------
local types = {
local types = {
-- Main character
main = "Personnage principal de ",
main = "Personnage principal de ",
["main character"] = "Personnage principal de ",
m = "Personnage principal de ",
m = "Personnage principal de ",
ma = "Personnage principal de ",
p = "Personnage principal de ",
principal = "Personnage principal de ",
principal = "Personnage principal de ",
["personnage principal"] = "Personnage principal de ",


-- Supporting character
supporting = "Personnage secondaire de ",
supporting = "Personnage secondaire de ",
["supporting character"] = "Personnage secondaire de ",
s = "Personnage secondaire de ",
s = "Personnage secondaire de ",
su = "Personnage secondaire de ",
se = "Personnage secondaire de ",
secondaire = "Personnage secondaire de ",
secondaire = "Personnage secondaire de ",
ps = "Personnage secondaire de ",
["personnage secondaire"] = "Personnage secondaire de ",


-- Recurring character
recurring = "Personnage récurrent de ",
recurring = "Personnage récurrent de ",
["recurring character"] = "Personnage récurrent de ",
re = "Personnage récurrent de ",
re = "Personnage récurrent de ",
["récurrent"] = "Personnage récurrent de ",
["personnage récurrent"] = "Personnage récurrent de ",


-- One shot character
["one shot"] = "Personnage one shot de ",
["one shot"] = "Personnage one shot de ",
["one-shot"] = "Personnage one shot de ",
["one shot character"] = "Personnage one shot de ",
guest = "Personnage one shot de ",
os = "Personnage one shot de ",
os = "Personnage one shot de ",
g = "Personnage one shot de ",
["personnage one shot"] = "Personnage one shot de ",


-- Minor character
minor = "Personnage mineur de ",
minor = "Personnage mineur de ",
["minor character"] = "Personnage mineur de ",
mi = "Personnage mineur de ",
mi = "Personnage mineur de ",
["personnage mineur"] = "Personnage mineur de ",
mineur = "Personnage mineur de ",


-- Présence générique
yes = "Apparaît dans ",
yes = "Apparaît dans ",
['true'] = "Apparaît dans ",
["#default"] = "Apparaît dans ",
y = "Apparaît dans ",
y = "Apparaît dans ",
t = "Apparaît dans ",
o = "Apparaît dans ",
oui = "Apparaît dans ",
v = "Apparaît dans ",
vrai = "Apparaît dans ",
vrai = "Apparaît dans ",


-- Mention
mention = "Mentionné dans ",
mention = "Mentionné dans ",
mentioned = "Mentionné dans ",
me = "Mentionné dans ",
me = "Mentionné dans ",
men = "Mentionné dans ",
["mentionné"] = "Mentionné dans ",


-- Visual presence only
picture = "Photo seule dans ",
picture = "Photo seule dans ",
photo = "Photo seule dans ",
photo = "Photo seule dans ",
["photo seule"] = "Photo seule dans ",


-- Vocal presence only
voice = "Voix seule dans ",
voice = "Voix seule dans ",
voix = "Voix seule dans ",
voix = "Voix seule dans ",


-- Corpse
body = "Corps visible dans ",
body = "Corps visible dans ",
corpse = "Corps visible dans ",
corps = "Corps visible dans ",
corps = "Corps visible dans ",
cadavre = "Corps visible dans ",


deleted = "Apparaît uniquement dans les scènes supprimées de ",
-- Deleted scenes only
["deleted scenes"] = "Apparaît uniquement dans les scènes supprimées de ",
del = "Apparaît uniquement dans les scènes supprimées de ",
sup = "Apparaît uniquement dans les scènes supprimées de ",
supp = "Apparaît uniquement dans les scènes supprimées de ",
["scène supprimée"] = "Apparaît uniquement dans les scènes supprimées de ",
["scènes supprimées"] = "Apparaît uniquement dans les scènes supprimées de ",

-- Flashback only
flash = "Apparaît uniquement dans des flashbacks de ",
flashback = "Apparaît uniquement dans des flashbacks de ",
flashback = "Apparaît uniquement dans des flashbacks de ",
flashbacks = "Apparaît uniquement dans des flashbacks de ",


-- Name visible only
name = "Nom visible dans ",
nom = "Nom visible dans ",
nom = "Nom visible dans ",

["#default"] = "Apparaît dans "
}
}


Ligne 130 : Ligne 76 :


----------------------------------------------------------------------
----------------------------------------------------------------------
-- 4) Alias → catégories (Marquage type d'apparition)
-- Alias → catégories
----------------------------------------------------------------------
----------------------------------------------------------------------
local alias = {
local alias = {
m="principal", main="principal", principal="principal",
-- Principal
["m"] = "principal",
s="secondaire", secondaire="secondaire",
["main"] = "principal",
re="recurrent", recurring="recurrent",
["main character"] = "principal",
os="oneshot", ["one shot"]="oneshot",
["p"] = "principal",
mi="mineur", minor="mineur",
["principal"] = "principal",
y="true", yes="true", vrai="true",
["personnage principal"] = "principal",
me="mention", mention="mention",
picture="photo", photo="photo",

voice="voix", voix="voix",
-- Secondaire
["s"] = "secondaire",
body="corps", corps="corps",
["su"] = "secondaire",
del="deleted", deleted="deleted",
["supporting"] = "secondaire",
flash="flashback", flashback="flashback",
nom="nom"
["supporting character"] = "secondaire",
["se"] = "secondaire",
["secondaire"] = "secondaire",
["ps"] = "secondaire",
["personage secondaire"] = "secondaire",

-- Récurrent
["re"] = "recurrent",
["recurring"] = "recurrent",
["recurring character"] = "recurrent",
["recurrent"] = "recurrent",
["recurent"] = "recurrent",
["personnage recurrent"] = "recurrent",

-- One-shot
["os"] = "oneshot",
["one shot"] = "oneshot",
["one shot character"] = "oneshot",
["one-shot"] = "oneshot",
["personnage one shot"] = "oneshot",

-- Mineur
["mi"] = "mineur",
["minor"] = "mineur",
["minor character"] = "mineur",
["mineur"] = "mineur",
["personnage mineur"] = "mineur",

-- Booléens (yes/true)
["y"] = "true",
["yes"] = "true",
["t"] = "true",
["true"] = "true",
["o"] = "true",
["oui"] = "true",
["v"] = "true",
["vrai"] = "true",

-- Mentionné
["me"] = "mention",
["men"] = "mention",
["mention"] = "mention",
["mentioned"] = "mention",
["mentionne"] = "mention",

-- Photo seule
["picture"] = "photo",
["photo"] = "photo",

-- Voix seule
["voice"] = "voix",
["voix"] = "voix",
["voix seule"] = "voix",

-- Corps visible
["body"] = "corps",
["corpse"] = "corps",
["corps"] = "corps",
["cadavre"] = "corps",

-- Scènes supprimées
["del"] = "deleted",
["deleted scenes"] = "deleted",
["sup"] = "deleted",
["supp"] = "deleted",
["scene supprimee"] = "deleted",
["scenes supprimees"] = "deleted",

-- Flashbacks
["flash"] = "flashback",
["flashback"] = "flashback",

-- Nom uniquement
["name"] = "nom",
["nom"] = "nom",
}
}


local messages = {
local messages = {
principal = "",
principal="", secondaire="", recurrent="", oneshot="", mineur="", ["true"]="",
mention=" (mention)", photo=" (photo seule)", voix=" (voix seule)",
secondaire = "",
deleted=" (scenes supprimees)", flashback=" (flashbacks)",
recurrent = "",
nom=" (nom uniquement)", corps=" (corps)"
oneshot = "",
mineur = "",
["true"] = "",
mention = " (mention%s)",
photo = " (photo seule%s)",
voix = " (voix seule%s)",
deleted = " (scenes supprimees%s)",
flashback = " (flashbacks%s)",
nom = " (nom uniquement%s)",
corps = " (corps%s)",
}
}


----------------------------------------------------------------------
local function appearanceSuffix(typeApp, epLink, deathLink)
-- Suffixe brut basé sur isDead
----------------------------------------------------------------------
local function appearanceSuffix(typeApp, isDead)
local norm = normalize(typeApp)
local norm = normalize(typeApp)
local key = alias[norm]
local key = alias[norm]


local isDead = (epLink == deathLink and epLink ~= "")

-- 1) Si type d'apparition vide → afficher (décédé) si mort
if norm == "" then
if norm == "" then
if isDead then
if isDead then return " (décédé)" end
return " (décédé)"
end
return ""
return ""
end
end


-- 2) Si alias inconnu → même logique que type vide
if not key then
if not key then
if isDead then
if isDead then return " (décédé)" end
return " (décédé)"
end
return ""
return ""
end
end


-- 3) Type d'apparition connu → suffixe normal
local base = messages[key] or ""
local base = messages[key] or ""
local deceased = ""


if isDead then
if isDead then
deceased = ", décédé"
return base:gsub("%)$", ", décédé)")
end
end


return base:format(deceased)
return base
end
end


----------------------------------------------------------------------
----------------------------------------------------------------------
-- Italique
-- 5) Nom du personnage dans l'épisode (SMW)
----------------------------------------------------------------------
local function buildDisplaySuffix(rawSuffix)
if rawSuffix == "" then return "" end
return " ''" .. rawSuffix .. "''"
end

----------------------------------------------------------------------
-- Nom du personnage (SMW)
----------------------------------------------------------------------
----------------------------------------------------------------------
local function setCharacterName(ep, name)
local function setCharacterName(ep, name)
if ep == "" or name == "" then
if ep == "" or name == "" then return "" end
return ""
end

local fullName = Episode.getEpisodeTitle{ args = { ep } }
local fullName = Episode.getEpisodeTitle{ args = { ep } }
if not fullName or fullName == "" then
if not fullName or fullName == "" then return "" end
return string.format("{{#set: Nom du personnage dans %s = %s}}", fullName, name)
return ""
end

return string.format(
"{{#set: Nom du personnage dans %s = %s }}",
fullName,
name
)
end
end


----------------------------------------------------------------------
----------------------------------------------------------------------
-- 6) Fonction principale
-- Fonction principale
----------------------------------------------------------------------
----------------------------------------------------------------------
function p.main(frame)
function p.main(frame)
Ligne 303 : Ligne 157 :
local deathEp = safe_utf8(args[5] or "")
local deathEp = safe_utf8(args[5] or "")


if ep == "" then
if ep == "" then return "" end

return ""
------------------------------------------------------------------
-- TITRES
------------------------------------------------------------------
local titleEp = Episode.getEpisodeLink{ args = { ep } }
local titleDeath = Episode.getEpisodeLink{ args = { deathEp } }

if (not titleDeath or titleDeath == "") and deathEp ~= "" then
local full = Episode.getEpisodeFullLink{ args = { deathEp } }
if full and full ~= "" then
titleDeath = Episode.getEpisodeLink{ args = { full } }
end
end
end


if (not titleDeath or titleDeath == "") and deathEp ~= "" then
local linkFull = Episode.getEpisodeFullLink{ args = { ep } }
local linkTitle = Episode.getEpisodeTitle{ args = { ep } }
titleDeath = Episode.getEpisodeLink{ args = { deathEp } }
end
local linkShort = Episode.getEpisodeLink{ args = { ep } }

------------------------------------------------------------------
-- DÉTECTION DU DÉCÈS PAR TITRE
------------------------------------------------------------------
local isDead = (titleEp ~= "" and titleDeath ~= "" and titleEp == titleDeath)


------------------------------------------------------------------
local deathLink = Episode.getEpisodeLink{ args = { deathEp } }
-- Suffixe
------------------------------------------------------------------
local rawSuffix = appearanceSuffix(typeApp, isDead)
local suffix = buildDisplaySuffix(rawSuffix)


------------------------------------------------------------------
local suffix = appearanceSuffix(typeApp, linkShort, deathLink)
-- Affichage
------------------------------------------------------------------
local propLabel = appearancePropertyLabel(typeApp)
local propLabel = appearancePropertyLabel(typeApp)
local linkFull = Episode.getEpisodeFullLink{ args = { ep } }


local display
local display
if typeApp ~= "" then
if typeApp ~= "" then
display = string.format(
display = string.format("'''[[%s::%s|%s]]'''%s",
"'''[[%s::%s|%s]]'''%s",
propLabel, linkFull, titleEp, suffix)
propLabel,
linkFull,
linkTitle,
suffix
)
else
else
display = string.format(
display = string.format("<span style=\"color:#555555;\">%s</span>%s",
"<span style=\"color:#555555;\">%s</span>",
titleEp, suffix)
linkTitle
)
end
end


------------------------------------------------------------------
local smwDeath = ""
-- SMW
if deathLink == linkShort and deathLink ~= "" then
------------------------------------------------------------------
smwDeath = string.format("{{#set: Décédé dans = %s}}", linkFull)
local smw = ""

if isDead then
smw = smw .. string.format("{{#set: Décédé dans = %s}}", linkFull)
end
end


local smwOrder = ""
if order ~= "" then
if order ~= "" then
smwOrder = string.format(
smw = smw .. string.format("{{#set: Ordre d'apparition dans %s = %s}}",
"{{#set: Ordre d'apparition dans %s = %s }}",
titleEp, order)
linkShort,
order
)
end
end


if name ~= "" then
local smwName = setCharacterName(ep, name)
smw = smw .. setCharacterName(ep, name)
end

if smw ~= "" then
frame:preprocess(smw)
end


return display .. smwDeath .. smwOrder .. smwName
return display
end
end



Dernière version du 16 juin 2026 à 21:20

Documentation icon Documentation module[créer]
local p = {}

local Episode = require("Module:Episode")

----------------------------------------------------------------------
-- Nettoyage UTF‑8
----------------------------------------------------------------------
local function safe_utf8(str)
    if type(str) ~= "string" then return "" end
    return mw.ustring.gsub(str, "[^\0-\x7F\xC2-\xF4][\x80-\xBF]*", " ")
end

----------------------------------------------------------------------
-- Normalisation
----------------------------------------------------------------------
local function normalize(str)
    str = safe_utf8(str or "")
    str = mw.text.trim(str)
    str = mw.ustring.lower(str)
    str = str:gsub("[%-%_]", " ")
    str = mw.ustring.toNFD(str)
    str = str:gsub("[%pM]", "")
    str = str:gsub("%s+", " ")
    return str
end

----------------------------------------------------------------------
-- Types d’apparition → propriété SMW
----------------------------------------------------------------------
local types = {
    main = "Personnage principal de ",
    m = "Personnage principal de ",
    principal = "Personnage principal de ",

    supporting = "Personnage secondaire de ",
    s = "Personnage secondaire de ",
    secondaire = "Personnage secondaire de ",

    recurring = "Personnage récurrent de ",
    re = "Personnage récurrent de ",

    ["one shot"] = "Personnage one shot de ",
    os = "Personnage one shot de ",

    minor = "Personnage mineur de ",
    mi = "Personnage mineur de ",

    yes = "Apparaît dans ",
    y = "Apparaît dans ",
    vrai = "Apparaît dans ",

    mention = "Mentionné dans ",
    me = "Mentionné dans ",

    picture = "Photo seule dans ",
    photo = "Photo seule dans ",

    voice = "Voix seule dans ",
    voix = "Voix seule dans ",

    body = "Corps visible dans ",
    corps = "Corps visible dans ",

    deleted = "Apparaît uniquement dans les scènes supprimées de ",
    flashback = "Apparaît uniquement dans des flashbacks de ",

    nom = "Nom visible dans ",

    ["#default"] = "Apparaît dans "
}

local function appearancePropertyLabel(typeApp)
    local key = normalize(typeApp)
    return types[key] or types["#default"]
end

----------------------------------------------------------------------
-- Alias → catégories
----------------------------------------------------------------------
local alias = {
    m="principal", main="principal", principal="principal",
    s="secondaire", secondaire="secondaire",
    re="recurrent", recurring="recurrent",
    os="oneshot", ["one shot"]="oneshot",
    mi="mineur", minor="mineur",
    y="true", yes="true", vrai="true",
    me="mention", mention="mention",
    picture="photo", photo="photo",
    voice="voix", voix="voix",
    body="corps", corps="corps",
    del="deleted", deleted="deleted",
    flash="flashback", flashback="flashback",
    nom="nom"
}

local messages = {
    principal="", secondaire="", recurrent="", oneshot="", mineur="", ["true"]="",
    mention=" (mention)", photo=" (photo seule)", voix=" (voix seule)",
    deleted=" (scenes supprimees)", flashback=" (flashbacks)",
    nom=" (nom uniquement)", corps=" (corps)"
}

----------------------------------------------------------------------
-- Suffixe brut basé sur isDead
----------------------------------------------------------------------
local function appearanceSuffix(typeApp, isDead)
    local norm = normalize(typeApp)
    local key = alias[norm]

    if norm == "" then
        if isDead then return " (décédé)" end
        return ""
    end

    if not key then
        if isDead then return " (décédé)" end
        return ""
    end

    local base = messages[key] or ""

    if isDead then
        return base:gsub("%)$", ", décédé)")
    end

    return base
end

----------------------------------------------------------------------
-- Italique
----------------------------------------------------------------------
local function buildDisplaySuffix(rawSuffix)
    if rawSuffix == "" then return "" end
    return " ''" .. rawSuffix .. "''"
end

----------------------------------------------------------------------
-- Nom du personnage (SMW)
----------------------------------------------------------------------
local function setCharacterName(ep, name)
    if ep == "" or name == "" then return "" end
    local fullName = Episode.getEpisodeTitle{ args = { ep } }
    if not fullName or fullName == "" then return "" end
    return string.format("{{#set: Nom du personnage dans %s = %s}}", fullName, name)
end

----------------------------------------------------------------------
-- Fonction principale
----------------------------------------------------------------------
function p.main(frame)
    local args = frame.args

    local ep      = safe_utf8(args[1] or "")
    local typeApp = safe_utf8(args[2] or "")
    local order   = safe_utf8(args[3] or "")
    local name    = safe_utf8(args[4] or "")
    local deathEp = safe_utf8(args[5] or "")

    if ep == "" then return "" end

    ------------------------------------------------------------------
    -- TITRES
    ------------------------------------------------------------------
    local titleEp = Episode.getEpisodeLink{ args = { ep } }
    local titleDeath = Episode.getEpisodeLink{ args = { deathEp } }

    if (not titleDeath or titleDeath == "") and deathEp ~= "" then
        local full = Episode.getEpisodeFullLink{ args = { deathEp } }
        if full and full ~= "" then
            titleDeath = Episode.getEpisodeLink{ args = { full } }
        end
    end

    if (not titleDeath or titleDeath == "") and deathEp ~= "" then
        titleDeath = Episode.getEpisodeLink{ args = { deathEp } }
    end

    ------------------------------------------------------------------
    -- DÉTECTION DU DÉCÈS PAR TITRE
    ------------------------------------------------------------------
    local isDead = (titleEp ~= "" and titleDeath ~= "" and titleEp == titleDeath)

    ------------------------------------------------------------------
    -- Suffixe
    ------------------------------------------------------------------
    local rawSuffix = appearanceSuffix(typeApp, isDead)
    local suffix = buildDisplaySuffix(rawSuffix)

    ------------------------------------------------------------------
    -- Affichage
    ------------------------------------------------------------------
    local propLabel = appearancePropertyLabel(typeApp)
    local linkFull  = Episode.getEpisodeFullLink{ args = { ep } }

    local display
    if typeApp ~= "" then
        display = string.format("'''[[%s::%s|%s]]'''%s",
            propLabel, linkFull, titleEp, suffix)
    else
        display = string.format("<span style=\"color:#555555;\">%s</span>%s",
            titleEp, suffix)
    end

    ------------------------------------------------------------------
    -- SMW
    ------------------------------------------------------------------
    local smw = ""

    if isDead then
        smw = smw .. string.format("{{#set: Décédé dans = %s}}", linkFull)
    end

    if order ~= "" then
        smw = smw .. string.format("{{#set: Ordre d'apparition dans %s = %s}}",
            titleEp, order)
    end

    if name ~= "" then
        smw = smw .. setCharacterName(ep, name)
    end

    if smw ~= "" then
        frame:preprocess(smw)
    end

    return display
end

return p