模块:Message box:修订间差异
imported>Shizhao |
imported>Shizhao ep |
||
| 第60行: | 第60行: | ||
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 | ||
| 第158行: | 第172行: | ||
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( | function box:removeBlankArgs(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 = {} | ||
| 第169行: | 第184行: | ||
end | end | ||
end | end | ||
for i, param in ipairs(cfg.allowBlankParams or {}) do | for i, param in ipairs(self.cfg.allowBlankParams or {}) do | ||
newArgs[param] = args[param] | newArgs[param] = args[param] | ||
end | end | ||
| 第175行: | 第190行: | ||
end | end | ||
function box:setBoxParameters( | function box:setBoxParameters(args) | ||
local cfg = self.cfg | |||
-- Get type data. | -- Get type data. | ||
self.type = args.type | self.type = args.type | ||
| 第514行: | 第531行: | ||
)) | )) | ||
end | end | ||
root:wikitext(insertStyle(self.cfg)) | |||
-- Create the box table. | -- Create the box table. | ||
| 第625行: | 第644行: | ||
local outputBox = box.new() | local outputBox = box.new() | ||
outputBox:setTitle(args) | outputBox:setTitle(args) | ||
outputBox:getConfig(boxType) | |||
args = outputBox:removeBlankArgs( | args = outputBox:removeBlankArgs(args) | ||
outputBox:setBoxParameters( | outputBox:setBoxParameters(args) | ||
return outputBox:export() | return outputBox:export() | ||
end | end | ||
| 第636行: | 第655行: | ||
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 | ||
p[boxType] = makeWrapper(boxType) | if boxType:sub(1, 1) ~= '@' then | ||
p[boxType] = makeWrapper(boxType) | |||
end | |||
end | end | ||
return p | return p | ||