维护提醒
BWIKI 全站将于 9 月 3 日(全天)进行维护,期间无法编辑任何页面或发布新的评论。
全站通知:
模块:For
刷
历
编
跳到导航
跳到搜索
local p = {}
local function isWikilink(s)
return s:find('[[', 1, true) and s:find(']]', 1, true)
end
function p.main(frame)
local parentArgs = frame:getParent().args
local args = {}
local max_n = 0
for k, v in pairs(parentArgs) do
local n = tonumber(k)
if n and n > 0 and math.floor(n) == n then
args[n] = mw.text.trim(v)
if n > max_n then
max_n = n
end
end
end
local R_param = mw.text.trim(parentArgs.R or '')
local title = mw.title.getCurrentTitle()
local pagename = title.text
local content_parts = {}
table.insert(content_parts, '[[File:Disambig gray.svg|25px|link=]] ')
if R_param ~= '' then
table.insert(content_parts, R_param)
end
local subsequent_parts = {}
local state = ''
for i = 1, max_n do
local v = args[i]
if v ~= nil then
if state == 'link' then
if isWikilink(v) then
table.insert(subsequent_parts, "“'''" .. v .. "'''”")
else
table.insert(subsequent_parts, "“'''[[" .. v .. "]]'''”")
end
state = 'end'
else
if v == '和' or v == '或' or v == '、' then
table.insert(subsequent_parts, v)
else
if state == 'end' then
table.insert(subsequent_parts, ';')
end
local desc_text = (v ~= '') and v or '其他用法'
table.insert(subsequent_parts, '关于' .. desc_text .. ',请见')
state = 'link'
end
end
end
end
if max_n < 1 then
table.insert(subsequent_parts, '关于其他用法,请见')
state = 'link'
end
if state == 'link' then
table.insert(subsequent_parts, "“'''[[" .. pagename .. "(消歧义)]]'''”")
end
local final_parts = {}
table.insert(final_parts, table.concat(content_parts, ''))
if #subsequent_parts > 0 then
if R_param ~= '' then
table.insert(final_parts, ' ')
end
table.insert(final_parts, table.concat(subsequent_parts, ' '))
table.insert(final_parts, '。')
end
local final_content = table.concat(final_parts, '')
return frame:expandTemplate{ title = 'hatnote', args = { final_content } }
end
return p