Warning.png

Поддержка Wiki прекращена, она доступна в режиме архива. Информация в ней устарела и может быть неактуальной.

Модуль:Документация

Материал из Hilarious Wiki
Версия от 11:36, 5 августа 2016; MailGik (обсуждение | вклад) (Отмена правки 411, сделанной участником MailGik (обс.))

(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск
Документация

Этот модуль необходим для работы шаблонов {{Документация}} и {{Документация/Шапка}}

Расположенная выше документация включена из Модуль:Документация/док.

local p = {}
-- Creating a documentation page or transclution through {{subst:doc}}
function p.create( f )
	local args = require( 'Модуль:ProcessArgs' ).norm()
	page = mw.title.getCurrentTitle()
	namespace = args['тип'] or page.nsText
	docPage = args['страница'] or namespace .. ':' .. page.baseText .. '/док'
	
	local out
	if page.fullText == docPage then
		out = f:preprocess( '{{subst:Шаблон:Документация/Предзагрузка}}' )
	else
		local templateArgs = {}
		if args['тип'] then
			table.insert( templateArgs, 'тип=' .. args['тип'] )
		end
		if args['страница'] then
			table.insert( templateArgs, 'страница=' .. args['страница'] )
		end
		
		out = '{{Документация|' .. table.concat( templateArgs, '|' ) .. '}}\n<!-- Размещайте категории/интервики на странице документации -->'
		out = out:gsub( '|}}', '}}' )
	end
	
	if not mw.isSubsting() then
		out = f:preprocess( out )
		if not args['некат'] then
			out = out .. '[[Категория:Страницы с требующими подстановки шаблонами]]'
		end
	end
	
	return out
end

-- Header on the documentation page
function p.docPage(f)
	local args = require( 'Модуль:ProcessArgs' ).merge( true )
	local badDoc = args['плохдок']
	if f:callParserFunction( '#dplvar:noheader' ) == '1' then
		if badDoc then
			f:callParserFunction( '#dplvar:set', 'baddoc', '1' )
		end
		return ''
	end
	local page = mw.title.getCurrentTitle()
	local namespace = args['тип'] or page.nsText
	local pageType = 'этого шаблона'
	local pageType2 = 'этот шаблон'
	local pageType3 = 'Шаблоны'

	if namespace == 'Модуль' then
		pageType = 'этого модуля'
		pageType2 = 'этот модуль'
		pageType3 = 'Модули'
	elseif page.fullText:find( '.css$' ) then
		pageType = 'этой таблицы стилей'
		pageType2 = 'эту таблицу стилей'
		pageType3 = 'Таблицы стилей'
	elseif page.fullText:find( '.js$' ) then
		pageType = 'этого скрипта'
		pageType2 = 'этот скрипт'
		pageType3 = 'Скрипты'
	elseif namespace == 'MediaWiki' then
		pageType = 'этого сообщения'
		pageType2 = 'это сообщение'
		pageType3 = 'Сообщения'
	end

	local colour = '161619'
	local message = ''
	if badDoc then
		colour = '1b1814'
		message = "'''Документация " .. pageType .. " была отмечена как плохая. Пожалуйста, дополните или улучшите её.'''"
	end
	
	local certainty = 'её следует включить'
	if pageType2 == 'этот модуль' then
		certainty = 'она будет включена'
	end
	
	local category = ''
	if not args['некат'] then
		category = '[[Категория:Страницы документации]]'
	end
	
	local out = table.concat( {
		'<div style="margin-bottom: 0.8em; padding: 0.8em 1em 0.7em; background-color: #' .. colour .. '; border: 1px solid #505050">',
		'<div style="float: right">[[' .. page:fullUrl( 'action=purge' ) .. ' обновить]]</div>',
			'<p style="margin: 0">Это страница документации, ' .. certainty .. ' в основную страницу ' .. pageType .. '. Для дополнительной информации см. [[Шаблон:Документация]].</p>',
			message,
		'</div>',
		category
	}, '\n' )
	
	return mw.text.trim( out )
end

-- Wrapper around the documentation on the main page
function p.page( f )
	local args = require( 'Модуль:ProcessArgs' ).merge( true )	
	local page = mw.title.getCurrentTitle()
	local namespace = args['тип'] or page.nsText
	local docPage = mw.title.new( args['страница'] or namespace .. ':' .. page.text .. '/док' )
	local noDoc = args['нетдок'] or not docPage.exists
	local badDoc = args['плохдок']

	local pageType = 'этого шаблона'
	local pageType2 = 'этот шаблон'
	local pageType3 = 'Шаблоны'

	if namespace == 'Модуль' then
		pageType = 'этого модуля'
		pageType2 = 'этот модуль'
		pageType3 = 'Модули'
	elseif page.fullText:find( '.css$' ) then
		pageType = 'этой таблицы стилей'
		pageType2 = 'эту таблицу стилей'
		pageType3 = 'Таблицы стилей'
	elseif page.fullText:find( '.js$' ) then
		pageType = 'этого скрипта'
		pageType2 = 'этот скрипт'
		pageType3 = 'Скрипты'
	elseif namespace == 'MediaWiki' then
		pageType = 'этого сообщения'
		pageType2 = 'это сообщение'
		pageType3 = 'Сообщения'
	end

	local docText = ''

	if not noDoc then
		f:callParserFunction( '#dplvar:set', 'noheader', '1' )
		docText = mw.text.trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
		if f:callParserFunction( '#dplvar:baddoc' ) == '1' then
			badDoc = 1
		end

		if docText == '' then
			noDoc = 1
		else
			docText = '\n' .. docText .. '\n'
		end
	end
	
	local action = 'править'
	local preload = ''
	local colour = '161619'
	local message = ''
	local category = ''
	if noDoc then
		action = 'создать'
		preload = '&preload=Шаблон:Документация/Предзагрузка'
		colour = '161619'
		message = "'''У " .. pageType .. " нет документации. Если вы знаете, как использовать " .. pageType2 .. ", пожалуйста, добавьте соответствующую информацию.'''"
		if not args['некат'] then
			if mw.title.new( 'Категория:' .. pageType3 .. ' без документации' ).exists then
				category = '[[Категория:' .. pageType3 .. ' без документации]]'
			else
				category = '[[Категория:Страницы без документации]]'
			end
		end
	elseif badDoc then
		colour = '1b1814'
		message = "'''Документация " .. pageType .. " была отмечена как плохая. Пожалуйста, дополните или улучшите её.'''\n"
		if not args['некат'] then
			if mw.title.new( 'Категория:' .. pageType3 .. ' с плохой документацией' ).exists then
				category = '[[Категория:' .. pageType3 .. ' с плохой документацией]]'
			else
				category = '[[Категория:Страницы с плохой документацией]]'
			end
		end
	end
	
	local links = {
		'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']',
		'[' .. page:fullUrl( 'action=purge' ) .. ' обновить]'
	}
	local footer = ''
	if not noDoc then
		table.insert( links, 1, '[[' .. docPage.fullText .. '|просмотр]]' )
		footer = table.concat( {
			'<div style="margin: 0.7em -1em -0.7em; background-color: #252527; border-top: 1px solid #505050; padding: 0.8em 1em 0.7em; clear: both">\n',
				'<div style="float: right">' .. mw.text.nowiki( '[' ) .. table.concat( links, ' | ' ) .. ']</div>\n',
				'<p style="margin: 0">Расположенная выше документация включена из [[' .. docPage.fullText .. ']].</p>\n',
			'</div>\n'
		} )
	end
	
	local out = {
		'<div style="background-color: #' .. colour .. '; border: 1px solid #505050; padding: 0.8em 1em 0.7em; clear: both">\n',
			'<div style="margin: -0.8em -1em 0.8em; padding: 0.8em 1em 0.7em; background-color: #252527; border-bottom: 1px solid #505050">\n',
				'<div style="float: right">' .. mw.text.nowiki( '[' ) .. table.concat( links, ' | ' ) .. ']</div>\n',
				'<span style="font-weight: bold; font-size: 130%">Документация</span>',
			'</div>\n',
			message,
			docText,
			footer,
		'</div>\n',
		category
	}
	
	return mw.text.trim( table.concat( out ) )
end
return p