Module:PageSummary:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
function p. | -- 实际的逻辑处理函数 | ||
-- | 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. 获取描述 | -- 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. | -- 3. 构建简易 HTML | ||
local container = mw.html.create('div') | local container = mw.html.create('div') | ||
:cssText('display: flex; gap: | :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)) | ||
end | end | ||
local text = container:tag('div') | |||
local | text:tag('b'):wikitext(pageTitle):done() | ||
text:tag('p'):css('margin', '0'):wikitext(description) | |||
return tostring(container) | return tostring(container) | ||
end | end | ||
-- 关键:确保导出名称完全一致 | |||
return p | return p | ||