[Lesen | Bearbeiten | Versionen | Aktualisieren] DokumentationSpringe zum Quelltext ↴ Zum Gebrauch von Lua-Modulen siehe die Modul-Hilfe.
Das Modul Dokumentation stellt Funktionen zur Darstellung von Vorlagen- und Moduldokumentationen zur Verfügung
- page liefert den Rahmen um eine Vorlagen- oder Modulseite
- docPage liefert den Rahmen um eine Dokumentationsseite
- create erzeugt eine neue Dokumentation und belegt sie mit einem Textgerüst aus der Vorlage:Dokumentationsvorbelegung vor
Aufruf
{{#invoke: Dokumentation| page }}
{{#invoke: Dokumentation| docPage }}
{{#invoke: Dokumentation| create }}
Anwendung
Liste der Vorlagen, die dieses Modul verwenden
local p = {}
local getType = function( namespace, page )
local pageType = 'Vorlage'
if namespace == 'Modul' then
pageType = 'Modul'
elseif page.fullText:gsub( '/Dokumentation$', '' ):find( '%.css$' ) then
pageType = 'Stylesheet'
elseif page.fullText:gsub( '/Dokumentation$', '' ):find( '%.js$' ) then
pageType = 'Skript'
end
return pageType
end
-- Erstellen einer Dokumentationsseite
function p.create( f )
local args = require( 'Modul:ParameterUmwandeln' ).norm()
local page = mw.title.getCurrentTitle()
local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/Dokumentation'
local out
if not args.content and page == docPage then
out = f:preprocess( '{{subst:Vorlage:Dokumentationsvorbelegung}}' )
else
local templateArgs = {}
for _, key in ipairs{ 'type', 'page', 'content' } do
local val = args[key]
if val then
if key == 'content' then val = '\n' .. val .. '\n' end
table.insert( templateArgs, key .. '=' .. val )
end
end
out = '{{Dokumentation|' .. table.concat( templateArgs, '|' ) .. '}}'
out = out:gsub( '|}}', '}}' )
if not args.content then
out = out .. '\n<!-- Navboxen, Kategorien und Interwikilinks bitte auf die Dokumentationsseite! -->'
end
end
if not mw.isSubsting() then
out = f:preprocess( out )
if not args.demo then
out = out .. '[[Kategorie:Seiten mit nicht substituierten Vorlagen]]'
end
end
return out
end
-- Dokumentationskopf auf der Dokumentationsseite
function p.docPage( f )
local lang = mw.language.new('de_DE')
local args = require( 'Modul:ParameterUmwandeln' ).merge( true )
local badDoc = args.baddoc
if args.noheader == '1' then
if badDoc then
args.baddoc = '1'
end
return ''
end
local page = mw.title.getCurrentTitle()
local namespace = page.nsText
local pageType = lang:ucfirst( mw.ustring.lower( args.type or getType( namespace, page ) ) )
if string.match( page.text, "/Dokumentation" ) then
local templatePage = string.gsub( page.text, "/Dokumentation", "" )
local links = {
'<span class=plainlinks>[' .. page:fullUrl( 'action=purge' ) .. ' Aktualisieren]</span>'
}
if not noDoc then
table.insert( links, '[[Hilfe:Vorlagen|Hilfe]]' )
end
local body = mw.html.create( 'div' )
body
:css{
['margin-bottom'] = '0.8em',
padding = '0.8em 1em 0.7em'
}
:attr( 'class', 'documentation-header documentation-docpage' .. ( badDoc and ' documentation-baddoc' or '' ) )
:tag( 'div' )
:css( 'float', 'right' )
:wikitext( mw.text.nowiki( '[' ), table.concat( links, ' | ' ), mw.text.nowiki( ']' ) )
:done()
:wikitext(
'Dies ist die Dokumentation, sie wird auf der [[',
args.type or page.nsText, ':', templatePage .. '|', ( (pageType == 'Vorlage' and 'Vorlagen') or pageType), 'seite]] eingebunden. ',
'Siehe [[Vorlage:Dokumentation]] für weitere Informationen.'
)
local t = pageType
if t == 'Vorlage' then t = 'Vorlagen' end
if badDoc then
body:wikitext( "<br>'''Diese " .. t .. "dokumentation muss verbessert werden.'''" )
end
if not args.demo then
body:wikitext( '[[Kategorie:' .. t .. 'dokumentation]]' )
end
return body
end
return
end
-- Dokumentationskasten auf der Vorlagen-, Modul-, Stylesheet-, Skriptseite
function p.page( f )
-- mw.text.trim benutzt mw.ustring.gsub, welches ab und zu bei großen Zeichenketten versagt
local function trim( s )
return string.gsub( s, '^[\t\r\n\f ]*(.-)[\t\r\n\f ]*$', '%1' )
end
local args = require( 'Modul:ParameterUmwandeln' ).merge( true )
local page = mw.title.getCurrentTitle()
local namespace = page.nsText
local docText = trim( args.content or '' )
local lang = mw.language.new('de_DE')
if docText == '' then docText = nil end
local docPage
local noDoc
if docText then
docPage = page
else
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/Dokumentation' )
noDoc = args.nodoc or not docPage.exists
end
local badDoc = args.baddoc
local pageType = lang:ucfirst( mw.ustring.lower( args.type or getType( namespace, page ) ) )
if not docText and not noDoc then
args.noheader = '1'
docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
if not args.baddoc == '' then
badDoc = 1
end
if docText == '' then
docText = nil
noDoc = 1
end
end
if docText then
local m = ''
if args.lua then
local l = {}
for s in args.lua:gmatch( '[^;]+' ) do table.insert( l, '[[Modul:' .. s .. '|' .. s .. ']]' ) end
m = '<div style="float:right; margin:8px">[[Datei:Lua logo.svg|20px|link=]] ' .. table.concat( l, ', ' ) .. '</div>\n'
elseif args.widget then
m = '<div style="float:right; margin:8px">[[Datei:Zahnrad.png|20px|link=]] [[Widget:' .. args.widget .. '|' .. args.widget .. ']]</div>\n'
end
docText = '__NOEDITSECTION__\n' .. m .. docText .. '\n'
end
local action = 'Bearbeiten'
local preload = ''
local classes = ''
local message
local category
if noDoc then
action = 'Erstellen'
preload = '&preload=Vorlage:Dokumentationsvorbelegung'
classes = ' documentation-nodoc'
local d
local e
local f
if pageType == 'Vorlage' then d = 'diese ' .. pageType else d = 'dieses ' .. pageType end
if pageType == 'Vorlage' then e = 'die ' .. pageType else e = 'es' end
if pageType == 'Vorlage' then f ='dokumentiere' else f = 'erstelle' end
message = "'''" .. lang:ucfirst(d) .. ' hat keine Dokumentation. ' ..
'Wenn du weißt, wie ' .. e .. ' funktioniert, dann <span class=plainlinks>[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. f .. "]</span> sie bitte.'''"
if not args.demo then
category = 'Kategorie:Fehlende Dokumentation'
end
elseif badDoc then
classes = ' documentation-baddoc'
message = "'''Diese Dokumentation benötigt genauere oder weitere Informationen.'''\n"
if not args.demo then
category = 'Kategorie:Unzureichende Dokumentation'
end
end
local links = {
'<span class=plainlinks>[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']</span>',
'<span class=plainlinks>[' .. docPage:fullUrl( 'action=history' ) .. ' Versionen]</span>',
'<span class=plainlinks>[' .. page:fullUrl( 'action=purge' ) .. ' Aktualisieren]</span>',
modullink
}
if not noDoc and page ~= docPage then
table.insert( links, 1, '[[' .. docPage.fullText .. '|Lesen]]' )
end
links = mw.html.create( 'span' )
:css( 'float', 'right' )
:wikitext( mw.text.nowiki( '[' ), table.concat( links, ' | ' ), mw.text.nowiki( ']' ) )
local body = mw.html.create( 'div' )
body:css{
padding = '0.8em 1em 0.7em',
['margin-top'] = '1em',
clear = 'both'
}
:attr( 'class', 'documentation' .. classes )
local header = mw.html.create( 'div' )
:css{
margin = '-0.8em -1em 0.8em',
padding = '0.8em 1em 0.7em',
['border-bottom'] = 'inherit'
}
:attr( 'class', 'documentation-header' )
header
:node( links )
:tag( 'span' )
:css{
['font-weight'] = 'bold',
['font-size'] = '130%',
['margin-right'] = '1em',
['line-height'] = '1'
}
:wikitext( '[[Datei:Buch und Feder.png|16px|link=]] Dokumentation' )
if not noDoc and pageType ~= 'Vorlage' then
header
:tag( 'span' )
:css( 'white-space', 'nowrap' )
:wikitext( '[[#the-code|Springe zum Quelltext ↴]]' )
elseif pageType == 'Vorlage' then
header
:tag( 'span' )
:addClass( 'helptext' )
:css{
['margin-left'] = '50px',
['white-space'] = 'nowrap'
}
:wikitext( '[[Datei:Achtung.svg|20px|link=]] Zum Gebrauch von Vorlagen siehe die [[Hilfe:Vorlagen|Vorlagen-Hilfe]].' )
end
if pageType == 'Modul' then
header
:tag( 'span' )
:addClass( 'helptext' )
:css{
['margin-left'] = '50px',
['white-space'] = 'nowrap'
}
:wikitext( '[[Datei:Lua logo.svg|20px|link=]] Zum Gebrauch von Lua-Modulen siehe die [[Hilfe:Vorlagen#Lua-Module|Modul-Hilfe]].' )
end
body
:node( header ):done()
:wikitext( message )
:wikitext( docText )
if not noDoc and page ~= docPage then
body
:tag( 'div' )
:css{
margin = '0.7em -1em -0.7em',
['border-top'] = 'inherit',
padding = '0.8em 1em 0.7em',
clear = 'both'
}
:attr( 'class', 'documentation-footer' )
:node( links )
:wikitext( 'Diese Dokumentation ist unter [[' .. docPage.fullText .. ']] zu finden.' )
end
if category then
body:wikitext( '[[', category, ']]' )
end
local anchor = ''
if not noDoc and pageType ~= 'Vorlage' then
anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' )
end
return tostring( body ) .. tostring( anchor )
end
return p