模块:Message box:修订间差异

imported>Xiplus
嘗試正規化日期
imported>Shizhao
ep
 
(未显示5个用户的7个中间版本)
第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(cfg, args)
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(cfg, args)
function box:setBoxParameters(args)
local cfg = self.cfg
 
-- Get type data.
-- Get type data.
self.type = args.type
self.type = args.type
第283行: 第300行:
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
第300行: 第317行:
date = lang:formatDate('Y年n月j日', args.time)
date = lang:formatDate('Y年n月j日', args.time)
end
end
local ok, tempdate = pcall(lang.formatDate, lang, 'Y年n月j日', date) -- 正規化日期
if date then
if ok then
local ok, tempdate = pcall(lang.formatDate, lang, 'Y年n月j日', date) -- 正規化日期
date = tempdate
if ok then
date = tempdate
end
end
end
if date then
if date then
第405行: 第424行:
if args.date and args.date ~= '' then
if args.date and args.date ~= '' then
date = args.date
date = args.date
local ok, tempdate = pcall(lang.formatDate, lang, 'Y年n月', date) -- 正規化日期
if ok then
date = tempdate
end
elseif args.time and args.time ~= '' then
elseif args.time and args.time ~= '' then
date = lang:formatDate('Y年n月', args.time)
date = lang:formatDate('Y年n月', args.time)
第508行: 第531行:
))
))
end
end
root:wikitext(insertStyle(self.cfg))


-- Create the box table.
-- Create the box table.
第550行: 第575行:
textCell
textCell
:cssText(self.textstyle)
:cssText(self.textstyle)
local textCellSpan = textCell:tag('span')
local textCellSpan = textCell:tag('div')
textCellSpan
textCellSpan
:addClass('mbox-text-span')
:addClass('mbox-text-span')
第619行: 第644行:
local outputBox = box.new()
local outputBox = box.new()
outputBox:setTitle(args)
outputBox:setTitle(args)
local cfg = outputBox:getConfig(boxType)
outputBox:getConfig(boxType)
args = outputBox:removeBlankArgs(cfg, args)
args = outputBox:removeBlankArgs(args)
outputBox:setBoxParameters(cfg, args)
outputBox:setBoxParameters(args)
return outputBox:export()
return outputBox:export()
end
end
第630行: 第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