Открыть меню
Открыть персональное меню
Вы не представились системе
Your IP address will be publicly visible if you make any edits.

Модуль:Documentation: различия между версиями

Материал из Энциклопедия Тренерон
Нет описания правки
м (1 версия импортирована)
 
(не показана 1 промежуточная версия 1 участника)
Строка 1: Строка 1:
-- <nowiki>
-- <nowiki>
local dependencyList = require( 'Module:DependencyList' )
local dependencyList = require( 'Module:DependencyList' )
local yn = require( 'Module:Yesno' )
local hatnote = require( 'Module:Hatnote' )._hatnote
local hatnote = require( 'Module:Hatnote' )._hatnote
local mbox = require( 'Module:Mbox' )._mbox
local mbox = require( 'Module:Mbox' )._mbox
local TNT = require( 'Module:Translate' ):new()
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()
local p = {}
local p = {}
--- FIXME: This should go to somewhere else, like Module:Common
--- Calls TNT with the given key
---
--- @param key string The translation key
--- @return string If the key was not found in the .tab page, the key is returned
local function translate( key, ... )
local success, translation = pcall( TNT.format, 'Module:Documentation/i18n.json', key or '', ... )
if not success or translation == nil then
return key
end
return translation
end


function p.doc( frame )
function p.doc( frame )
     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()
     local args = frame:getParent().args
     local args = frame:getParent().args
     local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
     local page = args[1] or mw.ustring.gsub( title.fullText, '/[Dd]o[ck]u?$', '' )
     local ret, cats, ret1, ret2, ret3
     local ret, cats, ret1, ret2, ret3
     local pageType = title.namespace == 828 and 'module' or 'template'
     local pageType = title.namespace == 828 and translate( 'module' ) or translate( 'template' )
   
 
    local opts = frame.args;
   
     -- subpage header
     -- subpage header
     if title.subpageText == 'doc' then
     if title.subpageText == 'doc' then
ret = mbox(
ret = mbox(
'This is a documentation subpage for ' .. page .. '.',
translate( 'message_subpage_title', page ),
string.format(
translate( 'message_subpage_desc', page, pageType ),
'It contains usage information, categories, and other content that is not part of the [[' .. page .. '|original %s page]].',
pageType
),
{ icon = 'WikimediaUI-Notice.svg' }
{ icon = 'WikimediaUI-Notice.svg' }
     )
     )


         if title.namespace == 10 then -- Template namespace
         if title.namespace == 10 then -- Template namespace
             cats = '[[Category:Документация шаблонов|' .. title.baseText .. ']]'
             cats = '[[Category:' .. translate( 'category_template_documentation' ) .. '|' .. title.baseText .. ']]'
             ret2 = dependencyList._main()
             ret2 = dependencyList._main()
         elseif title.namespace == 828 then -- Module namespace
         elseif title.namespace == 828 then -- Module namespace
             cats = '[[Category:Документация модулей|' .. title.baseText .. ']]'
             cats = '[[Category:' .. translate( 'category_module_documentation' ) .. '|' .. title.baseText .. ']]'
             ret2 = dependencyList._main()
             ret2 = dependencyList._main()
             ret2 = ret2 .. require('Module:Module toc').main()
             ret2 = ret2 .. require('Module:Module toc').main()
Строка 41: Строка 53:
         return tostring( ret ) .. ret2 .. cats
         return tostring( ret ) .. ret2 .. cats
     end
     end
   
 
     -- template header
     -- template header
     -- don't use mw.html as we aren't closing the main div tag
     -- don't use mw.html as we aren't closing the main div tag
Строка 51: Строка 63:
             :tag( 'span' )
             :tag( 'span' )
                 :addClass( 'documentation-title' )
                 :addClass( 'documentation-title' )
                 :wikitext( lang:ucfirst( string.format('%s documentation', pageType) ) )
                 :wikitext( lang:ucfirst( translate('message_documentation_title', pageType ) ) )
                 :done()
                 :done()
             :tag( 'span' )
             :tag( 'span' )
Строка 59: Строка 71:
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
                     '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]'
                     '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, { action = 'purge' } ) ) .. ' purge]</span>]'
                 )
                 )
                 :done()
                 :done()
