Module:PageSummary:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
function p.render(frame) | |||
function p. | -- 获取条目名称,默认为当前页 | ||
local pageTitle = frame.args[1] or mw.title.getCurrentTitle().text | |||
local entityId = mw.wikibase.getEntityIdForTitle(pageTitle) | |||
if not entityId then | |||
if not | return '<div class="error">未找到关联的 Wikibase 项目。</div>' | ||
return | |||
end | end | ||
local | -- 1. 获取描述 (Summary) | ||
local description = mw.wikibase.getDescription(entityId) or "暂无描述" | |||
-- | -- 2. 获取图片 (P18 属性) | ||
local image = "" | |||
local | local claims = mw.wikibase.getBestStatements(entityId, 'P18') | ||
if claims[1] and claims[1].mainsnak.datavalue then | |||
image = claims[1].mainsnak.datavalue.value | |||
end | end | ||
-- 3. 构建 UI | |||
-- 3. | |||
local container = mw.html.create('div') | local container = mw.html.create('div') | ||
:cssText('display: flex; gap: 15px; | :cssText('display: flex; gap: 15px; background: #f8f9fa; border: 1px solid #a2a9b1; padding: 10px; border-radius: 8px; max-width: 400px;') | ||
if | -- 左侧图片 | ||
if image ~= "" then | |||
container:tag('div') | container:tag('div') | ||
:cssText('flex: 0 | :cssText('flex-shrink: 0;') | ||
:wikitext( | :wikitext(string.format('[[File:%s|100px]]', image)) | ||
end | end | ||
container:tag('div') | -- 右侧文字 | ||
:cssText(' | local textContainer = container:tag('div') | ||
:wikitext( | textContainer:tag('div') | ||
: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 | ||
2026年2月18日 (三) 12:56的版本
此模块的文档可以在Module:PageSummary/doc创建
local p = {}
function p.render(frame)
-- 获取条目名称,默认为当前页
local pageTitle = frame.args[1] or mw.title.getCurrentTitle().text
local entityId = mw.wikibase.getEntityIdForTitle(pageTitle)
if not entityId then
return '<div class="error">未找到关联的 Wikibase 项目。</div>'
end
-- 1. 获取描述 (Summary)
local description = mw.wikibase.getDescription(entityId) or "暂无描述"
-- 2. 获取图片 (P18 属性)
local image = ""
local claims = mw.wikibase.getBestStatements(entityId, 'P18')
if claims[1] and claims[1].mainsnak.datavalue then
image = claims[1].mainsnak.datavalue.value
end
-- 3. 构建 UI
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;')
-- 左侧图片
if image ~= "" then
container:tag('div')
:cssText('flex-shrink: 0;')
:wikitext(string.format('[[File:%s|100px]]', image))
end
-- 右侧文字
local textContainer = container:tag('div')
textContainer:tag('div')
: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)
end
return p