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

模块:Infobox settlement:修订间差异

来自Blockland Wiki
无编辑摘要
无编辑摘要
第6行: 第6行:
end
end


-- 构建分组子标题行
-- 构建分组子标题行 (调整了背景色以模仿维基百科样式)
local function buildSubheader(text)
local function buildSubheader(label)
     if hasValue(text) then
     if hasValue(label) then
         local row = mw.html.create('tr')
         local row = mw.html.create('tr')
         row:tag('th')
         row:tag('th')
           :attr('colspan', '2')
           :attr('colspan', '2')
           :css('background', '#E6E6FA') -- 淡紫色
           :css('background', '#f0f0f0') -- 更改为浅灰色
           :css('text-align', 'center')
           :css('text-align', 'left')    -- 标签靠左
           :wikitext(text)
          :css('padding-left', '0.4em')
          :css('font-weight', 'bold')
           :wikitext(label)
         return tostring(row)
         return tostring(row)
     end
     end
第20行: 第22行:
end
end


-- 构建信息框的单行数据
-- 构建信息框的单行数据(标签+数据)
local function buildRow(label, data)
local function buildRow(label, data)
     if hasValue(data) then
     if hasValue(data) then
第49行: 第51行:
     if hasValue(args.native_name) then
     if hasValue(args.native_name) then
         title_cell:wikitext('<br /><span style="font-size:85%; font-weight:normal;">' .. args.native_name .. '</span>')
         title_cell:wikitext('<br /><span style="font-size:85%; font-weight:normal;">' .. args.native_name .. '</span>')
    end
    -- 行政区分类子标题 (模仿维基百科样式)
    if hasValue(args.type) then
        local type_row = mw.html.create('tr')
        type_row:tag('th')
            :attr('colspan', '2')
            :css('background', '#cddeff') -- 淡蓝色背景
            :css('text-align', 'center')
            :css('font-weight', 'bold')
            :wikitext(args.type)
        root:wikitext(tostring(type_row))
     end
     end


第56行: 第70行:
             :attr('colspan', '2')
             :attr('colspan', '2')
             :css('text-align', 'center')
             :css('text-align', 'center')
         local image_wikitext = '[[File:' .. args.image .. '|280px]]'
         local image_wikitext = '[[File:' .. args.image .. '|290x220px|frameless]]'
         if hasValue(args.image_caption) then
         if hasValue(args.image_caption) then
             image_wikitext = image_wikitext .. '<br /><span>' .. args.image_caption .. '</span>'
             image_wikitext = image_wikitext .. '<br /><span style="font-size:90%;">' .. args.image_caption .. '</span>'
         end
         end
         image_cell:wikitext(image_wikitext)
         image_cell:wikitext(image_wikitext)
    end
   
    -- 坐标行
    if hasValue(args.lon) or hasValue(args.lat) then
        -- 将坐标直接放在图片下方,不使用子标题或普通行,模仿维基样式
        local coord_row = mw.html.create('tr')
        coord_row:tag('td')
            :attr('colspan', '2')
            :css('text-align', 'center')
            :css('font-size', '95%')
            :wikitext('坐标:' .. (args.lat or '') .. ' ' .. (args.lon or ''))
        root:wikitext(tostring(coord_row))
     end
     end
      
      
     -- 开始构建数据部分
     -- 开始构建数据部分
     local rows = {}
     local rows = {}
    table.insert(rows, buildSubheader('基本信息'))
    -- 特殊处理坐标行
    if hasValue(args.lon) or hasValue(args.lat) then
        local coord_data = '经度 ' .. (args.lon or '未提供') .. '<br />纬度 ' .. (args.lat or '未提供')
        table.insert(rows, buildRow('坐标', coord_data))
    end
      
      
     table.insert(rows, buildSubheader('地理位置'))
     -- 地理位置
     table.insert(rows, buildRow('国家', args.country))
     table.insert(rows, buildRow('国家', args.country))
     table.insert(rows, buildRow('省', args.province))
    table.insert(rows, buildRow('自治区', args.province)) -- 标签改为更通用的“自治区”或“省”
     table.insert(rows, buildRow('省', args.province2))     -- 添加一个额外的省份/区域字段
      
      
     table.insert(rows, buildSubheader('行政'))
    -- 人口信息
    -- 已简化的行政区分类行
    local pop_header_text = '人口'
     table.insert(rows, buildRow('分类', args.type))
    if hasValue(args.population_as_of) then
     table.insert(rows, buildRow('设立', args.established))
        pop_header_text = pop_header_text .. ' (' .. args.population_as_of .. ')'
    table.insert(rows, buildRow('市长', args.mayor))
    end
 
     table.insert(rows, buildSubheader(pop_header_text))
    -- 人口信息(没有子标题)
     table.insert(rows, buildRow(' • 总计', args.population))
    if hasValue(args.population) then
      
        local pop_data = args.population
    -- 时区信息
        if hasValue(args.population_as_of) then
    if hasValue(args.timezone) then
            pop_data = pop_data .. ' 人 (' .. args.population_as_of .. ')'
        table.insert(rows, buildSubheader('时区'))
        local tz_data = args.timezone
        if hasValue(args.utc_offset) then
            tz_data = tz_data .. ' (' .. args.utc_offset .. ')'
        end
        table.insert(rows, buildRow(' ', tz_data)) -- 标签留空,让内容靠左
       
        if hasValue(args.timezone_DST) then
            local tz_dst_data = args.timezone_DST
            if hasValue(args.utc_offset_DST) then
                tz_dst_data = tz_dst_data .. ' (' .. args.utc_offset_DST .. ')'
            end
            table.insert(rows, buildRow(' • 夏时制', tz_dst_data))
         end
         end
        table.insert(rows, buildRow('人口', pop_data))
     end
     end



