Minecraft Wiki
Registrarse
Advertisement
[Ver | Editar | Purgar]DocumentaciónVer código ↴

Este módulo implementa {{Documentación}}.

Dependencias[]

[Ver | Editar | Purgar]La documentación arriba es transcluída desde Módulo:Documentation/doc.
local p = {}
local defaultDocPage = 'doc'

local getType = function( namespace, page )
	local pageType = 'sta plantilla'
	if namespace == 'Módulo' then
		pageType = 'ste módulo'
	elseif namespace == 'Widget' then
		pageType = 'ste widget'
	elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.css$' ) then
		pageType = 'sta hoja de estilos'
	elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.js$' ) then
		pageType = 'ste script'
	elseif namespace == 'MediaWiki' then
		pageType = 'ste mensaje'
	end
	
	return pageType
end

-- Creating a documentation page or transclusion through {{subst:docc}}
function p.create( f )
	local args = require( 'Módulo:ProcessArgs' ).norm()
	local page = mw.title.getCurrentTitle()
	local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage
	
	local out
	if not args.content and tostring( page ) == docPage then
		out = f:preprocess( '{{subst:Plantilla:Documentación/preload}}' )
	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 = '{{documentación|' .. table.concat( templateArgs, '|' ) .. '}}'
		out = out:gsub( '|}}', '}}' )
		
		if not args.content then
			out = out .. '\n<!-- Coloca las categorías/interwikis en la página de documentación -->'
		end
	end
	
	if not mw.isSubsting() then
		out = f:preprocess( out )
		if not args.nocat then
			out = out .. '[[Categoría:Páginas con plantillas que necesitan sustitución]]'
		end
	end
	
	return out
end

-- Header on the documentation page
function p.docPage( f )
	local args = require( 'Módulo:ProcessArgs' ).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 subpage = page.subpageText
	if subpage == 'sandbox' or subpage == 'testcases' then
		page = page.basePageTitle
	end
	local namespace = page.nsText
	local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
	
	local body = mw.html.create( 'div' ):addClass( 'documentation-header' )
	body
		:addClass( badDoc and 'documentation-badDoc' or '' )
		:css{
			['margin-bottom'] = '0.8em',
			padding = '0.8em 1em 0.7em',
			['background-color'] = '#' .. ( badDoc and 'F9F2EA' or 'EAF4F9' ),
			border = '1px solid #AAA'
		}
		:tag( 'div' )
			:attr( 'id', 'documentation-header-tools' )
			:css( 'float', 'right' )
			:wikitext( '[[', page:fullUrl( 'action=purge' ), ' ' .. f:preprocess('Purgar') .. ']]' )
		:done()
		:wikitext(
			'Esta es la página de documentación. Esta ',
			pageType == 'será' or 'debería',
			' ser transcluida en la página principal de e', pageType, '. ',
			' Véase [[Plantilla:Documentación]] para más información.'
		)
	if badDoc then
		body:wikitext( "<br>'''La documentación de e", pageType, " necesita mejorarse o más información.'''" )
	end
	if not ( args.nocat or namespace == 'User' ) then
		body:wikitext( '[[Categoría:Páginas de documentación]]' )
	end
	
	return body
end

