Modul:Dokumentation
Zweck[Quelltext bearbeiten]
Dieses Modul steuert die gesamte Ausgabe der zentralen Vorlage {{Vorlage:Dokumentation}} im Wikonia-Wiki.
Es zeigt automatisch den Dokumentationskopf, Hinweisboxen, die eigentliche Dokumentation (aus der gleichnamigen Unterseite /Doku) sowie ggf. einen <templatedata>-Block.
Verwendung[Quelltext bearbeiten]
Das Modul wird nicht direkt eingebunden, sondern über die Vorlage:
{{Dokumentation
| lua = 1
| css = 1
| subst = kann
| risiko = warnung
}}
Unterstützte Parameter[Quelltext bearbeiten]
| Parameter | Wirkung | Mögliche Werte |
|---|---|---|
lua |
Zeigt Lua-Hinweisbox an | 1 (Standardtext) oder Liste: Modul:Foo, Modul:Bar
|
css |
Zeigt CSS-Hinweisbox an | 1
|
subst |
Zeigt Hinweis zur Substitution | kann, soll, muss, darf nicht
|
risiko |
Zeigt Hinweis auf Änderungsrisiko | none, achtung, kritisch
|
Automatische Funktionen[Quelltext bearbeiten]
- Bindet
/Dokuautomatisch ein, sofern vorhanden - Zeigt
<templatedata>-Block, wenn vorhanden - Fügt Kategorien automatisch hinzu:
Hauptseite: Vorlage mit Dokumentation / Modul mit Dokumentation
/Doku: Vorlagendokumentation / Moduldokumentation
Hinweis[Quelltext bearbeiten]
Dieses Modul ersetzt eine Vielzahl an Hilfskonstruktionen aus älteren Systemen.
Die dazugehörige Vorlage {{Vorlage:Dokumentation}} sollte immer verwendet werden.
-- Modul:Dokumentation
-- Entwickelt nach Analyse der enwiki-Version, angepasst auf unsere Struktur und entschlankt
-- Modul:Dokumentation – FIXED: /Doku-Einbindung robust und dummheitsresistent™
local p = {}
local getArgs = require('Module:Arguments').getArgs
local function pageExists(title)
local t = mw.title.new(title)
return t and t.exists
end
local function isDocSubpage(title)
return title.text:match("/Doku$") ~= nil
end
local function hasTemplateData(docTitle)
if not docTitle or not docTitle.exists then return false end
local content = docTitle:getContent()
return content and content:find("<templatedata>", 1, true) ~= nil
end
local function makeIcon(icon)
return string.format('[[Datei:%s|50px|class=wikonia-doku-icon]]', icon)
end
local function makeHeader(title, icon, links)
-- icon kann entweder ein Dateiname (z. B. "Documentation-plain-black.svg")
-- oder bereits geparster Wikitext/HTML sein (z. B. frame:preprocess('[[Datei:...]]')).
local iconHtml = ""
if icon and icon ~= "" then
local iconStr = tostring(icon)
-- Wenn iconStr bereits Parser-/HTML-Ausgabe enthält, verwenden wir es direkt.
if iconStr:find("%[%[") or iconStr:find("<img") or iconStr:find('typeof="mw:File"') then
iconHtml = iconStr
else
-- ansonsten ist es ein Dateiname -> makeIcon erzeugt den Wikitext
iconHtml = makeIcon(iconStr)
end
end
local linksText
if type(links) == "table" then
linksText = table.concat(links, " | ")
else
linksText = tostring(links or "")
end
return string.format(
'<div class="wikonia-doku-header">%s <strong>%s</strong> <span class="wikonia-doku-links">%s</span></div>',
iconHtml,
title,
linksText
)
end
local function makeCategory(cat)
return string.format('[[Kategorie:%s]]', cat)
end
function p.main(frame)
local args = getArgs(frame)
local title = mw.title.getCurrentTitle()
local ns = title.namespace
local fullpagename = title.fullText
local isTemplate = ns == 10
local isModule = ns == 828
local isDocPage = isDocSubpage(title)
local baseName = title.text:gsub("/Doku$", "")
local baseTitle = mw.title.makeTitle(ns, baseName)
local dokuPageName = baseTitle.prefixedText .. "/Doku"
local purgeTitle = mw.title.makeTitle('Spezial', 'Purge/' .. fullpagename) -- mw.title-Objekt für die Spezialseite "Spezial:Purge/Aktuelle_Seite"
local purgeUrl = purgeTitle:fullUrl() -- URL dieses Titel-Objekts ab (Garantie für String-Rückgabe)
local out = {}
-- Kategorieverwaltung für /Doku-Seiten
if isDocPage then
if isTemplate then table.insert(out, makeCategory("Vorlagendokumentation")) end
if isModule then table.insert(out, makeCategory("Moduldokumentation")) end
return table.concat(out, "\n")
end
-- Warnung bei falschem Namensraum
if not (isTemplate or isModule) then
table.insert(out, '<div class="wikonia-doku-warnung">Diese Vorlage ist nur für Seiten im Namensraum „Vorlage“ oder „Modul“ gedacht.</div>')
return table.concat(out, "\n")
end
-- Headerbox mit Icon und funktionierenden Links (ohne extern-Icon)
local icon = isTemplate and "Template Info-Icon.svg" or "Module-info.svg"
local docTitle = mw.title.new(baseTitle.fullText .. "/Doku")
-- Plainlinks-Wrapper: verhindert extern-Icons bei echten URLs
local headLinks = {
string.format('[%s ansehen]', docTitle:fullUrl()),
string.format('[%s bearbeiten]', docTitle:fullUrl('action=edit')),
string.format('[%s Versionsverlauf]', docTitle:fullUrl('action=history')),
string.format('[%s Cache leeren]', purgeUrl)
}
-- Umhüllen in <span class="plainlinks">...</span>
local linkBlock = '<span class="plainlinks">' .. table.concat(headLinks, ' • ') .. '</span>'
local iconMarkup = string.format('[[Datei:%s|40px|class=wikonia-doku-icon|link=]]', icon)
local iconParsed = frame:preprocess(iconMarkup) -- <--- HIER: zwingend parsen
table.insert(out, makeHeader("Dokumentation", iconParsed, { linkBlock }))
-- BODY MIT HAUPTINHALT
-- Badges (rechtsbündig, gesammelt)
local boxes = {}
table.insert(boxes, frame:preprocess("{{Versionsschutz}}"))
if args["lua"] then
if args["lua"] == "1" then
table.insert(boxes, frame:preprocess("{{Dokumentation/Lua}}"))
else
table.insert(boxes, frame:preprocess(string.format("{{Dokumentation/Lua|luamodule=%s}}", args["lua"])))
end
end
if args["css"] then
table.insert(boxes, frame:preprocess(string.format("{{Dokumentation/CSS|%s}}", args["css"])))
end
if args["subst"] then
table.insert(boxes, frame:preprocess(string.format("{{Subst|%s}}", args["subst"])))
end
if args["risiko"] then
table.insert(boxes, frame:preprocess(string.format("{{Änderungsrisiko|%s}}", args["risiko"])))
end
-- Ausgabe Versionsschutz
local protectionArg = args["protected"]
-- Prüfen, ob das Argument gesetzt und nicht auf "0" oder "false" gesetzt ist.
-- Wir verwenden tostring() für den Fall, dass ein boolean (z.B. false) übergeben wird.
if protectionArg and tostring(protectionArg):lower() ~= "0" and tostring(protectionArg):lower() ~= "false" then
-- Wenn der Wert "1" (typisch für unbenannte Argumente) oder "" (leeres Argument) ist,
-- verwenden wir den Standardwert "Programmierschutz".
if protectionArg == "1" or protectionArg == "" then
table.insert(boxes, frame:preprocess("{{Versionsschutz|Programmierschutz}}"))
else
-- Anderenfalls verwenden wir den benutzerdefinierten Wert.
table.insert(boxes, frame:preprocess(string.format("{{Versionsschutz|%s}}", protectionArg)))
end
end
-----------------------------------------------------------
-- BODY-Container über mw.html (Badges + /Doku)
-----------------------------------------------------------
local body = mw.html.create('div')
:addClass('vorlage-dokumentation_body')
-- Badges / Boxen als Float-Block innerhalb des Bodys
if #boxes > 0 then
local boxWrap = mw.html.create('div')
:addClass('wikonia-doku-float')
:wikitext(table.concat(boxes, "\n"))
body:node(boxWrap)
end
-- Einbindung der Doku-Seite
if pageExists(dokuPageName) then
body:wikitext(frame:preprocess(string.format("{{%s}}", dokuPageName)))
else
body:wikitext('<div class="wikonia-doku-warnung">Diese Seite hat noch keine Dokumentation.</div>')
body:wikitext(makeCategory("Dokumentation fehlt"))
end
-- Body in die Gesamtausgabe einfügen
table.insert(out, tostring(body))
-- FOOTER (aus Vorlage)
table.insert(out, frame:preprocess(string.format("{{Dokumentation/Footer|issubpage=%s|subpages=%s}}",
args["issubpage"] or "",
args["subpages"] or ""
)))
-- Kategorisierung Hauptseite
if isTemplate then table.insert(out, makeCategory("Vorlage mit Dokumentation")) end
if isModule then table.insert(out, makeCategory("Modul mit Dokumentation")) end
return table.concat(out, "\n")
end
return p