纂
模組:Documentation
跳至導覽
跳至搜尋
警示:
子未登簿,若確纂,IP將誌。茍
登
或
開戶口
,是纂欲存以子名,及他效。
反亂查。
勿
是文入!
local p = {} -- Load modules (language wikis exclusive) -- ... -- Customizable strings local i18n = { -- default settings, change when necessary defaultDocPage = 'doc', -- documentation page suffix defaultSandboxPage = 'sandbox', -- sandbox page suffix defaultTestCasePage = 'testcases', -- testcases page suffix defaultPreload = 'Template:Documentation/preload', -- page that stores qualified documentation page contents defaultStyles = 'Template:Documentation/styles.css', -- stylesheet for this module when using TemplateStyles, remove or set to nil if your wiki not use this -- format strings, should not be translated commonInternalLink = '[[%s]]', commonInternalLinkPipe = '[[%s|%s]]', commonExternalLink = '[%s]', commonExternalLinkWithName = '[%s %s]', commonNamespacedPage = '%s:%s', commonNamespacedPageWithSub = '%s:%s/%s', -- namespace names, translate if your language prefers localized namespace name, although remain it untouched most likely not affect anything namespaceCategory = '分類', namespaceSpecial = '特殊', namespaceUser = '使用者', -- names of special pages, translate if your language prefers localized namespace name, although remain it untouched will still correctly linked to target page specialPurge = 'Purge', specialEdit = 'EditPage', specialHistory = 'PageHistory', -- translate following types if your language displays differ pageType_template = '模', pageType_module = '模組', pageType_widget = '器', pageType_stylesheet = '樣表', pageType_script = '腳本', pageType_message = '訊', -- modify them if your wiki use different style to displaying links linkBar = mw.text.nowiki( '[ ' ) .. '%s' .. mw.text.nowiki( ' ]' ), -- format used for whole link bar linkFormat = '%s', -- format used for each individual links linkSeparator = mw.text.nowiki( mw.getCurrentFrame():callParserFunction( 'int:pipe-separator' ) ), -- separator between links -- name of different type of links, change them if necessary linkTextPurge = mw.getCurrentFrame():callParserFunction( 'int:purge' ), linkTextView = mw.getCurrentFrame():callParserFunction( 'int:view' ), linkTextEdit = mw.getCurrentFrame():callParserFunction( 'int:edit' ), linkTextHistory = mw.getCurrentFrame():callParserFunction( 'int:history_short' ), linkTextCreate = mw.getCurrentFrame():callParserFunction( 'int:create' ), -- strings used in p.create(): contents shown when using {{doc}} or {{subst:doc}} createOutputFormat = '<noinclude>%s%s</noinclude>', -- overall format createSplitDocPagePrompt = '\n<!-- 請釋類、語二連於案文也 -->', -- this string is shown when a separate documentation page is created createNoSubstCategory = '須代模板之文', -- tracking category for using {{doc}} without substitution -- strings used in p.docPage(): contents shown in documentation page docPagePrompt = '此乃案文,其%s為置於%s,閱[[模板:Documentation]]以膺詳訊。', -- message shown as documentation header in documentation pages. Params: word used when page is a module or not; code page's type docPagePromptWill = '將', -- word used when code page is a module page docPagePromptShould = '應', -- word used when code is not a module page docPageBadDocPrompt = "<br>'''此%s案文待良或增訊。'''", -- additional message if a documentation page marked as baddoc docPageCategory = '案文', -- tracking category for documentation pages -- strings used in p.page(): contents shown in code page pageNoDocPrompt = "'''此%s無案文。若汝知此%s用法,請助立案文于之。'''", -- message shown when a separate documentation page is not exist, both parameters refers to page type pageNoDocCategory = '無案之%s', -- tracking category for pages without documentation, parameters refers to page type pageNoDocCategoryDefault = '無案之文', -- fallback tracking category for pages without documentation pageBadDocPrompt = "'''此%s案文待良或增訊。'''\n", -- message shown when a documentation page marked as baddoc, both parameters refers to page type pageBadDocCategory = '案品較惡之%s', -- tracking category for pages marked as baddoc, parameters refers to page type pageBadDocCategoryDefault = '案品較惡之文', -- fallback tracking category for pages marked as baddoc pageDocHeaderTitle = '案文', -- message shown as the title of the documentation header pageDocJumpToCode = '往碼 ↴', -- text of the link to jump to the code pageDocHeaderBottom = '是案引於%s。', -- message shown as the bottom line of the documentation header } -- Customizable functions local function pageCategoryHandler( category ) return i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( i18n.namespaceCategory, category ) ) end -- Load modules local loadStyles = require( 'Module:TSLoader' ).call local static = require( 'Module:Static' ) if not static.Documentation then static.Documentation = {} end -- Internal functions local function getType( namespace, page ) local pageType = 'template' if namespace == 'Module' then pageType = 'module' elseif namespace == 'Widget' then pageType = 'widget' elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.css$' ) then pageType = 'stylesheet' elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.js$' ) then pageType = 'script' elseif namespace == 'MediaWiki' then pageType = 'message' end return pageType end local function getDisplayType( pageType ) return i18n[ 'pageType_' .. pageType ] or i18n.pageType_template end -- Exported functions function p.create( f ) -- Creating a documentation page or transclusion through {{subst:doc}} local args = require( 'Module:ProcessArgs' ).norm() local page = mw.title.getCurrentTitle() local docPage = args.page or i18n.commonNamespacedPageWithSub:format( page.nsText, page.baseText, i18n.defaultDocPage ) local out if not args.content and tostring( page ) == docPage then local pageType = mw.ustring.lower( args.type or getType( page.nsText, page ) ) local pageTypeDisplay = getDisplayType( pageType ) out = f:preprocess( mw.title.new( i18n.defaultPreload ):getContent():gsub( '$1' , pageTypeDisplay ) ) else local templateArgs = {} for _, key in ipairs{ 'type', 'page', 'content', 'nodoc', 'baddoc' } 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 = '{{documentation|' .. table.concat( templateArgs, '|' ) .. '}}' out = out:gsub( '|}}', '}}' ) out = i18n.createOutputFormat:format( out, args.content and '' or i18n.createSplitDocPagePrompt ) end if not mw.isSubsting() then out = f:preprocess( out ) if not args.nocat then out = out .. i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( i18n.namespaceCategory, i18n.createNoSubstCategory ) ) end end return out end function p.docPage( f ) -- Header on the documentation page local args = require( 'Module:ProcessArgs' ).merge( true ) local badDoc = args.baddoc mw.logObject( badDoc, 'Module:Documentation: badDoc' ) if badDoc then static.Documentation.badDoc = '1' end local page = mw.title.getCurrentTitle() local subpage = page.subpageText if subpage == i18n.defaultSandboxPage or subpage == i18n.defaultTestCasePage then page = page.basePageTitle end local docPage = mw.title.new( args.page or i18n.commonNamespacedPageWithSub:format( page.nsText, page.baseText, i18n.defaultDocPage ) ) mw.logObject( docPage, 'Module:Documentation: docPage' ) mw.logObject( page, 'Module:Documentation: page' ) if docPage ~= page then return end local namespace = page.nsText local pageType = mw.ustring.lower( args.type or getType( namespace, page ) ) local pageTypeDisplay = getDisplayType( pageType ) local body = mw.html.create( 'div' ):addClass( 'documentation' ) body :addClass( badDoc and 'documentation-badDoc' or '' ) :tag( 'div' ) :attr( 'id', 'documentation-header-tools' ) :wikitext( i18n.linkBar:format( i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialPurge, page.fullText ), i18n.linkTextPurge ) ) ) ) :done() :wikitext( i18n.docPagePrompt:format( pageType == 'module' and i18n.docPagePromptWill or i18n.docPagePromptShould, i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( namespace, page.baseText ) ) ) ) if badDoc then body:wikitext( i18n.docPageBadDocPrompt:format( pageTypeDisplay ) ) end if not ( args.nocat or namespace == i18n.namespaceUser ) then body:wikitext( i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( i18n.namespaceCategory, i18n.docPageCategory ) ) ) end mw.logObject( body, 'Module:Documentation: body' ) return loadStyles( i18n.defaultStyles ) .. tostring( body ) end function p.page( f ) -- Wrapper around the documentation on the main page -- 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( 'Module:ProcessArgs' ).merge( true ) local page = mw.title.getCurrentTitle() local subpage = page.subpageText if subpage == i18n.defaultSandboxPage or subpage == i18n.defaultTestCasePage 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 i18n.commonNamespacedPageWithSub:format( namespace, page.text, i18n.defaultDocPage ) ) noDoc = args.nodoc or not docPage.exists end local badDoc = args.baddoc local pageType = mw.ustring.lower( args.type or getType( namespace, page ) ) local pageTypeDisplay = getDisplayType( pageType ) if not docText and not noDoc then docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } ) if static.Documentation.badDoc and static.Documentation.badDoc == '1' then mw.logObject( static, 'static' ) badDoc = 1 end if docText == '' then docText = nil noDoc = 1 end end if docText then docText = '\n' .. docText .. '\n' end local docClass = '' local message local category if noDoc then docClass = 'documentation-noDoc' message = i18n.pageNoDocPrompt:format( pageTypeDisplay, pageTypeDisplay ) if not ( args.nocat or namespace == i18n.namespaceUser ) then category = i18n.pageNoDocCategory:format( pageTypeDisplay ) if not mw.title.new( i18n.commonNamespacedPage:format( i18n.namespaceCategory, category ) ).exists then category = i18n.pageNoDocCategoryDefault end end elseif badDoc then docClass = 'documentation-badDoc' message = i18n.pageBadDocPrompt:format( pageTypeDisplay ) if not ( args.nocat or namespace == i18n.namespaceUser ) then category = i18n.pageBadDocCategory:format( pageTypeDisplay ) if not mw.title.new( i18n.commonNamespacedPage:format( i18n.namespaceCategory, category ) ).exists then category = i18n.pageBadDocCategoryDefault end end end -- Generates the link bar local links = mw.html.create( 'span' ) :attr( 'id', 'documentation-header-tools' ) local linkList = {} if not noDoc then if page ~= docPage then table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( docPage.fullText, i18n.linkTextView ) ) ) end table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialEdit, docPage.fullText ), i18n.linkTextEdit ) ) ) table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialHistory, docPage.fullText ), i18n.linkTextHistory ) ) ) else table.insert( linkList, i18n.linkFormat:format( i18n.commonExternalLinkWithName:format( docPage:canonicalUrl{ action = 'edit', preload = i18n.defaultPreload, preloadparams = pageTypeDisplay }, i18n.linkTextCreate ) ) ) end table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialPurge, docPage.fullText ), i18n.linkTextPurge ) ) ) links:wikitext( i18n.linkBar:format( table.concat( linkList, i18n.linkSeparator ) ) ) local body = mw.html.create( 'div' ):addClass( 'documentation' ) body :addClass( docClass ) local header = mw.html.create( 'div' ) :addClass( 'documentation-header-top' ) header :node( links ) :tag( 'span' ) :addClass( 'documentation-header-title' ) :wikitext( i18n.pageDocHeaderTitle ) local codePages = { module = true, stylesheet = true, script = true, } if not noDoc and codePages[ pageType ] then header :tag( 'span' ) :attr( 'id', 'documentation-jump-to-code' ) :wikitext( i18n.commonInternalLinkPipe:format( '#the-code', i18n.pageDocJumpToCode ) ) end body :node( header ):done() :wikitext( message ) :wikitext( docText ) if not noDoc and page ~= docPage then body :tag( 'div' ) :addClass( 'documentation-header-bottom' ) :node( links ) :wikitext( i18n.pageDocHeaderBottom:format( i18n.commonInternalLink:format( docPage.fullText ) ) ) end if category then body:wikitext( pageCategoryHandler( category ) ) end local anchor = '' if not noDoc and pageType ~= 'template' and pageType ~= 'message' then anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' ) end return loadStyles( i18n.defaultStyles ) .. tostring( body ) .. tostring( anchor ) end return p
概:
Minecraft Wiki全文皆循CC BY-NC-SA 3.0,詳見
Minecraft Wiki:版權
。不喜他纂,但去可矣。文務親撰,或謄公本,
萬勿盜版!
捨
助纂塾
啟窗
使用此模板預覽頁面
此文用模 :
模板:Documentation header
(
纂
)
模板:Template link
(
纂
)
模板:Tl
(
纂
)
模板:Transclude
(
纂
)
模組:Documentation
(
纂
)
模組:Documentation/doc
(
纂
)
模組:ProcessArgs
(
纂
)
模組:Static
(
纂
)
模組:TSLoader
(
纂
)
導
家私
尚未登簿
議
績
增簿
籍名
名集
模組
議
English
覽
閱
纂碼
覽史
餘
重新整理
尋
導
監修
清風翻書
會館
凡例
章法
多寶
取佐
援引
特查
文訊