Module:ListPeople: Difference between revisions
Appearance
Created page with "local p = {} local cargo = mw.ext.cargo function p.get() local peopleSet = {} -- Fetch Composer values local composerResults = cargo.query('Compositions', 'Composer', { groupBy = 'Composer', limit = 1000 }) -- Fetch Arranger values local arrangerResults = cargo.query('Compositions', 'Arranger', { groupBy = 'Arranger', limit = 1000 }) local function addNames(field) for _, row in ipairs(field) do..." |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.get() | function p.get() | ||
local cargo = mw.ext.cargo | |||
local peopleSet = {} | local peopleSet = {} | ||
local function safeQuery(field) | |||
local success, result = pcall(function() | |||
return cargo.query('Compositions', field, { | |||
groupBy = field, | |||
limit = 1000 | |||
}) | |||
end) | |||
if not success then | |||
return {} | |||
end | |||
return result | |||
end | |||
local function addNames(resultTable, field) | |||
for _, row in ipairs(resultTable) do | |||
local names = row[field] or '' | |||
for name in mw.text.gsplit(names, '[,;]') do | |||
local function addNames(field) | |||
for _, row in ipairs( | |||
for name in mw.text.gsplit( | |||
name = mw.text.trim(name) | name = mw.text.trim(name) | ||
if name ~= '' then | if name ~= '' then | ||
Line 29: | Line 30: | ||
end | end | ||
addNames( | -- Query and process both Composer and Arranger | ||
addNames( | local composers = safeQuery('Composer') | ||
addNames(composers, 'Composer') | |||
local arrangers = safeQuery('Arranger') | |||
addNames(arrangers, 'Arranger') | |||
-- | -- Sort and format | ||
local | local list = {} | ||
for name | for name in pairs(peopleSet) do | ||
table.insert( | table.insert(list, name) | ||
end | end | ||
table.sort( | table.sort(list) | ||
local output = {} | |||
for _, name in ipairs(list) do | |||
for _, name in ipairs( | table.insert(output, '* [[' .. name .. ']]') | ||
table.insert( | |||
end | end | ||
return table.concat( | return table.concat(output, '\n') | ||
end | end | ||
return p | return p |
Latest revision as of 03:27, 23 July 2025
Documentation for this module may be created at Module:ListPeople/doc
local p = {}
function p.get()
local cargo = mw.ext.cargo
local peopleSet = {}
local function safeQuery(field)
local success, result = pcall(function()
return cargo.query('Compositions', field, {
groupBy = field,
limit = 1000
})
end)
if not success then
return {}
end
return result
end
local function addNames(resultTable, field)
for _, row in ipairs(resultTable) do
local names = row[field] or ''
for name in mw.text.gsplit(names, '[,;]') do
name = mw.text.trim(name)
if name ~= '' then
peopleSet[name] = true
end
end
end
end
-- Query and process both Composer and Arranger
local composers = safeQuery('Composer')
addNames(composers, 'Composer')
local arrangers = safeQuery('Arranger')
addNames(arrangers, 'Arranger')
-- Sort and format
local list = {}
for name in pairs(peopleSet) do
table.insert(list, name)
end
table.sort(list)
local output = {}
for _, name in ipairs(list) do
table.insert(output, '* [[' .. name .. ']]')
end
return table.concat(output, '\n')
end
return p