Aller au contenu

« Module:Episode » : différence entre les versions

De Stargate Wiki Sémantique
Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 5 : Ligne 5 :
local function safe(v)
local function safe(v)
return v or ""
return v or ""
end

-- Normalisation robuste des alias
local function normalizeAlias(s)
if not s then return "" end

s = mw.ustring.lower(s)

local accents = {
["à"]="a", ["á"]="a", ["â"]="a", ["ä"]="a", ["ã"]="a", ["å"]="a",
["ç"]="c",
["è"]="e", ["é"]="e", ["ê"]="e", ["ë"]="e",
["ì"]="i", ["í"]="i", ["î"]="i", ["ï"]="i",
["ñ"]="n",
["ò"]="o", ["ó"]="o", ["ô"]="o", ["ö"]="o", ["õ"]="o",
["ù"]="u", ["ú"]="u", ["û"]="u", ["ü"]="u",
["ý"]="y", ["ÿ"]="y"
}

s = mw.ustring.gsub(s, ".", accents)
s = mw.ustring.gsub(s, "[’']", "")
s = mw.ustring.gsub(s, "[^%w]", " ")
s = mw.ustring.gsub(s, "%s+", " ")
s = mw.text.trim(s)

return s
end
end


-- Function 1: Get full episode link from key
-- Function 1: Get full episode link from key
function p.getEpisode(frame)
function p.getEpisode(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 29 : Ligne 55 :
-- Function 2: Force namespace to "Credits:"
-- Function 2: Force namespace to "Credits:"
function p.getCreditsLink(frame)
function p.getCreditsLink(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 44 : Ligne 70 :
-- Function 3: Force namespace to "Transcript:"
-- Function 3: Force namespace to "Transcript:"
function p.getTranscriptLink(frame)
function p.getTranscriptLink(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 59 : Ligne 85 :
-- Function 4: Force namespace to "Quotes:"
-- Function 4: Force namespace to "Quotes:"
function p.getQuotesLink(frame)
function p.getQuotesLink(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 74 : Ligne 100 :
-- Function 5: Force namespace to "Category:Images from"
-- Function 5: Force namespace to "Category:Images from"
function p.getImagesLink(frame)
function p.getImagesLink(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 89 : Ligne 115 :
-- Function 6: Retrieve from link
-- Function 6: Retrieve from link
function p.getEpisodeLink(frame)
function p.getEpisodeLink(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 101 : Ligne 127 :
-- Function 7: Get full episode link only from key
-- Function 7: Get full episode link only from key
function p.getEpisodeFullLink(frame)
function p.getEpisodeFullLink(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 120 : Ligne 146 :
-- Function 8: Get episode title only from key
-- Function 8: Get episode title only from key
function p.getEpisodeTitle(frame)
function p.getEpisodeTitle(frame)
local key = string.lower(frame.args[1] or "")
local key = normalizeAlias(frame.args[1])
local entry = data[key]
local entry = data[key]


Ligne 128 : Ligne 154 :


return safe(entry[3])
return safe(entry[3])
end

function p.aliasToPages()
local map = {}

for alias, entry in pairs(data) do
local link = entry[2]

if not map[alias] then
map[alias] = { link }
else
-- éviter les doublons exacts
local exists = false
for _, v in ipairs(map[alias]) do
if v == link then
exists = true
break
end
end
if not exists then
table.insert(map[alias], link)
end
end
end

return map
end

function p.showAliasConflicts()
local map = p.aliasToPages()
local out = {}

table.insert(out, "== Alias pointant vers plusieurs pages ==")

local found = false

for alias, pages in pairs(map) do
if #pages > 1 then
found = true
table.insert(out,
"* <code>" .. alias .. "</code> → " .. table.concat(pages, " / ")
)
end
end

if not found then
table.insert(out, "* Aucun conflit détecté")
end

return table.concat(out, "\n")
end
end



Version du 5 juin 2026 à 21:27

Documentation icon Documentation module[créer]
local data = mw.loadData("Module:Episode/data")
local p = {}

-- Sécurisation des valeurs nil
local function safe(v)
    return v or ""
end

-- Normalisation robuste des alias
local function normalizeAlias(s)
    if not s then return "" end

    s = mw.ustring.lower(s)

    local accents = {
        ["à"]="a", ["á"]="a", ["â"]="a", ["ä"]="a", ["ã"]="a", ["å"]="a",
        ["ç"]="c",
        ["è"]="e", ["é"]="e", ["ê"]="e", ["ë"]="e",
        ["ì"]="i", ["í"]="i", ["î"]="i", ["ï"]="i",
        ["ñ"]="n",
        ["ò"]="o", ["ó"]="o", ["ô"]="o", ["ö"]="o", ["õ"]="o",
        ["ù"]="u", ["ú"]="u", ["û"]="u", ["ü"]="u",
        ["ý"]="y", ["ÿ"]="y"
    }

    s = mw.ustring.gsub(s, ".", accents)
    s = mw.ustring.gsub(s, "[’']", "")
    s = mw.ustring.gsub(s, "[^%w]", " ")
    s = mw.ustring.gsub(s, "%s+", " ")
    s = mw.text.trim(s)

    return s
end

-- Function 1: Get full episode link from key
function p.getEpisode(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local ns  = safe(entry[1])
    local link = safe(entry[2])
    local title = safe(entry[3])

    if ns == "" then
        return string.format("[[%s|%s]]", link, title)
    else
        return string.format("[[%s:%s|%s]]", ns, link, title)
    end
end

-- Function 2: Force namespace to "Credits:"
function p.getCreditsLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return string.format("[[Crédits:%s|%s]]", link, title)
end

-- Function 3: Force namespace to "Transcript:"
function p.getTranscriptLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return string.format("[[Retranscription:%s|%s]]", link, title)
end

-- Function 4: Force namespace to "Quotes:"
function p.getQuotesLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return string.format("[[Citations:%s|%s]]", link, title)
end

-- Function 5: Force namespace to "Category:Images from"
function p.getImagesLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return string.format("[[:Catégorie:Images de %s|%s]]", link, title)
end

-- Function 6: Retrieve from link
function p.getEpisodeLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    return safe(entry[2])
end

-- Function 7: Get full episode link only from key
function p.getEpisodeFullLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local ns = safe(entry[1])
    local link = safe(entry[2])

    if ns == "" then
        return link
    else
        return ns .. ":" .. link
    end
end

-- Function 8: Get episode title only from key
function p.getEpisodeTitle(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Episode not found"
    end

    return safe(entry[3])
end

return p