Строка 67: Строка 79:
             :tag( 'span' )
             :tag( 'span' )
                 :addClass( 'documentation-documentation' )
                 :addClass( 'documentation-documentation' )
                 :wikitext( 'This documentation is transcluded from [[' .. page .. '/doc]]. Changes can be proposed in the talk page.' )
                 :wikitext( translate( 'message_transclude_desc', page ) )
                 :done()
                 :done()
             :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Documentation/styles.css'} })
             :wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } )
             :done()
             :done()


Строка 78: Строка 90:
     table.insert( ret3,
     table.insert( ret3,
     mbox(
     mbox(
    string.format(
    translate(
"'''%s''' is [%s%s shared across] the Star Citizen Wikis.",
'message_shared_across',
title.fullText,
title.fullText,
'https://github.com/The-Star-Citizen-Wikis/SharedModules/tree/master/',
mw.uri.encode( title.rootText, 'PATH' )
title.rootText
),
),
string.format(
translate(
'This %s is shared across the Star Citizen Wikis. Any changes should also be relayed to the GitHub repository.',
'message_shared_across_subtext',
pageType
pageType
),
),
Строка 92: Строка 103:
  )
  )
  --- Set category
  --- Set category
  table.insert( ret3, string.format( '[[Category:%s shared by the Star Citizen Wikis]]', lang:ucfirst( pageType ) .. 's' ) )
  table.insert( ret3, '[[Category:' .. translate( 'category_shared_across', lang:ucfirst( pageType ) ) .. ']]' )
  --- Interlanguage link
--- Interlanguage link
  --- TODO: Make this into a for loop when there are more wikis
--- TODO: Make this into a for loop when there are more wikis
  table.insert( ret3, string.format( '[[%s:%s]]', 'de', title.fullText ) )
for _, code in pairs{ 'de', 'en' } do
if lang:getCode() ~= code then
    table.insert( ret3, string.format( '[[%s:%s]]', code, title.fullText ) )
end
end
     end
     end


Строка 101: Строка 116:
     table.insert( ret3,
     table.insert( ret3,
     mbox(
     mbox(
    string.format(
    translate(
"'''%s''' is imported from [https://en.wikipedia.org/wiki/%s %s] on Wikipedia.",
'message_from_wikipedia',
title.fullText,
title.fullText,
page,
mw.uri.encode( page, 'WIKI' ),
page
page
),
),
string.format(
translate(
'This %s is imported from the English Wikipedia. Although the visual appearance might be different, the functionality is identical. Please refer to the Wikipedia page for detailed documentation.',
'message_from_wikipedia_subtext',
pageType
pageType
),
),
Строка 115: Строка 130:
  )
  )
  --- Set category
  --- Set category
  table.insert( ret3, string.format( '[[Category:%s импортированно из Википедии]]', lang:ucfirst( pageType ) .. 's' ) )
  table.insert( ret3, '[[Category:' .. translate( 'category_from_wikipedia', lang:ucfirst( pageType ) ) .. ']]' )
     end
     end
   
 
     if title.namespace == 828 then
     if title.namespace == 828 then
     -- Has config
     -- Has config
Строка 123: Строка 138:
table.insert( ret3,
table.insert( ret3,
mbox(
mbox(
    string.format(
    translate(
    "'''%s''' loads configuration from [[%s/config.json]].",
    'message_module_configuration',
    title.fullText,
    title.fullText,
    title.fullText
    title.fullText
    ),
    ),
    'This module can be configurated from the config.json subpage.',
    translate( 'message_module_configuration_subtext' ),
    { icon='WikimediaUI-Settings.svg' }
    { icon = 'WikimediaUI-Settings.svg' }
    )
    )
)
)
Строка 138: Строка 153:
table.insert( ret3,
table.insert( ret3,
mbox(
mbox(
    string.format(
    translate(
    "'''%s''' loads messages from [[%s/i18n.json]].",
    'message_module_i18n',
    title.fullText,
    title.fullText,
    title.fullText
    title.fullText
    ),
    ),
    'This module is designed to be language-neutral. All of the messages are saved in the i18n.json subpage.',
    translate( 'message_module_i18n_subtext' ),
    { icon='WikimediaUI-Language.svg' }
    { icon = 'WikimediaUI-Language.svg' }
    )
    )
)
)
Строка 153: Строка 168:
     table.insert( ret3,
     table.insert( ret3,
    hatnote(
    hatnote(
    string.format( 'This is the test cases page for the module [[Module:%s]].', title.baseText ),
    translate( 'message_module_tests', title.baseText ),
    { icon='WikimediaUI-LabFlask.svg' }
    { icon = 'WikimediaUI-LabFlask.svg' }
    )
    )
    )
    )
end
end
table.insert( ret3, string.format( '[[Category:%s]]', translate( 'category_module' ) ) )
     end
     end
   
 
     --- Dependency list
     --- Dependency list
     table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) )
     table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) )
   
 
     -- Has templatestyles
     -- Has templatestyles
