Die Dokumentation für dieses Modul kann unter Modul:Serie/Doku erstellt werden
-- <nowiki>
-- Ermöglicht das Einfügen des Titels eines Serieneintrags
-- mithilfe eines vorgegebenen Codes und kann bei Bedarf
-- Anpassungen vornehmen, z.B. auf eine Abkürzung zurück-
-- greifen oder die zuhehörige Seite verlinken (letzteres
-- ist standardmäßig aktiviert).
-- Für weitere Infos siehe [[Vorlage:Serie]].
local p = {}
-- ACHTUNG! Kategorie ist derzeit nur für Orte angepasst und die Namen
-- unterscheiden sich von anderen Kategorien wie Rätsel oder Personen.
-- Diese Liste enthält Codes, mit denen jeweils ein entspre-
-- chender Titel und eine Kurzschreibweise assoziiert werden.
local serie = {
["1"] = { titel = "Professor Layton und das geheimnisvolle Dorf", kurz = "Das geheimnisvolle Dorf", kategorie = "Layton 1" },
["2"] = { titel = "Professor Layton und die Schatulle der Pandora", kurz = "Die Schatulle der Pandora", kategorie = "Layton 2" },
["3"] = { titel = "Professor Layton und die verlorene Zukunft", kurz = "Die verlorene Zukunft", kategorie = "Layton 3" },
["4"] = { titel = "Professor Layton und der Ruf des Phantoms", kurz = "Der Ruf des Phantoms", kategorie = "Layton 4" },
["5"] = { titel = "Professor Layton und die Maske der Wunder", kurz = "Die Maske der Wunder", kategorie = "Layton 5" },
["6"] = { titel = "Professor Layton und das Vermächtnis von Aslant", kurz = "Das Vermächtnis von Aslant", kategorie = "Layton 6" },
["VS"] = { titel = "Professor Layton vs. Phoenix Wright: Ace Attorney", kurz = "Layton vs. Ace Attorney", kategorie = "Layton vs. Wright" },
["LMJ"] = { titel = "LAYTON’S MYSTERY JOURNEY: Katrielle und die Verschwörung der Millionäre", kurz = "LAYTON’S MYSTERY JOURNEY", kategorie = "Layton’s Mystery Journey" },
["NWD"] = { titel = "Professor Layton und die Neue Welt des Dampfes", kurz = "Die Neue Welt des Dampfes", kategorie = "Neue Welt des Dampfes" },
["ED"] = { titel = "Professor Layton und die ewige Diva", kurz = "Die ewige Diva", kategorie = "Ewige Diva" },
["DL"] = { titel = "Detektei Layton – Katrielles rätselhafte Fälle", kurz = "Detektei Layton", kategorie = "Detektei Layton" },
["LBMR"] = { titel = "Layton Brothers: Mystery Room", kurz = "Layton Brothers", kategorie = "Layton Brothers" },
["LL"] = { titel = "Professor Layton's London Life", kurz = "London Life", kategorie = "London Life" },
["Shikyo"] = { titel = "Layton Kyōju to Shikyo no Kan", kurz = "Shikyo no Kan", kategorie = "Shikyo no Kan" },
["Jikenbo"] = { titel = "Cherumī Keibu no Jikenbo", kurz = "Cherumī Keibu no Jikenbo", kategorie = "Cherumī Keibu no Jikenbo" },
["Kyujitsu"] = { titel = "Layton Kyōju to London no Kyūjitsu", kurz = "London no Kyūjitsu", kategorie = "London no Kyūjitsu" }
}
-- Diese Liste enthält zusätzliche Codes, die als Aliase zu den Codes aus
-- "serie" fungieren. Es können mehrere Aliase für ein- und denselben Code
-- erstellt werden.
local alias = {
["7"] = "LMJ",
["MJ"] = "LMJ",
["NWS"] = "NWD"
}
-- Mark codes as deprecated (adds a maintenance category)
local deprecated = {
["NWS"] = true
}
-- Returns the list entry from "serie" using the "code" parameter.
local function getEintrag(code)
-- Resolve aliases
if alias[code] then
code = alias[code]
end
return serie[code]
end
-- Returns a string that adds a category indicating the given code has been marked as deprecated
local function getDeprecationCategory(code)
if deprecated[code] then
return "[[Kategorie:Veraltetes Kürzel eines Serien-Eintrags]]"
end
return ""
end
-- Turn a string into an annotation.
-- Current format: " (Annotation)"
local function formatAnmerkung(text)
return " " .. "(" .. text .. ")"
end
-- Separates a possible annotation from the code and returns
-- a table with the code and the annotation string. If there
-- is no annotation, the string will be empty.
local function getAnmerkung(code)
local t = { code = "", anmerkung = "" }
local i = 0
-- Split the string at every space character. The first
-- substring will be interpreted as the code, all other
-- substrings will be merged.
for s in mw.text.gsplit(code, "%s") do
if i == 0 then
t.code = s
i = i + 1
else
t.anmerkung = t.anmerkung .. " " .. s
end
end
-- If there's an annotation, format it using "formatAnmerkung()".
if t.anmerkung ~= "" then t.anmerkung = formatAnmerkung(mw.text.trim(t.anmerkung)) end
return t
end
-- A simple function for turning "page" into a string.
-- If "text" is given, it will override the link's text.
local function makeLink(page, text)
text = text and "|" .. text or ""
return "[[" .. page .. text .. "]]"
end
-- A simple function for printing an error message.
-- This is used whenever an invalid code has been given.
local invalidCodeCategory = "Ungültiges Kürzel eines Serien-Eintrags"
local function getInvalidCodeMessage(code)
return "{{Ungültig|Fehler: Ein ungültiges Kürzel wurde für den Serien-Eintrag angegeben.|" .. invalidCodeCategory .. "}}"
end
-- Entry point function
function p.Titel(frame)
local args = frame:getParent().args
local parts = getAnmerkung(args[1])
local eintrag = getEintrag(parts.code)
local text = ""
if not eintrag then return errMsgCodeFalsch(args[1]) end
local kurz = args[2] == "kurz" or args[3] == "kurz"
local link = args[2] ~= "text" and args[3] ~= "text"
text = kurz and eintrag.kurz or eintrag.titel
return link and makeLink(eintrag.titel, text) .. parts.anmerkung or text .. parts.anmerkung .. getDeprecationCategory(parts.code)
end
-- Entry point function for use in infoboxes.
-- This makes it possible to separate codes by a comma
-- to receive a list of formatted titles.
function p.Infobox(frame)
local args = frame:getParent().args
local eintrag, parts
local kategorie = ""
local liste = ""
local kategorieKeyword = "Kategorie:" -- must include colons
for code in mw.text.gsplit(args[1], ',', true) do
parts = getAnmerkung(code)
eintrag = getEintrag(parts.code)
-- @todo
-- ACHTUNG! Das ist noch keine perfekte Lösung, denn es wird von allen
-- Kategorien erwartet, dass sie gleich starten. Z.B. ist hier folgende
-- unterschiedliche Benennung problematisch:
-- "Orte in einem Film" und "Orte aus Layton #"
if args[3] ~= nil and string.sub(args[3], 1, string.len(kategorieKeyword)) == kategorieKeyword and eintrag.kategorie ~= "" then
kategorie = "[[" .. kategorieKeyword .. mw.text.trim(string.sub(args[3], string.len(kategorieKeyword) + 1) .. " " .. eintrag.kategorie) .. "]]"
end
if not eintrag then
liste = liste .. errMsgCodeFalsch(code) .. "<br>"
else
liste = liste .. makeLink(eintrag.titel, eintrag.kurz) .. parts.anmerkung .. kategorie .. getDeprecationCategory(code) .. "<br>"
end
end
return mw.text.trim(liste, "<br>")
end
-- Entry point function for use in categories.
-- This will output the code used in categories.
function p.Kategorie(frame)
local args = frame:getParent().args
local eintrag = getEintrag(args[1])
if not eintrag then return errMsgCodeFalsch(args[1]) end
return eintrag.kategorie
end
-- Entry point function for use in the template.
function p.Main(frame)
local args = frame:getParent().args
local usage = args[2] and string.lower(args[2]) or ""
if usage == "infobox" then
return p.Infobox(frame)
elseif usage == "kategorie" then
return p.Kategorie(frame)
else
return p.Titel(frame)
end
end
return p