Module:Documentation:修订间差异

删除的内容 添加的内容
新增 escapeBrackets 函数 + renderStartBoxLinks 方括号实体包裹
去掉 message() 中多余的 preprocess 调用(config 已无 -{}-)
 
(未显示同一用户的8个中间版本)
第20行:
--[[
-- Gets a message from the cfg table and formats it if appropriate.
-- SupportsConfig is plain -{zh-hans:...;, no zh-hant:...;{}- syntax viaprocessing frame:preprocess()needed.
--]]
local msg = cfg[cfgKey]
第79行:
end
for i = 1, lim do
ret[#retlocal + 1]v = select(i, ...)
if v then
ret[#ret + 1] = v
end
end
if #ret == 0 then return nil end
return format(
'<span class="%s">(%s)</span>',
第89行 ⟶ 第93行:
 
p.makeToolbar = makeToolbar
 
local function escapeBrackets(s)
-- 将方括号转为 HTML 实体,防止被 wikitext 解析为外部链接
s = s:gsub('%[', '&#91;')
s = s:gsub('%]', '&#93;')
return s
end
 
p.escapeBrackets = escapeBrackets
 
----------------------------------------------------------------------------
第263行 ⟶ 第258行:
function envFuncs.testcasesTitle()
return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage'))
end
 
function envFuncs.printTitle()
local templateTitle = env.templateTitle
if subjectSpace ~= 10 or not templateTitle then
return templateTitle.prefixedText .. '/' .. :subPageTitle(message('print-subpage'))
end
return snil
end
 
第342行 ⟶ 第345行:
omargs.image = message('sandbox-notice-image')
 
local text = '__EXPECTUNUSEDTEMPLATE__'
local pagetype, pagetypee, sandboxCat
if subjectSpace == 10 then
第360行 ⟶ 第363行:
local templateLink = makeWikilink(templateTitle.prefixedText)
local compareUrl = env.compareUrl
-- mworg 预览检测:预览时不显示 diff 链接
if compareUrl then
local isPreviewing = mw.getCurrentFrame():preprocess('{{REVISIONID}}') == ''
if isPreviewing or not compareUrl then
text = text .. message('sandbox-notice-blurb', {pagetype, templateLink})
else
local compareDisplay = message('sandbox-notice-compare-link-display')
local compareLink = makeUrlLink(compareUrl, compareDisplay)
text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink})
else
text = text .. message('sandbox-notice-blurb', {pagetype, templateLink})
end
 
第375行 ⟶ 第380行:
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay)
text = text .. '<br /><small>' .. message('sandbox-notice-testcases-run-blurb', {pagetypee, testcasesLink, testcasesRunLink}) .. '</small>'
else
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
text = text .. '<br /><small>' .. message('sandbox-notice-testcases-blurb', {pagetypee, testcasesLink}) .. '</small>'
end
end
第448行 ⟶ 第453行:
 
function p.renderStartBoxLinks(data)
-- escapeBrackets: 用方括号实体包裹链接,防止 wikitext 错误解析
local docTitle = data.docTitle
local purgeLink = makeWikilink("Special:Purge/" .. data.title.prefixedText, data.purgeLinkDisplay)
local ret
if docTitle.exists then
local viewLink = makeWikilink(docTitle.prefixedText, data.viewLinkDisplay)
local editLink = makeWikilink("Special:EditPage/" .. docTitle.prefixedText, data.editLinkDisplay)
local historyLink = makeWikilink("Special:PageHistory/" .. docTitle.prefixedText, data.historyLinkDisplay)
ret =return format('[&#91;%s]&#93; [&#91;%s]&#93; [&#91;%s]&#93; [&#91;%s]&#93;', viewLink, editLink, historyLink, purgeLink)
viewLink, editLink, historyLink, purgeLink)
else
local createLink = makeUrlLink(docTitle:canonicalUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay)
ret =return format('[&#91;%s]&#93; [&#91;%s]&#93;', createLink, purgeLink)
end
return escapeBrackets(ret)
end
 
第496行 ⟶ 第499行:
if links then
data.linksClass = message('start-box-link-classes')
data.linksId = message('start-box-link-id')
data.links = links
end
第582行 ⟶ 第586行:
if subjectSpace == 2 or subjectSpace == 10 or subjectSpace == 828 then
text = text .. (p.makeExperimentBlurb(args, env) or '') .. '<br />'
-- 若存在 /Print 子页面,提示打印版本链接
text = text .. (p.makePrintBlurb(args, env) or '')
if not args.content and not args[1] then
text = text .. (p.makeCategoriesBlurb(args, env) or '')
end
text = text .. '' .. (p.makeSubpagesBlurb(args, env) or '')
-- Print 版本提示(位于 end box 末尾)
textlocal printBlurb = text .. (p.makePrintBlurb(args, env) or '')
if printBlurb then
text = text .. '<br />' .. printBlurb
end
end
end
第754行 ⟶ 第761行:
--]=]
local subjectSpace = env.subjectSpace
local templateTitleprintTitle = env.templateTitleprintTitle
if subjectSpace ~= 10 or not printTitle or not printTitle.exists then
-- 仅模板空间显示打印版本提示
if subjectSpace ~= 10 or not templateTitle then
return nil
end
local printTitle = mw.title.new(
templateTitle.prefixedText .. '/' .. message('print-subpage')
)
if not printTitle or not printTitle.exists then
return nil
end
第770行:
text = text .. makeCategoryLink(message('print-category'))
end
return text .. '<br />'
end