模块:Doc
来自卡厄思梦境WIKI
此模块的文档可以在模块:Doc/doc创建
local p = {}
function p.main(frame)
local title = mw.title.getCurrentTitle()
local fullText = title.fullText
local docPageName = fullText .. '/doc'
local docTitle = mw.title.new(docPageName)
local html = mw.html.create('div'):addClass('tpl-doc')
local header = html:tag('div'):addClass('tpl-doc__header')
header:tag('span'):addClass('tpl-doc__title'):wikitext('模板文档')
local links = header:tag('span'):addClass('tpl-doc__links')
links:wikitext('<span class="tpl-doc__link">[[Special:EditPage/' .. fullText .. '|编辑模板]]</span>')
links:wikitext('<span class="tpl-doc__link">[[Special:EditPage/' .. docPageName .. '|编辑文档]]</span>')
links:wikitext('<span class="tpl-doc__link">[' .. tostring(mw.uri.fullUrl(fullText, {action = 'purge'})) .. ' 刷新模板]</span>')
links:wikitext('<span class="tpl-doc__link">[' .. tostring(mw.uri.fullUrl(docPageName, {action = 'purge'})) .. ' 刷新文档]</span>')
local body = html:tag('div'):addClass('tpl-doc__body')
if docTitle and docTitle.exists then
local content = docTitle:getContent()
if content and content ~= '' then
body:wikitext(frame:preprocess(content))
else
body:tag('div'):addClass('tpl-doc__empty')
:wikitext('文档子页面存在但内容为空。请[[Special:EditPage/' .. docPageName .. '|补充内容]]。')
end
html:wikitext('[[Category:模板文档]]')
else
local createUrl = tostring(mw.uri.fullUrl(docPageName, {
action = 'edit',
preload = 'Template:Doc/preload'
}))
body:tag('div'):addClass('tpl-doc__empty')
:wikitext('此模板尚无说明文档。请前往 [' .. createUrl .. ' 创建文档子页面] 。')
end
return tostring(html)
end
return p