模块:Message box:修订间差异

无编辑摘要
(创建页面,内容为“-- 摘自中文维基百科:https://zh.wikipedia.org/w/index.php?title=Module:Message_box -- This is a meta-module for producing message box templates, including {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}. -- Require necessary modules. local getArgs = require('Module:Arguments').getArgs local categoryHandler = require('Module:Category handler').main local yesno = require('Module:Yesno') -- Load the configuration page. loc…”)
 
无编辑摘要
 
第62行: 第62行:
table.sort(nums)
table.sort(nums)
return nums
return nums
end
local function insertStyle(cfg)
-- Create the templatestyles tag.
local frame = mw.getCurrentFrame()
return frame:extensionTag{
name = 'templatestyles',
args = { src = cfgTables['@global'].templatestyles },
} .. frame:extensionTag{
name = 'templatestyles',
args = { src = cfg.templatestyles },
}
end
end


第174行: 第160行:
error(format('無效的訊息框類型「%s」;有效的類型為%s', tostring(boxType), mw.text.listToText(boxTypes)), 2)
error(format('無效的訊息框類型「%s」;有效的類型為%s', tostring(boxType), mw.text.listToText(boxTypes)), 2)
end
end
self.cfg = cfg
return cfg
return cfg
end
end


function box:removeBlankArgs(args)
function box:removeBlankArgs(cfg, args)
-- Only allow blank arguments for the parameter names listed in cfg.allowBlankParams.
-- Only allow blank arguments for the parameter names listed in cfg.allowBlankParams.
local newArgs = {}
local newArgs = {}
第186行: 第171行:
end
end
end
end
for i, param in ipairs(self.cfg.allowBlankParams or {}) do
for i, param in ipairs(cfg.allowBlankParams or {}) do
newArgs[param] = args[param]
newArgs[param] = args[param]
end
end
第192行: 第177行:
end
end


function box:setBoxParameters(args)
function box:setBoxParameters(cfg, args)
local cfg = self.cfg
 
-- Get type data.
-- Get type data.
self.type = args.type
self.type = args.type
第302行: 第285行:
local talkText = '相關討論可見於'
local talkText = '相關討論可見於'
if talkArgIsTalkPage then
if talkArgIsTalkPage then
talkText = format('%s[[%s|%s]].', talkText, talk, talkTitle.prefixedText)
talkText = format('%s[[%s|%s]]', talkText, talk, talkTitle.prefixedText)
else
else
talkText = format('%s[[%s#%s|討論頁]].', talkText, talkTitle.prefixedText, talk)
talkText = format('%s[[%s#%s|討論頁]]', talkText, talkTitle.prefixedText, talk)
end
end
self.talk = talkText
self.talk = talkText
第533行: 第516行:
))
))
end
end
root:wikitext(insertStyle(self.cfg))


-- Create the box table.
-- Create the box table.
第577行: 第558行:
textCell
textCell
:cssText(self.textstyle)
:cssText(self.textstyle)
local textCellSpan = textCell:tag('div')
local textCellSpan = textCell:tag('span')
textCellSpan
textCellSpan
:addClass('mbox-text-span')
:addClass('mbox-text-span')
第646行: 第627行:
local outputBox = box.new()
local outputBox = box.new()
outputBox:setTitle(args)
outputBox:setTitle(args)
outputBox:getConfig(boxType)
local cfg = outputBox:getConfig(boxType)
args = outputBox:removeBlankArgs(args)
args = outputBox:removeBlankArgs(cfg, args)
outputBox:setBoxParameters(args)
outputBox:setBoxParameters(cfg, args)
return outputBox:export()
return outputBox:export()
end
end
第657行: 第638行:
return main(boxType, args)
return main(boxType, args)
end
end
end
local function insertStyleWikitext(frame)
local args = getArgs(frame, {trim = false, removeBlanks = false})
local boxType = args[1] or 'mbox'
-- // ---- // --
local outputBox = box.new()
outputBox:setTitle(args)
local cfg = outputBox:getConfig(boxType)
return insertStyle(cfg)
end
end


local p = {
local p = {
main = main,
main = main,
mbox = makeWrapper('mbox'),
mbox = makeWrapper('mbox')
insertStyle = insertStyleWikitext
}
}


for boxType in pairs(cfgTables) do
for boxType in pairs(cfgTables) do
if boxType:sub(1, 1) ~= '@' then
p[boxType] = makeWrapper(boxType)
p[boxType] = makeWrapper(boxType)
end
end
end


return p
return p
134

个编辑