More actions
test |
No edit summary |
||
Line 3: | Line 3: | ||
local util = require('Module:Utility') | local util = require('Module:Utility') | ||
function p. | function p.category(frame) | ||
local out = {} | local out = {} | ||
if frame.args.category ~= nil then | if frame.args.category ~= nil then |
Latest revision as of 14:16, 7 May 2025
Documentation for this module may be created at Module:List/doc
local p = {}
local util = require('Module:Utility')
function p.category(frame)
local out = {}
if frame.args.category ~= nil then
local payload = {
source=mw.site.server .. mw.site.scriptPath .. '/api.php?action=query&format=json&generator=categorymembers&gcmlimit=max&gcmtitle=Category:' .. util.firstToUpper(frame.args.category),
format='json'
}
header_depth = '==';
if frame.args.header ~= nil then
for i=0,frame.args.header do
header_depth = header_depth .. '='
end
end
local json = mw.ext.externalData.getExternalData(payload)
for _,page in ipairs(json) do
if (page['title'] ~= nil) then
if (page['title'] ~= frame.args['category']) and (string.find(page['title'],'Category:') == nil) then
table.insert(out, frame:preprocess('\n'.. header_depth .. page['title'] .. header_depth .. '\n'))
table.insert(out, frame:expandTemplate({title='SmallLink', args = { page['title'] } }))
table.insert(out, frame:expandTemplate({title=':' .. page['title']}))
table.insert(out, frame:preprocess('\n----'))
end
end
end
end
return table.concat(out)
end
return p