-- Wrapper around the documentation on the main page
function p.page( f )
	-- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings
	local function trim( s )
		return (s:gsub( '^[\t\r\n\f ]+', '' ):gsub( '[\t\r\n\f ]+$', '' ))
		--return string.gsub( s, '^[\t\r\n\f ]*(.-)[\t\r\n\f ]*$', '%1' )
	end
	local args = require( 'Módulo:ProcessArgs' ).merge( true )
	local page = mw.title.getCurrentTitle()
	local subpage = page.subpageText
	if subpage == 'sandbox' or subpage == 'testcases' then
		page = page.basePageTitle
	end
	local namespace = page.nsText
	local docText = 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 .. '/' .. defaultDocPage )
		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 = 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 = f:preprocess('Editar')
	local preload = ''
	local docClass = ''
	local colour = 'EAF4F9'
	local message
	local category
	if noDoc then
		action = f:preprocess('Crear')
		preload = '&preload=Plantilla:Documentación/preload'
		docClass = 'documentation-noDoc'
		colour = 'F9EAEA'
		message = "'''E" .. pageType .. " no tiene documentación. " ..
			"Si sabes cómo crear e" .. pageType .. ", por favor crea su página.'''"
		if not ( args.nocat or namespace == 'User' ) then
			category =  pageType .. 's sin documentación'
			if not mw.title.new( 'Categoría:' .. category ).exists then
				category = 'Páginas sin documentación'
			end
		end
	elseif badDoc then
		docClass = 'documentation-badDoc'
		colour = 'F9F2EA'
		message = "'''La documentación de e" .. pageType .. " necesita mejorarse o más información.'''\n"
		if not ( args.nocat or namespace == 'User' ) then
			category = pageType .. 's con mala documentación'
			if not mw.title.new( 'Categoría:' .. category ).exists then
				category = 'Páginas con mala documentación'
			end
		end
	end
	
	local links = {
		'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']',
		'[' .. page:fullUrl( 'action=purge' ) .. ' ' .. f:preprocess('Purgar') .. ']'
	}
	if not noDoc and page ~= docPage then
		table.insert( links, 1, '[[' .. docPage.fullText .. '|' .. f:preprocess('Ver') .. ']]' )
	end
	links = mw.html.create( 'span' )
		:attr( 'id', 'documentation-header-tools' )
		:css( 'float', 'right' )
		:wikitext( mw.text.nowiki( '[' ), table.concat( links, ' | ' ), mw.text.nowiki( ']' ) )
	
	local body = mw.html.create( 'div' ):addClass( 'documentation' )
	body
		:addClass( docClass )
		:css{
		['background-color'] = 'rgba(147, 218, 255, 0.15)',
		border = '1px solid rgba(175, 175, 175, 0.4)',
		padding = '0.8em 1em 0.7em',
		['margin-top'] = '1em',
		clear = 'both'
	}
	
	local header = mw.html.create( 'div' )
		:addClass( 'documentation-header-top' )
		:css{
			margin = '-0.8em -1em 0.8em',
			padding = '0.8em 1em 0.7em',
			['background-color'] = 'rgba(75, 149, 187, 0.1)',
			['border-bottom'] = 'inherit'
		}
	
	header
		:node( links )
		:tag( 'span' )
			:attr( 'id', 'documentation-header-title' )
			:css{
				['font-weight'] = 'bold',
				['font-size'] = '130%',
				['margin-right'] = '1em',
				['line-height'] = '1'
			}
			:wikitext( 'Documentación' )
	
	local codePages = {
		module = true,
		stylesheet = true,
		script = true,
	}
	if not noDoc and codePages[pageType] then
		header
			:tag( 'span' )
				:attr( 'id', 'documentation-jump-to-code' )
				:css( 'white-space', 'nowrap' )
				:wikitext( '[[#el-código|Ver código ↴]]' )
	end
	
	body
		:node( header ):done()
		:wikitext( message )
		:wikitext( docText )
	
	if not noDoc and page ~= docPage then
		body
			:tag( 'div' )
				:addClass( 'documentation-header-bottom' )
				:css{
					margin = '0.7em -1em -0.7em',
					['background-color'] = 'rgba(75, 149, 187, 0.3)',
					['border-top'] = 'inherit',
					padding = '0.8em 1em 0.7em',
					clear = 'both'
				}
				:node( links )
				:wikitext( 'La documentación arriba es transcluída desde [[', docPage.fullText, ']].' )
	end
	
	if category then
		body:wikitext( f:expandTemplate{ title = 'Translation category', args = { category, project = '0' } } )
	end
	
	local anchor = ''
	if not noDoc and pageType ~= 'sta plantilla' and pageType ~= 'ste mensaje' then
		anchor = mw.html.create( 'div' ):attr( 'id', 'el-código' )
	end
	
	return tostring( body ) .. tostring( anchor )
end

return p
Advertisement