if mw.title.new( title.fullText .. '/styles.css' ).exists then
if mw.title.new( title.fullText .. '/styles.css' ).exists then
table.insert( ret3,
table.insert( ret3,
hatnote(
hatnote(
    string.format(
    translate( 'message_styles', title.fullText, title.fullText ),
    "'''%s''' loads styles from [[%s/styles.css]].",
    { icon = 'WikimediaUI-Palette.svg' }
    title.fullText,
    title.fullText
    ),
    { icon='WikimediaUI-Palette.svg' }
    )
    )
)
)
end
end
   
 
     --- Module stats bar
     --- Module stats bar
     if title.namespace == 828 then
     if title.namespace == 828 then
Строка 183: Строка 196:
-- Function list
-- Function list
table.insert( ret3, require( 'Module:Module toc' ).main() )
table.insert( ret3, require( 'Module:Module toc' ).main() )
 
-- Unit tests
-- Unit tests
local testcaseTitle = title.baseText .. '/testcases'
local testcaseTitle = title.baseText .. '/testcases'
Строка 190: Строка 203:
table.insert( ret3, frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' ) )
table.insert( ret3, frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' ) )
     end
     end
 
     table.insert( ret3, '</div>' )
     table.insert( ret3, '</div>' )
     end
     end
       
 
     return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )
     return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )
end
end

Текущая версия от 17:01, 28 февраля 2024

Для документации этого модуля может быть создана страница Модуль:Documentation/doc

-- <nowiki>
local dependencyList = require( 'Module:DependencyList' )
local hatnote = require( 'Module:Hatnote' )._hatnote
local mbox = require( 'Module:Mbox' )._mbox
local TNT = require( 'Module:Translate' ):new()
local lang = mw.getContentLanguage()
local p = {}


--- FIXME: This should go to somewhere else, like Module:Common
--- Calls TNT with the given key
---
--- @param key string The translation key
--- @return string If the key was not found in the .tab page, the key is returned
local function translate( key, ... )
	local success, translation = pcall( TNT.format, 'Module:Documentation/i18n.json', key or '', ... )

	if not success or translation == nil then
		return key
	end

	return translation
end


