Minecraft Wiki
Advertisement

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


[Ansehen | Bearbeiten | Aktualisieren]Diese Dokumentation ist unter Modul:Dokumentation/Dokumentation zu finden.
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'
	elseif namespace == 'MediaWiki' then
		pageType = 'Nachricht'
	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:Dokumentation/Start}}' )
	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
function p.docPage( f )
	local args = require( 'Modul:ParameterUmwandeln' ).merge( true )
	local badDoc = args.baddoc
	if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then
		if badDoc then
			f:callParserFunction( '#dplvar:set', '$doc bad', '1' )
		end
		return
	end
	
	local page = mw.title.getCurrentTitle()
	local namespace = page.nsText
	local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
	
	local body = mw.html.create( 'div' )
	body
		:css{
			['margin-bottom'] = '0.8em',
			padding = '0.8em 1em 0.7em',
			['background-color'] = '#' .. ( badDoc and 'F9F2EA' or 'EAF4F9' ),
			border = '1px solid #AAA'
		}
		:tag( 'div' )
			:css( 'float', 'right' )
			:wikitext( '[[', page:fullUrl( 'action=purge' ), ' purge]]' )
		:done()
		:wikitext(
			'Dies ist die Dokumentation, sie ',
			pageType == 'Modul' and 'wird' or 'sollte',
			' auf der ', pageType == "Vorlage" and "nseite" or pageType == "Modul" and "seite" or pageType == "Stylesheet" and "seite" or pageType == "Skript" and "seite" or pageType == "Nachricht" and "enseite", ' eingebunden', pageType == "Vorlage" and 'werden', '. ',
			'Siehe [[Vorlage:Dokumentation]] für weitere Informationen.'
		)
	if badDoc then
		body:wikitext( "<br>'''Diese ", pageType == "Vorlage" and "n" or pageType == "Nachricht" and "en" or pageType, "dokumentation muss verbessert werden.'''" )
	end
	if not args.demo then
		body:wikitext( '[[Kategorie:Dokumentation]]' )
	end
	
	return body
end

-- Wrapper around the documentation on the main page
function p.page( f )
	local args = require( 'Modul:ParameterUmwandeln' ).merge( true )
	local page = mw.title.getCurrentTitle()
	local namespace = page.nsText
	local docText = mw.text.trim( args.content or '' )
	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 = mw.ustring.lower( args.type or getType( namespace, page ) )
	
	if not docText and not noDoc then
		f:callParserFunction( '#dplvar:set', '$doc noheader', '1' )
		docText = mw.text.trim( f:expandTemplate{ title = ':' .. docPage.fullText }  )
		if f:callParserFunction( '#dplvar', '$doc bad' ) == '1' then
			badDoc = 1
		end
		
		if docText == '' then
			docText = nil
			noDoc = 1
		end
	end
	if docText then
		docText = '\n' .. docText .. '\n'
	end
	
	local action = 'Bearbeiten'
	local preload = ''
	local colour = 'EAF4F9'
	local message
	local category
	if noDoc then
		action = 'create'
		preload = '&preload=Vorlage:Dokumentation/Start'
		colour = 'F9EAEA'
		message = "'''" .. "Diese " and pageType == "Vorlage" or "Dieses " and pageType == "Modul" or "Dieses " and pageType == "Stylesheet" or "Dieses " and pageType == "Skript" or "Diese " and pageType == "Nachricht" .. " hat keine Dokumentation. " ..
			"Wenn du weißt, wie " .. "diese " and pageType == "Vorlage" or "dieses " and pageType == "Modul" or "dieses " and pageType == "Stylesheet" or "dieses " and pageType == "Skript" or "diese " and pageType == "Nachricht" .. "funktioniert, dann erstelle sie bitte.'''"
		if not args.demo then
			category = 'Kategorie:Vorlagen ohne Dokumentation'
			if not mw.title.new( category ).exists then
				category = 'Kategorie:Vorlagen ohne Dokumentation'
			end
		end
	elseif badDoc then
		colour = 'F9F2EA'
		message = "'''Diese" ..  pageType == "Vorlage" and "n" or pageType == "Modul" and "e" or pageType == "Stylesheet" and "s" or pageType == "Skript" and "s" or pageType == "Nachricht" and "en" .. "dokumentation benötigt genauere oder weitere Informationen.'''\n"
		if not args.demo then
			category = 'Kategorie:Vorlagen mit unzureichender Dokumentation'
			-- if not mw.title.new( category ).exists then
			-- 	category = 'Kategorie:Vorlagen mit unzureichender Dokumentation'
			-- end
		end
	end
	
	local links = {
		'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']',
		'[' .. page:fullUrl( 'action=purge' ) .. ' Aktualisieren]'
	}
	if not noDoc and page ~= docPage then
		table.insert( links, 1, '[[' .. docPage.fullText .. '|Ansehen]]' )
	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{
		['background-color'] = '#' .. colour,
		border = '1px solid #AAA',
		padding = '0.8em 1em 0.7em',
		['margin-top'] = '1em',
		clear = 'both'
	}
	
	local header = mw.html.create( 'div' )
		:css{
			margin = '-0.8em -1em 0.8em',
			padding = '0.8em 1em 0.7em',
			['background-color'] = '#EAF4F9',
			['border-bottom'] = 'inherit'
		}
	
	header
		:node( links )
		:tag( 'span' )
			:css{
				['font-weight'] = 'bold',
				['font-size'] = '130%',
				['margin-right'] = '1em',
				['line-height'] = '1'
			}
			:wikitext( 'Dokumentation' )
	
	if not noDoc and pageType ~= 'Vorlage' and pageType ~= 'Nachricht' then
		header
			:tag( 'span' )
				:css( 'white-space', 'nowrap' )
				:wikitext( '[[#the-code|Springe zum Quelltext ↴]]' )
	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',
					['background-color'] = '#EAF4F9',
					['border-top'] = 'inherit',
					padding = '0.8em 1em 0.7em',
					clear = 'both'
				}
				: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' and pageType ~= 'Nachricht' then
		anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' )
	end
	
	return tostring( body ) .. tostring( anchor )
end

return p
Advertisement