打开/关闭菜单
331
1.7K
131
11.8K
星露谷物语扩展百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Hatnote:修订间差异

来自星露谷物语扩展百科
Sizau留言 | 贡献
创建页面
 
Sizau留言 | 贡献
无编辑摘要
第2行: 第2行:
local p = {}
local p = {}


-- 辅助函数:检查字符串是否为维基链接
-- 获取页面类型
local function checkLink(s)
local function getPageType(title, hasSection)
return s:find('[[', 1, true) and s:find(']]', 1, true)
    if hasSection then return '章节' end
end


-- 辅助函数:获取页面类型
    local nsText = title.nsText
local function getPageType(title, hasSection)
    if nsText == '模板' then
if hasSection then
        return '模板'
return '章节'
    elseif nsText == '模块' then
end
        return '模块'
    else
local nsText = title.nsText
        return '条目'
if nsText == '模板' then
    end
return '模板'
elseif nsText == '模块' then
return '模块'
else
return '条目'
end
end
end


-- 辅助函数:格式化链接
-- 格式化链接
local function formatLink(text)
local function formatLink(text)
if isWikilink(text) then
    if text:find('[[', 1, true) and text:find(']]', 1, true) then
return "“'''" .. text .. "'''”"
        return "“'''" .. text .. "'''”"
else
    else
return "“'''[[" .. text .. "]]'''”"
        return "“'''[[" .. text .. "]]'''”"
end
    end
end
end


-- 检查是否为连接词
-- 检查是否为连接词
local function isConnector(text)
local function isConnector(text)
return text == '和' or text == '或' or text == '、'
    return text == '和' or text == '或' or text == '、'
end
end


-- 获取最大数字索引
-- 获取最大数字索引
local function getMaxIndex(args)
local function getMaxIndex(args)
local maxIndex = 0
    local maxIndex = 0
for key, _ in pairs(args) do
    for key, _ in pairs(args) do
local index = tonumber(key)
        local index = tonumber(key)
if index and index > 0 and math.floor(index) == index then
        if index and index > 0 and math.floor(index) == index then
if index > maxIndex then
            if index > maxIndex then maxIndex = index end
maxIndex = index
        end
end
    end
end
    return maxIndex
end
return maxIndex
end
end


-- 处理描述和链接序列
-- 处理描述和链接序列
local function processDescriptionLinks(args, startIndex, maxIndex, pagename)
local function processDescriptionLinks(args, startIndex, maxIndex, pagename)
local parts = {}
    local parts = {}
local state = '' -- 状态: '' | 'link' | 'end'
    local state = '' -- 状态: '' | 'link' | 'end'
 
for i = startIndex, maxIndex do
    for i = startIndex, maxIndex do
local value = args[i]
        local value = args[i]
if value then
        if value then
if state == 'link' then
            if state == 'link' then
table.insert(parts, formatLink(value))
                table.insert(parts, formatLink(value))
state = 'end'
                state = 'end'
elseif isConnector(value) then
            elseif isConnector(value) then
table.insert(parts, value)
                table.insert(parts, value)
else
            else
if state == 'end' then
                if state == 'end' then table.insert(parts, ';') end
table.insert(parts, ';')
                local description = (value ~= '') and value or '其他用法'
end
                table.insert(parts, '关于' .. description .. ',请见')
local description = (value ~= '') and value or '其他用法'
                state = 'link'
table.insert(parts, '关于' .. description .. ',请见')
            end
state = 'link'
        end
end
    end
end
 
end
    -- fallback
    if state == 'link' then
-- fallback
        table.insert(parts, formatLink(pagename .. '(消歧义)'))
if state == 'link' then
    end
table.insert(parts, formatLink(pagename .. '(消歧义)'))
 
end
    return parts, state
return parts, state
end
end


-- For
-- For
function p.about(frame)
function p.about(frame)
local args = getArgs(frame, {
    local args = getArgs(frame,
trim = true,
                        {trim = true, removeBlanks = true, parentOnly = true})
removeBlanks = true,
 
parentOnly = true
    local maxIndex = getMaxIndex(args)
})
    local title = mw.title.getCurrentTitle()
    local pagename = title.text
