模块:Documentation
来自INFWiki
更多操作
-- <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' }
)
return tostring( ret )
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( '以下是模板的文档,点击右侧按钮去编辑文档' )
:done()
:wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } )
:done()
ret3 = {}
return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )
end
return p
-- </nowiki>