Aller au contenu

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

De Stargate Wiki Sémantique
Contenu supprimé Contenu ajouté
mAucun résumé des modifications
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
local data = mw.loadData("Module:Episode/data")
local data = mw.loadData("Module:Episode/data")

local p = {}
local p = {}

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


-- Function 1: Get full episode link from key
-- Function 1: Get full episode link from key
Ligne 12 : Ligne 16 :
end
end


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


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


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

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


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

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


local link = safe(entry[2])
-- FIX : 4 valeurs → il faut 4 variables
local _, link, title = unpack(entry)
local title = safe(entry[3])

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


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

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


local _, link = unpack(entry)
return safe(entry[2])
return link
end
end


Ligne 96 : Ligne 108 :
end
end


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


if ns == "" or ns == nil then
if ns == "" then
return link
return link
else
else
Ligne 114 : Ligne 127 :
end
end


local _, _, title = unpack(entry)
return safe(entry[3])
return title
end

-- Function X: Detect duplicates in Module:Episode/data

function p.checkAliasConflicts()
local seen = {}
local conflicts = {}

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

if seen[alias] and seen[alias] ~= link then
table.insert(conflicts, {
alias = alias,
link1 = seen[alias],
link2 = link
})
else
seen[alias] = link
end
end

return conflicts
end

function p.showAliasConflicts()
local list = p.checkAliasConflicts()
local out = {}

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

if #list == 0 then
table.insert(out, "* Aucun conflit")
else
for _, c in ipairs(list) do
table.insert(out,
"* " .. c.alias ..
" → " .. c.link1 ..
" / " .. c.link2
)
end
end

return table.concat(out, "\n")
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.showAliasToPages()
local map = p.aliasToPages()
local out = {}

table.insert(out, "== Alias → Pages ==")

for alias, pages in pairs(map) do
if #pages == 1 then
table.insert(out, "* <code>" .. alias .. "</code> → " .. pages[1])
else
table.insert(out,
"* <code>" .. alias .. "</code> → '''CONFLIT''' : " .. table.concat(pages, " / ")
)
end
end

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



Version du 5 juin 2026 à 20:39

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

-- Function 1: Get full episode link from key
function p.getEpisode(frame)
    local key = string.lower(frame.args[1] or "")
    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 = string.lower(frame.args[1] or "")
    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 = string.lower(frame.args[1] or "")
    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 = string.lower(frame.args[1] or "")
    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 = string.lower(frame.args[1] or "")
    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 = string.lower(frame.args[1] or "")
    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 = string.lower(frame.args[1] or "")
    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 = string.lower(frame.args[1] or "")
    local entry = data[key]

    if not entry then
        return "Episode not found"
    end

    return safe(entry[3])
end

return p