Module:FeaturedArticle:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第4行: | 第4行: | ||
function p.show(frame) | function p.show(frame) | ||
local smw = mw.smw | local smw = mw.smw | ||
-- 查询所有 IsFeatured::Yes 页面 | -- 查询所有 IsFeatured::Yes 页面 | ||
2025年11月30日 (日) 12:47的最新版本
此模块的文档可以在Module:FeaturedArticle/doc创建
local p = {}
-- 显示随机特色条目
function p.show(frame)
local smw = mw.smw
-- 查询所有 IsFeatured::Yes 页面
local results = smw.ask{
query = "[[IsFeatured::Yes]]",
limit = 0, -- 获取全部
format = "o" -- 返回对象
}
if not results or #results == 0 then
return "(暂无特色条目)"
end
-- 随机选择一个条目
math.randomseed(os.time() % 2147483647)
local row = results[math.random(1, #results)]
local title = row.fulltext or "未知页面"
-- 构造 HTML 卡片
local html = mw.html.create('div'):addClass('fa-box')
html:tag('div'):addClass('fa-title'):wikitext('⭐ 今日特色条目')
html:tag('div'):addClass('fa-article-title'):wikitext('[['..title..']]')
html:tag('div'):addClass('fa-link'):wikitext('[['..title..'|阅读全文 →]]')
return html:allHtml()
end
return p