跳转到内容
打开/关闭菜单
  • 451 条目
  • 808 文件
  • 22 用户
  • 9259 编辑
Blockland Wiki
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Infobox settlement:修订间差异

来自Blockland Wiki
创建页面,内容为“local p = {} -- 辅助函数:检查参数是否存在且不为空 local function hasValue(arg) return arg and arg:match('%S') end -- 构建信息框的单行数据 local function buildRow(label, data) if hasValue(data) then local row = mw.html.create('tr') row:tag('th'):css('width', '30%'):wikitext(label) row:tag('td'):wikitext(data) return tostring(row) end return '' end -- 构建子标题行 local function…”
 
无编辑摘要
第17行: 第17行:
end
end


-- 构建子标题行
-- 构建分组子标题行
local function buildSubheader(text)
local function buildSubheader(text)
     if hasValue(text) then
     if hasValue(text) then
第67行: 第67行:
         end
         end
         image_cell:wikitext(image_wikitext)
         image_cell:wikitext(image_wikitext)
    end
   
    -- *** 新增:蓝色背景的类型标题 ***
    if hasValue(args.type) then
        root:tag('tr'):tag('th')
            :attr('colspan', '2')
            :css('text-align', 'center')
            :css('background', '#DDEEFF') -- 维基百科风格的淡蓝色
            :wikitext(args.type)
     end
     end



2025年10月31日 (五) 20:25的版本

此模块的文档可以在模块:Infobox settlement/doc创建

local p = {}

-- 辅助函数:检查参数是否存在且不为空
local function hasValue(arg)
    return arg and arg:match('%S')
end

-- 构建信息框的单行数据
local function buildRow(label, data)
    if hasValue(data) then
        local row = mw.html.create('tr')
        row:tag('th'):css('width', '30%'):wikitext(label)
        row:tag('td'):wikitext(data)
        return tostring(row)
    end
    return ''
end

-- 构建分组子标题行
local function buildSubheader(text)
    if hasValue(text) then
        local row = mw.html.create('tr')
        row:tag('th')
           :attr('colspan', '2')
           :css('background', '#E8E8E8')
           :css('text-align', 'center')
           :wikitext(text)
        return tostring(row)
    end
    return ''
end

-- 主函数,生成整个信息框
function p.main(frame)
    local args = frame:getParent().args
    local root = mw.html.create('table')
    root:addClass('infobox')
       :css('width', '300px')
       :css('font-size', '90%')

    -- 标题
    local title = args.name or mw.title.getCurrentTitle().text
    local title_cell = root:tag('tr'):tag('th')
        :attr('colspan', '2')
        :css('text-align', 'center')
        :css('font-size', '125%')
        :css('padding', '0.5em')
        :wikitext(title)

    -- 原生名称 (副标题)
    if hasValue(args.native_name) then
         root:tag('tr'):tag('th')
            :attr('colspan', '2')
            :css('text-align', 'center')
            :css('font-style', 'italic')
            :wikitext(args.native_name)
    end

    -- 图片和图注
    if hasValue(args.image) then
        local image_cell = root:tag('tr'):tag('td')
            :attr('colspan', '2')
            :css('text-align', 'center')
        local image_wikitext = '[[File:' .. args.image .. '|280px]]'
        if hasValue(args.image_caption) then
            image_wikitext = image_wikitext .. '<br /><span>' .. args.image_caption .. '</span>'
        end
        image_cell:wikitext(image_wikitext)
    end
    
    -- *** 新增:蓝色背景的类型标题 ***
    if hasValue(args.type) then
        root:tag('tr'):tag('th')
            :attr('colspan', '2')
            :css('text-align', 'center')
            :css('background', '#DDEEFF') -- 维基百科风格的淡蓝色
            :wikitext(args.type)
    end

    -- 格言
    if hasValue(args.motto) then
        root:tag('tr'):tag('th')
           :attr('colspan', '2')
           :css('text-align', 'center')
           :css('font-style', 'italic')
           :css('padding', '0.5em')
           :wikitext('"' .. args.motto .. '"')
    end

    -- 开始构建数据部分
    local rows = {}
    table.insert(rows, buildSubheader('概况'))
    table.insert(rows, buildRow('国家', args.country))
    table.insert(rows, buildRow(args.subdivision_type or '省份', args.subdivision_name))
    table.insert(rows, buildRow(args.leader_title or '领主', args.leader_name))
    
    table.insert(rows, buildSubheader('地理'))
    table.insert(rows, buildRow('总面积', (args.area_total_km2 or '') .. ' km²'))
    table.insert(rows, buildRow('海拔', (args.elevation_m or '') .. ' m'))

    table.insert(rows, buildSubheader('人口'))
    table.insert(rows, buildRow('总计', args.population_total))
    table.insert(rows, buildRow('密度', args.population_density_km2))

    -- 将所有行添加到表格中
    root:wikitext(table.concat(rows))

    return tostring(root)
end

return p