可在模块:AU信息框/image/doc创建此模块的帮助文档
local p = {} function p.getImages(frame) local category = "AU" -- 获取传入的参数 local limit = tonumber(frame.args.limit) or 10 -- 构建查询 local query = {} table.insert(query, "[[Category:" .. category .. "]]") table.insert(query, "?Image") query.mainlabel = "title" -- 设置主标签为"title" query.limit = limit -- 设置结果数量限制 local result = mw.smw.ask(query) -- 执行查询 -- 构建结果字符串 local output = "" local count = 0 if type(result) == "table" then for _, row in pairs(result) do local image = row["Image"] local title = row.title if type(image) == "table" then image = image[1] -- 获取表格中的第一个值 end if image and title then output = output .. '<div class="col-md-3 p-3 text-white" style="box-sizing: border-box;">' .. "[[" .. image .. "|150px|link=" .. title .. "]]" .. '</div>' count = count + 1 if limit > 0 and count >= limit then break -- 达到限制数量后停止迭代 end end end end return output end return p