local maxIndex = getMaxIndex(args)
 
local title = mw.title.getCurrentTitle()
    local contentParts = {'[[File:Disambig gray.svg|25px|link=]]  '}
local pagename = title.text
 
    if args[1] then
local contentParts = {
        local pageType = getPageType(title, args.section)
'[[File:Disambig gray.svg|25px|link=]]  '
        table.insert(contentParts,
}
                    '本' .. pageType .. '介绍的是' .. args[1])
    end
if args[1] then
 
local pageType = getPageType(title, args.section)
    local subsequentParts = processDescriptionLinks(args, 2, maxIndex, pagename)
table.insert(contentParts, '本' .. pageType .. '介绍的是' .. args[1])
 
end
    if maxIndex < 2 and args[1] then
        table.insert(subsequentParts, '关于其他用法,请见' ..
local subsequentParts = processDescriptionLinks(args, 2, maxIndex, pagename)
                        formatLink(pagename .. '(消歧义)'))
    end
if maxIndex < 2 and args[1] then
 
table.insert(subsequentParts, '关于其他用法,请见' .. formatLink(pagename .. '(消歧义)'))
    local finalParts = {table.concat(contentParts, '')}
end
 
    if #subsequentParts > 0 then
local finalParts = { table.concat(contentParts, '') }
        if args[1] then table.insert(finalParts, '。 ') end
        table.insert(finalParts, table.concat(subsequentParts, ' '))
if #subsequentParts > 0 then
        table.insert(finalParts, '。')
if args[1] then
    elseif args[1] then
table.insert(finalParts, '。 ')
        table.insert(finalParts, '。')
end
    end
table.insert(finalParts, table.concat(subsequentParts, ' '))
 
table.insert(finalParts, '。')
    local finalContent = table.concat(finalParts, '')
elseif args[1] then
    return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
table.insert(finalParts, '。')
end
local finalContent = table.concat(finalParts, '')
return frame:expandTemplate{ title = 'hatnote', args = { finalContent } }
end
end


-- For
-- For
function p.for2(frame)
function p.for2(frame)
local args = getArgs(frame, {
    local args = getArgs(frame,
trim = true,
                        {trim = true, removeBlanks = true, parentOnly = true})
removeBlanks = true,
 
parentOnly = true
    local maxIndex = getMaxIndex(args)
})
    local title = mw.title.getCurrentTitle()
    local pagename = title.text
local maxIndex = getMaxIndex(args)
 
local title = mw.title.getCurrentTitle()
    local contentParts = {'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'}
local pagename = title.text
 
    if args.R then table.insert(contentParts, args.R) end
local contentParts = {
 
'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'
    local subsequentParts = processDescriptionLinks(args, 1, maxIndex, pagename)
}
 
    if maxIndex < 1 then
if args.R then
        table.insert(subsequentParts, '关于其他用法,请见')
table.insert(contentParts, args.R)
        table.insert(subsequentParts, formatLink(pagename .. '(消歧义)'))
end
    end
 
local subsequentParts = processDescriptionLinks(args, 1, maxIndex, pagename)
    local finalParts = {table.concat(contentParts, '')}
 
if maxIndex < 1 then
    if #subsequentParts > 0 then
table.insert(subsequentParts, '关于其他用法,请见')
        if args.R then table.insert(finalParts, ' ') end
table.insert(subsequentParts, formatLink(pagename .. '(消歧义)'))
        table.insert(finalParts, table.concat(subsequentParts, ' '))
end
        table.insert(finalParts, '。')
    end
local finalParts = { table.concat(contentParts, '') }
 
    local finalContent = table.concat(finalParts, '')
if #subsequentParts > 0 then
    return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
if args.R then
table.insert(finalParts, ' ')
end
table.insert(finalParts, table.concat(subsequentParts, ' '))
table.insert(finalParts, '。')
end
local finalContent = table.concat(finalParts, '')
return frame:expandTemplate{ title = 'hatnote', args = { finalContent } }
end
end



