Module:Documentation
跳转到导航
跳转到搜索
local getArgs = require("Dev:Arguments").getArgs
local p = {}
function p.doc(frame)
return p._doc(getArgs(frame))
end
function p._doc(args)
local currentPage = mw.title.getCurrentTitle()
local docPage = mw.title.new(args[1] or "") or currentPage:subPageTitle("doc")
local docContainer = mw.html.create("div"):addClass("documentation")
if args.type == nil then
if currentPage.namespace == 10 then args.type = "模板"
elseif currentPage.namespace == 828 then args.type = "模块"
else args.type = "页面" end
end
local header = "[[File:Template-info.svg|x24px]] <b>" .. args.type .. "文档</b>"
if args.content == nil and docPage.exists then
header = header .. tostring(mw.html.create("span"):addClass("documentation-actions")
:tag("span"):addClass("documentation-action-label"):wikitext("[更多选项]"):done()
:tag("ul"):addClass("documentation-action-menu")
:tag("li"):wikitext("[[" .. docPage.fullText .. "|查看文档页面]]"):done()
:tag("li"):wikitext("[[" .. docPage.talkPageTitle.fullText .. "|文档讨论页]]"):done()
:tag("li"):wikitext("[[Special:EditPage/" .. docPage.fullText .. "|编辑文档]]"):done()
:tag("li"):wikitext("[[Special:PageHistory/" .. docPage.fullText .. "|文档修订历史]]"):done()
:tag("li"):wikitext("[[Special:Purge/" .. currentPage.fullText .. "|刷新本页缓存]]"):done()
:done()
:done())
end
docContainer:tag("div"):addClass("documentation-header"):wikitext(header):done()
local content = args.content
if content == nil then
if docPage.exists then
local docTitle = docPage.fullText
if docPage.namespace == 0 then docTitle = ":" .. docTitle end
content = mw.getCurrentFrame():expandTemplate{ title = docTitle, args = {} }
else content = "文档页面[[" .. docPage.fullText .. "]]尚未创建。点击链接以创建页面!<br>"
end
end
docContainer:tag("div"):addClass("documentation-content"):wikitext("\n" .. content .. "\n"):done()
local footer = "([[Template:Documentation|如何使用文档?]])"
if args.content then footer = "此文档为内联文档。" .. footer
elseif docPage.exists then footer = "此文档嵌入自[[" .. docPage.fullText .. "]]。" .. footer end
docContainer:tag("div"):addClass("documentation-footer"):wikitext(footer):done()
return tostring(docContainer)
end
return p