打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Documentation:修订间差异

来自INFWiki
9Yan留言 | 贡献
无编辑摘要
9Yan留言 | 贡献
无编辑摘要
第52行: 第52行:
             cats = '[[Category:' .. string.format( t( 'category_documentation' ), t( 'category_' .. pageType ) ) .. '|' .. title.baseText .. ']]'
             cats = '[[Category:' .. string.format( t( 'category_documentation' ), t( 'category_' .. pageType ) ) .. '|' .. title.baseText .. ']]'
             ret2 = dependencyList._main()
             ret2 = dependencyList._main()
        elseif title.namespace == 828 then -- Module namespace
            cats = '[[Category:' .. string.format( t( 'category_documentation' ), t( 'category_' .. pageType ) ) .. '|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
            ret2 = ret2 .. require('Module:Module toc').main()
        else
            cats = ''
            ret2 = ''
         end
         end


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



2025年8月3日 (日) 19:55的版本

文档标题[查看][编辑][历史][刷新]
message_transclude_desc
Function list
L 15 — t
L 25 — translate
L 36 — p.doc

Module:Documentation 为模板和模块实现 Template:Documentation


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


--- Wrapper function for Module:i18n.translate
---
--- @param key string The translation key
--- @return string If the key was not found, the key is returned
local function t( key )
	return i18n:translate( key )
end


--- 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 string.gsub( title.fullText, '/[Dd]o[ck]u?$', '' )
    local ret, cats, ret1, ret2, ret3
    local pageType = title.namespace == 828 and 'Module' or 'Template'

    -- subpage header
    if title.subpageText == 'doc' then
		ret = mbox(
			'这是模板的文档子页面',
			'它包含使用信息以及其他不属于模板页面的内容。',
			{ icon = 'WikimediaUI-Notice.svg' }
    	)

        if title.namespace == 10 then -- Template namespace
            cats = '[[Category:' .. string.format( t( 'category_documentation' ), t( 'category_' .. pageType ) ) .. '|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
        elseif title.namespace == 828 then -- Module namespace
            cats = '[[Category:' .. string.format( t( 'category_documentation' ), t( 'category_' .. pageType ) ) .. '|' .. 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( '文档标题' )
                :done()
            :tag( 'span' )
                :addClass( 'documentation-links plainlinks' )
                :wikitext(
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' 查看]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' 编辑]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' 历史]]' ..
                    '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, { action = '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 = {}

    --- 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>