2025年11月1日 (六) 17:19的版本

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

local p = {}

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

-- 构建分组子标题行 (调整了背景色以模仿维基百科样式)
local function buildSubheader(label)
    if hasValue(label) then
        local row = mw.html.create('tr')
        row:tag('th')
           :attr('colspan', '2')
           :css('background', '#f0f0f0') -- 更改为浅灰色
           :css('text-align', 'left')    -- 标签靠左
           :css('padding-left', '0.4em')
           :css('font-weight', 'bold')
           :wikitext(label)
        return tostring(row)
    end
    return ''
end

-- 构建信息框的单行数据(标签+数据)
local function buildRow(label, data)
    if hasValue(data) then
        local row = mw.html.create('tr')
        row:tag('th'):css('width', '30%'):css('text-align', 'left'):wikitext(label)
        row:tag('td'):wikitext(data)
        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.2em')
        :wikitext(title)
    if hasValue(args.native_name) then
        title_cell:wikitext('<br /><span style="font-size:85%; font-weight:normal;">' .. args.native_name .. '</span>')
    end

    -- 行政区分类子标题 (模仿维基百科样式)
    if hasValue(args.type) then
        local type_row = mw.html.create('tr')
        type_row:tag('th')
            :attr('colspan', '2')
            :css('background', '#cddeff') -- 淡蓝色背景
            :css('text-align', 'center')
            :css('font-weight', 'bold')
            :wikitext(args.type)
        root:wikitext(tostring(type_row))
    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 .. '|290x220px|frameless]]'
        if hasValue(args.image_caption) then
            image_wikitext = image_wikitext .. '<br /><span style="font-size:90%;">' .. args.image_caption .. '</span>'
        end
        image_cell:wikitext(image_wikitext)
    end
    
    -- 坐标行
    if hasValue(args.lon) or hasValue(args.lat) then
         -- 将坐标直接放在图片下方,不使用子标题或普通行,模仿维基样式
        local coord_row = mw.html.create('tr')
        coord_row:tag('td')
            :attr('colspan', '2')
            :css('text-align', 'center')
            :css('font-size', '95%')
            :wikitext('坐标:' .. (args.lat or '') .. ' ' .. (args.lon or ''))
        root:wikitext(tostring(coord_row))
    end
    
    -- 开始构建数据部分
    local rows = {}
    
    -- 地理位置
    table.insert(rows, buildRow('国家', args.country))
    table.insert(rows, buildRow('自治区', args.province)) -- 标签改为更通用的“自治区”或“省”
    table.insert(rows, buildRow('省', args.province2))     -- 添加一个额外的省份/区域字段
    
    -- 人口信息
    local pop_header_text = '人口'
    if hasValue(args.population_as_of) then
        pop_header_text = pop_header_text .. ' (' .. args.population_as_of .. ')'
    end
    table.insert(rows, buildSubheader(pop_header_text))
    table.insert(rows, buildRow(' • 总计', args.population))
    
    -- 时区信息
    if hasValue(args.timezone) then
        table.insert(rows, buildSubheader('时区'))
        local tz_data = args.timezone
        if hasValue(args.utc_offset) then
            tz_data = tz_data .. ' (' .. args.utc_offset .. ')'
        end
        table.insert(rows, buildRow(' ', tz_data)) -- 标签留空,让内容靠左
        
        if hasValue(args.timezone_DST) then
            local tz_dst_data = args.timezone_DST
            if hasValue(args.utc_offset_DST) then
                tz_dst_data = tz_dst_data .. ' (' .. args.utc_offset_DST .. ')'
            end
            table.insert(rows, buildRow(' • 夏时制', tz_dst_data))
        end
    end

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

    return tostring(root)
end

return p