Module:FeaturedPages:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
创建页面,内容为“local p = {} function p.render(frame) local category = frame.args.category or "Featured" local limit = tonumber(frame.args.count) or 4 local api = mw.api local result = api.get({ action = "query", list = "categorymembers", cmtitle = "Category:" .. category, cmnamespace = 0, cmlimit = limit }) if not result or not result.query or not result.query.categorymembers then return "<p>暂无推…” |
无编辑摘要 |
||
| (未显示同一用户的1个中间版本) | |||
| 第5行: | 第5行: | ||
local limit = tonumber(frame.args.count) or 4 | local limit = tonumber(frame.args.count) or 4 | ||
local | local catTitle = mw.title.new("Category:" .. category) | ||
if not catTitle or not catTitle.exists then | |||
return "<p>分类不存在。</p>" | |||
if not | |||
return "<p> | |||
end | end | ||
local | local pages = catTitle:getContent() -- 占位,确保对象存在 | ||
local members = mw.site.stats.pages -- 触发加载 | |||
-- Scribunto 无法直接枚举分类成员 | |||
-- 所以:Lua 只能负责“包装”,不负责“查询” | |||
return | return string.format( | ||
'<div class="featured-list">[[Category:%s|查看推荐条目 →]]</div>', | |||
category | |||
) | |||
end | end | ||
return p | return p | ||
2025年12月13日 (六) 21:13的最新版本
此模块的文档可以在Module:FeaturedPages/doc创建
local p = {}
function p.render(frame)
local category = frame.args.category or "Featured"
local limit = tonumber(frame.args.count) or 4
local catTitle = mw.title.new("Category:" .. category)
if not catTitle or not catTitle.exists then
return "<p>分类不存在。</p>"
end
local pages = catTitle:getContent() -- 占位,确保对象存在
local members = mw.site.stats.pages -- 触发加载
-- Scribunto 无法直接枚举分类成员
-- 所以:Lua 只能负责“包装”,不负责“查询”
return string.format(
'<div class="featured-list">[[Category:%s|查看推荐条目 →]]</div>',
category
)
end
return p