Die Dokumentation für dieses Modul kann unter Modul:Unterrichtsfilm/Helper/Doku erstellt werden
local helper = {}
local getArgs = require('Module:Arguments').getArgs
-- Semantische Speicherung mit Fehlerausgabe
function helper.setProperty( frame )
if not mw.smw then
return "mw.smw module not found"
end
local result = mw.smw.set( frame.args )
if result == true then
return
else
return 'An error occurred during the storage process. Message reads ' .. result.error
end
end
-- Kategorien mit Sortkey + feste Kategorie
function helper.addCategories(data)
local cats = data.categories or {}
local sortkey = data.sortkey or mw.title.getCurrentTitle().text
if type(cats) == "string" then
cats = mw.text.split(cats, ",")
end
if type(cats) ~= "table" then
return "Ungültige Kategorienliste."
end
-- „Film & Serie“ immer hinzufügen
table.insert(cats, "Film & Serie")
local output = ""
for _, cat in ipairs(cats) do
if cat and cat ~= "" then
output = output .. string.format("[[Kategorie:%s|%s]]\n", cat, sortkey)
end
end
return output
end
-- Bereinigung von Zeichen
function helper.cleanString(input)
if not input or input == "" then return "" end
return input
:gsub("[%c]", "")
:gsub("[\"']", "")
:gsub("[%p&&[^:/]]", "")
:gsub("%s+", " ")
:gsub("^%s*(.-)%s*$", "%1")
:gsub("[:/]", " - ")
end
-- Kürzt & bereinigt Text (für Kurzbeschreibung etc.)
function helper.cleanAndTruncate(text, truncateLength)
if not text or text == "" then return "" end
text = mw.text.killMarkers(text)
:gsub(' ', ' ')
:gsub('<br ?/?>', ', ')
:gsub('<.->(.-)</.->', '%1')
:gsub('<.->', '')
:gsub('%[%[[^%]]-|', '')
:gsub('%[%[[^%]]-%]%]', '')
:gsub('%[%S.-%]', '')
:gsub('[%[%]]', '')
:gsub("'''''", "")
:gsub("'''?", "")
:gsub('----+', '')
:gsub("^%s+", "")
:gsub("%s+$", "")
:gsub("%s+", " ")
if truncateLength and tonumber(truncateLength) then
text = mw.text.truncate(text, tonumber(truncateLength), '…', true)
end
return text
end
function helper.setDisplayTitle(data)
local title = data.title
if title and title ~= "" then
local success, err = pcall(function()
mw.ext.displaytitle.set(title)
end)
if not success then
mw.log("Fehler beim Setzen des DISPLAYTITLE: " .. tostring(err))
end
end
end
-- Icon abhängig vom Typ
function helper.getIcon(typ)
typ = (typ or ""):lower()
if typ == "dokumentation" then
return "book"
elseif typ == "serie" then
return "tv"
elseif typ == "kurzfilm" then
return "clapperboard"
elseif typ == "Spielfilm" then
return "film"
else
return "film" -- Standard: Spielfilm
end
end
return helper