function p.doc( frame )
    local title = mw.title.getCurrentTitle()
    local args = frame:getParent().args
    local page = args[1] or mw.ustring.gsub( title.fullText, '/[Dd]o[ck]u?$', '' )
    local ret, cats, ret1, ret2, ret3
    local pageType = title.namespace == 828 and translate( 'module' ) or translate( 'template' )

    -- subpage header
    if title.subpageText == 'doc' then
		ret = mbox(
			translate( 'message_subpage_title', page ),
			translate( 'message_subpage_desc', page, pageType ),
			{ icon = 'WikimediaUI-Notice.svg' }
    	)

        if title.namespace == 10 then -- Template namespace
            cats = '[[Category:' .. translate( 'category_template_documentation' ) .. '|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
        elseif title.namespace == 828 then -- Module namespace
            cats = '[[Category:' .. translate( 'category_module_documentation' ) .. '|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
            ret2 = ret2 .. require('Module:Module toc').main()
        else
            cats = ''
            ret2 = ''
        end

        return tostring( ret ) .. ret2 .. cats
    end

    -- template header
    -- don't use mw.html as we aren't closing the main div tag
    ret1 = '<div class="documentation">'

    ret2 = mw.html.create( nil )
        :tag( 'div' )
            :addClass( 'documentation-header' )
            :tag( 'span' )
                :addClass( 'documentation-title' )
                :wikitext( lang:ucfirst( translate('message_documentation_title', pageType ) ) )
                :done()
            :tag( 'span' )
                :addClass( 'documentation-links plainlinks' )
                :wikitext(
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' view]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
                    '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, { action = 'purge' } ) ) .. ' purge]</span>]'
                )
                :done()
            :done()
        :tag( 'div' )
            :addClass( 'documentation-subheader' )
            :tag( 'span' )
                :addClass( 'documentation-documentation' )
                :wikitext( translate( 'message_transclude_desc', page ) )
                :done()
            :wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } )
            :done()

    ret3 = {}

    if args.scwShared then
    	--- Message box
    	table.insert( ret3,
    		mbox(
	    		translate(
					'message_shared_across',
					title.fullText,
					mw.uri.encode( title.rootText, 'PATH' )
				),
				translate(
					'message_shared_across_subtext',
					pageType
				),
				{ icon = 'WikimediaUI-ArticleDisambiguation-ltr.svg' }
			)
	   )
	   --- Set category
	   table.insert( ret3, '[[Category:' .. translate( 'category_shared_across', lang:ucfirst( pageType ) ) .. ']]' )
		--- Interlanguage link
		--- TODO: Make this into a for loop when there are more wikis
		for _, code in pairs{ 'de', 'en' } do
			if lang:getCode() ~= code then
	    		table.insert( ret3, string.format( '[[%s:%s]]', code, title.fullText ) )
			end
		end
    end

    if args.fromWikipedia then
    	table.insert( ret3,
    		mbox(
	    		translate(
					'message_from_wikipedia',
					title.fullText,
					mw.uri.encode( page, 'WIKI' ),
					page
				),
				translate(
					'message_from_wikipedia_subtext',
					pageType
				),
				{ icon = 'WikimediaUI-Logo-Wikipedia.svg' }
			)
	   )
	   --- Set category
	   table.insert( ret3, '[[Category:' .. translate( 'category_from_wikipedia', lang:ucfirst( pageType ) ) .. ']]' )
    end

    if title.namespace == 828 then
    	-- Has config
    	if mw.title.new( title.fullText .. '/config.json', 'Module' ).exists then
			table.insert( ret3,
				mbox(
		    		translate(
		    			'message_module_configuration',
		    			title.fullText,
		    			title.fullText
		    		),
		    		translate( 'message_module_configuration_subtext' ),
		    		{ icon = 'WikimediaUI-Settings.svg' }
		    	)
			)
    	end

    	-- Has localization
    	if mw.title.new( title.fullText .. '/i18n.json', 'Module' ).exists then
			table.insert( ret3,
				mbox(
		    		translate(
		    			'message_module_i18n',
		    			title.fullText,
		    			title.fullText
		    		),
		    		translate( 'message_module_i18n_subtext' ),
		    		{ icon = 'WikimediaUI-Language.svg' }
		    	)
			)
    	end

    	-- Testcase page
    	if title.subpageText == 'testcases' then
    		table.insert( ret3,
		    	hatnote(
		    		translate( 'message_module_tests', title.baseText ),
		    		{ icon = 'WikimediaUI-LabFlask.svg' }
		    	)
		    )
		end

		table.insert( ret3, string.format( '[[Category:%s]]', translate( 'category_module' ) ) )
    end

    --- Dependency list
    table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) )

    -- Has templatestyles
	if mw.title.new( title.fullText .. '/styles.css' ).exists then
		table.insert( ret3,
			hatnote(
	    		translate( 'message_styles', title.fullText, title.fullText ),
	    		{ icon = 'WikimediaUI-Palette.svg' }
	    	)
		)
	end

    --- Module stats bar
    if title.namespace == 828 then
		table.insert( ret3, '<div class="documentation-modulestats">' )

		-- Function list
		table.insert( ret3, require( 'Module:Module toc' ).main() )

		-- Unit tests
		local testcaseTitle = title.baseText .. '/testcases'
		if mw.title.new( testcaseTitle, 'Module' ).exists then
			-- There is probably a better way :P
			table.insert( ret3, frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' ) )
    	end

    	table.insert( ret3, '</div>' )
    end

    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )
end

return p

-- </nowiki>