2025年10月14日 (二) 19:39的版本

[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local getArgs = require('Module:Arguments').getArgs
local p = {}

-- 获取页面类型
local function getPageType(title, hasSection)
    if hasSection then return '章节' end

    local nsText = title.nsText
    if nsText == '模板' then
        return '模板'
    elseif nsText == '模块' then
        return '模块'
    else
        return '条目'
    end
end

-- 格式化链接
local function formatLink(text)
    if text:find('[[', 1, true) and text:find(']]', 1, true) then
        return "“'''" .. text .. "'''”"
    else
        return "“'''[[" .. text .. "]]'''”"
    end
end

-- 检查是否为连接词
local function isConnector(text)
    return text == '和' or text == '或' or text == '、'
end

-- 获取最大数字索引
local function getMaxIndex(args)
    local maxIndex = 0
    for key, _ in pairs(args) do
        local index = tonumber(key)
        if index and index > 0 and math.floor(index) == index then
            if index > maxIndex then maxIndex = index end
        end
    end
    return maxIndex
end

-- 处理描述和链接序列
local function processDescriptionLinks(args, startIndex, maxIndex, pagename)
    local parts = {}
    local state = '' -- 状态: '' | 'link' | 'end'

    for i = startIndex, maxIndex do
        local value = args[i]
        if value then
            if state == 'link' then
                table.insert(parts, formatLink(value))
                state = 'end'
            elseif isConnector(value) then
                table.insert(parts, value)
            else
                if state == 'end' then table.insert(parts, ';') end
                local description = (value ~= '') and value or '其他用法'
                table.insert(parts, '关于' .. description .. ',请见')
                state = 'link'
            end
        end
    end

    -- fallback
    if state == 'link' then
        table.insert(parts, formatLink(pagename .. '(消歧义)'))
    end

    return parts, state
end

-- For
function p.about(frame)
    local args = getArgs(frame,
                         {trim = true, removeBlanks = true, parentOnly = true})

    local maxIndex = getMaxIndex(args)
    local title = mw.title.getCurrentTitle()
    local pagename = title.text

    local contentParts = {'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'}

    if args[1] then
        local pageType = getPageType(title, args.section)
        table.insert(contentParts,
                     '本' .. pageType .. '介绍的是' .. args[1])
    end

    local subsequentParts = processDescriptionLinks(args, 2, maxIndex, pagename)

    if maxIndex < 2 and args[1] then
        table.insert(subsequentParts, '关于其他用法,请见' ..
                         formatLink(pagename .. '(消歧义)'))
    end

    local finalParts = {table.concat(contentParts, '')}

    if #subsequentParts > 0 then
        if args[1] then table.insert(finalParts, '。 ') end
        table.insert(finalParts, table.concat(subsequentParts, ' '))
        table.insert(finalParts, '。')
    elseif args[1] then
        table.insert(finalParts, '。')
    end

    local finalContent = table.concat(finalParts, '')
    return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
end

-- For
function p.for2(frame)
    local args = getArgs(frame,
                         {trim = true, removeBlanks = true, parentOnly = true})

    local maxIndex = getMaxIndex(args)
    local title = mw.title.getCurrentTitle()
    local pagename = title.text

    local contentParts = {'[[File:Disambig gray.svg|25px|link=]]&nbsp;&nbsp;'}

    if args.R then table.insert(contentParts, args.R) end

    local subsequentParts = processDescriptionLinks(args, 1, maxIndex, pagename)

    if maxIndex < 1 then
        table.insert(subsequentParts, '关于其他用法,请见')
        table.insert(subsequentParts, formatLink(pagename .. '(消歧义)'))
    end

    local finalParts = {table.concat(contentParts, '')}

    if #subsequentParts > 0 then
        if args.R then table.insert(finalParts, ' ') end
        table.insert(finalParts, table.concat(subsequentParts, ' '))
        table.insert(finalParts, '。')
    end

    local finalContent = table.concat(finalParts, '')
    return frame:expandTemplate{title = 'hatnote', args = {finalContent}}
end

p['for'] = p.for2

return p