Module:讯息框
跳转到导航
跳转到搜索
----修改自[[w:c:dev:Module:Mbox]]
local mbox = {}
local getArgs = require('Dev:Arguments').getArgs
local ts = require('Module:参数').loadData('Module:讯息框/参数')
function mbox.main(frame)
local args = getArgs(frame, { wrappers = 'Template:讯息框', 'Template:通知' })
if ts:parameter('類型', args) or 'standard' == 'source' then
args.revisionDate = string.sub(frame:preprocess('{{REVISIONTIMESTAMP}}'), 1, 8)
end
return mbox._main(args)
end
function mbox._main(args)
-- 容器
local container = mw.html.create('div')
do -- 標識符
local id = ts:parameter('id', args)
if id then container:attr('id', 'mbox-' .. id) end
end
-- 類別
local type = ts:parameter('類型', args) or 'standard'
container:addClass('mbox')
:addClass('mbox-type-' .. type)-- 類型
:addClass(ts:parameter('class', args)) -- 自訂類別
local collapsible = not ts:parameter('不可摺疊', args) and ts:msg { key = '可摺疊資料', sub = type } -- 摺疊
if collapsible then -- 可摺疊
container:addClass('mw-collapsible')
local collapsed = ts:parameter('摺疊', args) or ts:msg { key = '摺疊資料', sub = type } -- 預設摺疊
if collapsed then container:addClass('mw-collapsed') end
end
-- 樣式
container:css('--mbox-border-color', ts:parameter('邊框顏色', args)):cssText(ts:parameter('style', args))
do -- 圖片
local image = ts:parameter('圖片', args) or ts:msg { key = '圖片資料', sub = type }
if image then
image = string.gsub(image, '^File:', '')
local imagesize = ts:parameter('圖片大小', args) or ts:msg { key = '圖片大小資料', sub = type }
local imagelink = ts:parameter('圖片連結', args) or ts:msg { key = '圖片連結資料', sub = type }
local imagealt = ts:parameter('替代說明', args) or ts:msg { key = '替代說明資料', sub = type }
imagesize = imagesize and '|' .. imagesize or ''
if imagelink == '空' then
imagelink = '|link='
else
imagelink = imagelink and '|link=' .. imagelink or ''
end
if imagealt == '空' then
imagealt = '|alt='
else
imagealt = imagealt and '|alt=' .. imagealt or ''
end
image = string.format('[[File:%s%s%s%s]]', image, imagesize, imagelink, imagealt)
local imageDiv = container:tag('div'):addClass('mbox-image'):wikitext(image)
if collapsible then imageDiv:addClass('mw-collapsible-content') end
end
end
do -- 標題
local header = ts:parameter('標題', args)
if header then container:tag('div'):addClass('mbox-header'):wikitext(header) end
end
do -- 主體
local text = ts:parameter('文字', args)
if text then
local textDiv = container:tag('div'):addClass('mbox-text'):wikitext(text)
if collapsible then textDiv:addClass('mw-collapsible-content') end
-- 備註
local comment = ts:parameter('註', args)
if comment then textDiv:tag('div'):addClass('mbox-comment'):wikitext(comment) end
end
end
do -- 側
local aside = ts:parameter('側', args)
if aside then
local asideDiv = container:tag('div'):addClass('mbox-aside'):wikitext(aside)
if collapsible then asideDiv:addClass('mw-collapsible-content') end
end
end
if type ~= 'source' then
return container
end
if tonumber(args.revisionDate) and tonumber(args.revisionDate) < 20240210 then --9日無用到此模組的變更
local result = tostring(container)
result = string.gsub(result, '%[%[:?', '[[fandom:')
result = string.gsub(result, '%[%[[fF]andom:[fF]ile:', '[[File:')
result = string.gsub(result, 'plantsvszombies.wiki.gg/wiki/', 'plantsvszombies.fandom.com/wiki/')
result = string.gsub(result, 'pvz.wiki.gg/wiki/', 'plantsvszombies.fandom.com/wiki/')
result = string.gsub(result, 'plantsvszombies.wiki.gg/zh/wiki/', 'pvz.fandom.com/zh/wiki/')
result = string.gsub(result, 'pvz.wiki.gg/zh/wiki/', 'pvz.fandom.com/zh/wiki/')
return mw.text.tag{
name = 'div',
attrs = { class="mbox-type-source--old-wrapper" },
content = '以下-{zh-cn:信息;zh-tw:資訊}-對應本頁面2024年2月8日之前,來自Fandom舊站的版本內容,其中可能有導向中文、英文舊站的-{zh-cn:链接;zh-tw:連結;}-。<br /><span class="smaller">部分-{zh-cn:链接;zh-tw:連結;}-可能表現不符合預期,如有發現請告知管理員。</span>' .. result
}
end
return container
end
return mbox