未登录
登录
请求账号
BinWiki
搜索
查看“︁模块:Documentation”︁的源代码
来自BinWiki
命名空间
模块
讨论
更多
更多
页面操作
阅读
查看源代码
历史
←
模块:Documentation
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
-- This module implements {{documentation}}. -- Get required modules. local getArgs = require('Module:Arguments').getArgs local messageBox = require('Module:Message box') -- Get the config table. local cfg = mw.loadData('Module:Documentation/config') local p = {} -- Often-used functions. local ugsub = mw.ustring.gsub ------------------------------------------------------------------------------- -- Helper functions ------------------------------------------------------------------------------- local function message(cfgKey, valArray, expectType) local msg = cfg[cfgKey] expectType = expectType or 'string' if type(msg) ~= expectType then error('message: type error in message cfg.' .. cfgKey .. ' (' .. expectType .. ' expected, got ' .. type(msg) .. ')', 2) end if not valArray then return msg end local function getMessageVal(match) match = tonumber(match) return valArray[match] or error('message: no value found for key $' .. match .. ' in message cfg.' .. cfgKey, 4) end local ret = ugsub(msg, '$([1-9][0-9]*)', getMessageVal) return ret end p.message = message local function makeWikilink(page, display) if display then return mw.ustring.format('[[%s|%s]]', page, display) else return mw.ustring.format('[[%s]]', page) end end p.makeWikilink = makeWikilink local function makeCategoryLink(cat, sort) local catns = mw.site.namespaces[14].name return makeWikilink(catns .. ':' .. cat, sort) end p.makeCategoryLink = makeCategoryLink local function makeUrlLink(url, display) return mw.ustring.format('[%s %s]', url, display) end p.makeUrlLink = makeUrlLink local function makeToolbar(...) local ret = {} local lim = select('#', ...) if lim < 1 then return nil end for i = 1, lim do ret[#ret + 1] = select(i, ...) end return '<small style="font-style: normal;">(' .. table.concat(ret, ' | ') .. ')</small>' end p.makeToolbar = makeToolbar ------------------------------------------------------------------------------- -- Argument processing ------------------------------------------------------------------------------- local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame, { valueFunc = function (key, value) if type(value) == 'string' then value = value:match('^%s*(.-)%s*$') if key == 'heading' or value ~= '' then return value else return nil end else return value end end }) return p[funcName](args) end end ------------------------------------------------------------------------------- -- Entry points ------------------------------------------------------------------------------- function p.nonexistent(frame) if mw.title.getCurrentTitle().subpageText == 'testcases' then return frame:expandTemplate{title = 'module test cases notice'} else return p.main(frame) end end ------------------------------------------------------------------------------- -- Main function ------------------------------------------------------------------------------- p.main = makeInvokeFunc('_main') function p._main(args) local env = p.getEnvironment(args) local root = mw.html.create() root :wikitext(p._getModuleWikitext(args, env)) :wikitext(p.protectionTemplate(env)) :tag('div') :attr('id', message('main-div-id')) :addClass(message('main-div-classes')) :newline() :wikitext(p._startBox(args, env)) :wikitext(p._content(args, env)) :tag('div') :css('clear', 'both') :newline() :done() :done() :wikitext(p._endBox(args, env)) :wikitext(p.addTrackingCategories(env)) return tostring(root) end ------------------------------------------------------------------------------- -- Environment settings ------------------------------------------------------------------------------- function p.getEnvironment(args) local env, envFuncs = {}, {} setmetatable(env, { __index = function (t, key) local envFunc = envFuncs[key] if envFunc then local success, val = pcall(envFunc) if success then env[key] = val return val end end return nil end }) function envFuncs.title() local titleArg = args.page if titleArg then return mw.title.new(titleArg) else return mw.title.getCurrentTitle() end end function envFuncs.templateTitle() local subjectSpace = env.subjectSpace local title = env.title local subpage = title.subpageText if subpage == message('sandbox-subpage') or subpage == message('testcases-subpage') then return mw.title.makeTitle(subjectSpace, title.baseText) else return mw.title.makeTitle(subjectSpace, title.text) end end function envFuncs.docTitle() local title = env.title local docname = args[1] local docpage if docname then docpage = docname else docpage = env.docpageBase .. '/' .. message('doc-subpage') end return mw.title.new(docpage) end function envFuncs.sandboxTitle() return mw.title.new(env.docpageBase .. '/' .. message('sandbox-subpage')) end function envFuncs.testcasesTitle() return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage')) end function envFuncs.printTitle() return env.templateTitle:subPageTitle(message('print-subpage')) end function envFuncs.protectionLevels() return env.title.protectionLevels end function envFuncs.subjectSpace() return mw.site.namespaces[env.title.namespace].subject.id end function envFuncs.docSpace() return mw.site.namespaces[env.title.namespace].subject.id end function envFuncs.docpageBase() local title = env.title local subject = mw.site.namespaces[title.namespace].subject.id if subject == title.namespace then return title.prefixedText else return title.prefixedText:match('^(.-)/') end end function envFuncs.compareUrl() if env.sandboxTitle and env.sandboxTitle.exists then return mw.title.makeTitle(4, 'Special:ComparePages'):fullUrl{ page = env.sandboxTitle.prefixedText, target = env.templateTitle.prefixedText } else return nil end end return env end ------------------------------------------------------------------------------- -- End box (link box) construction ------------------------------------------------------------------------------- function p._endBox(args, env) -- Get environment data. env = env or p.getEnvironment(args) local subjectSpace = env.subjectSpace local docTitle = env.docTitle if not subjectSpace or not docTitle then return nil end -- Decide if end box should be shown. local linkBox = args['link box'] if linkBox == 'off' or not ( docTitle.exists or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 ) then return nil end -- Assemble the arguments for {{fmbox}}. local fmargs = {} fmargs.id = message('fmbox-id') fmargs.image = 'none' fmargs.style = message('fmbox-style') fmargs.textstyle = message('fmbox-textstyle') -- Assemble the fmbox text field. local text = '' if linkBox then text = text .. linkBox else if subjectSpace == 2 or subjectSpace == 10 or subjectSpace == 828 then if not args.content and not args[1] then text = text .. (p.makeCategoriesBlurb(args, env) or '') end end end fmargs.text = text return messageBox.main('fmbox', fmargs) end function p.makeCategoriesBlurb(args, env) local docTitle = env.docTitle if not docTitle then return nil end local docPathLink = makeWikilink(docTitle.prefixedText, message('doc-link-display')) return message('add-categories-blurb', {docPathLink}) end -- Tracking categories function p.addTrackingCategories(env) local title = env.title local subjectSpace = env.subjectSpace if not title or not subjectSpace then return nil end local subpage = title.subpageText local ret = '' if message('display-strange-usage-category', nil, 'boolean') and ( subpage == message('doc-subpage') or (subjectSpace ~= 828 and subpage == message('testcases-subpage')) ) then ret = ret .. p.makeCategoryLink(message('strange-usage-category')) end return ret end return p
该页面使用的模板:
模块:Documentation/doc
(
查看源代码
)
返回
模块:Documentation
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
wiki工具
wiki工具
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志