打开/关闭菜单
60
73
29
1.1K
武外梗百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:PageSummary:修订间差异

武外梗百科 爱国好学自强图新的百科全书
无编辑摘要
无编辑摘要
第1行: 第1行:
local p = {}
local p = {}


function p.render(frame)
-- 实际的逻辑处理函数
     -- 获取条目名称,默认为当前页
function p.getSummaryAndImage(frame)
     local pageTitle = frame.args[1] or mw.title.getCurrentTitle().text
     -- 如果你是通过模板调用,使用 getParent().args;如果是直接调用,使用 args
    local args = frame:getParent().args
     local pageTitle = args[1] or frame.args[1] or mw.title.getCurrentTitle().text
   
     local entityId = mw.wikibase.getEntityIdForTitle(pageTitle)
     local entityId = mw.wikibase.getEntityIdForTitle(pageTitle)


第10行: 第13行:
     end
     end


     -- 1. 获取描述 (Summary)
     -- 1. 获取描述
     local description = mw.wikibase.getDescription(entityId) or "暂无描述"
     local description = mw.wikibase.getDescription(entityId) or "暂无描述"


     -- 2. 获取图片 (P18 属性)
     -- 2. 获取图片 (P18)
     local image = ""
     local image = ""
     local claims = mw.wikibase.getBestStatements(entityId, 'P18')
     local claims = mw.wikibase.getBestStatements(entityId, 'P18')
第20行: 第23行:
     end
     end


     -- 3. 构建 UI
     -- 3. 构建简易 HTML
     local container = mw.html.create('div')
     local container = mw.html.create('div')
         :cssText('display: flex; gap: 15px; background: #f8f9fa; border: 1px solid #a2a9b1; padding: 10px; border-radius: 8px; max-width: 400px;')
         :cssText('display: flex; gap: 10px; border: 1px solid #ccc; padding: 10px; border-radius: 4px;')
 
      
     -- 左侧图片
     if image ~= "" then
     if image ~= "" then
         container:tag('div')
         container:tag('div'):wikitext(string.format('[[File:%s|80px]]', image))
            :cssText('flex-shrink: 0;')
            :wikitext(string.format('[[File:%s|100px]]', image))
     end
     end
 
      
     -- 右侧文字
     local text = container:tag('div')
     local textContainer = container:tag('div')
     text:tag('b'):wikitext(pageTitle):done()
     textContainer:tag('div')
     text:tag('p'):css('margin', '0'):wikitext(description)
        :cssText('font-weight: bold; font-size: 1.1em; margin-bottom: 5px;')
        :wikitext(pageTitle)
     textContainer:tag('div')
        :cssText('font-size: 0.9em; color: #54595d;')
        :wikitext(description)


     return tostring(container)
     return tostring(container)
end
end


-- 关键:确保导出名称完全一致
return p
return p