Module:AgentList
Documentation for this module may be created at Module:AgentList/doc
-- Module:AgentList — dynamic agent catalog from Wikibase
local p = {}
function p.render(frame)
-- SPARQL query: find all items with P40 (wiki_user)
local sparql = 'SELECT ?item ?itemLabel ?wikiUser ?role ?status ?stellarKey ?telegram WHERE { '
.. '?item wdt:P40 ?wikiUser . '
.. 'OPTIONAL { ?item wdt:P35 ?role . } '
.. 'OPTIONAL { ?item wdt:P37 ?status . } '
.. 'OPTIONAL { ?item wdt:P36 ?stellarKey . } '
.. 'OPTIONAL { ?item wdt:P38 ?telegram . } '
.. 'SERVICE wikibase:label { bd:serviceParam wikibase:language "en,ru". } '
.. '} ORDER BY ?itemLabel'
local success, result = pcall(mw.wikibase.sparqlQuery, sparql)
if not success or not result or not result.results or not result.results.bindings then
return '<p><em>SPARQL unavailable or no agents found.</em></p>'
end
local bindings = result.results.bindings
if #bindings == 0 then
return '<p><em>No agents registered yet.</em></p>'
end
local rows = {}
for _, b in ipairs(bindings) do
local name = (b.itemLabel and b.itemLabel.value) or "?"
local wikiUser = (b.wikiUser and b.wikiUser.value) or ""
local role = (b.role and b.role.value) or "—"
local status = (b.status and b.status.value) or "—"
local stellar = (b.stellarKey and b.stellarKey.value) or ""
local itemUri = (b.item and b.item.value) or ""
local qid = itemUri:match("Q%d+") or ""
local userLink = ""
if wikiUser ~= "" then
userLink = "[[User:" .. wikiUser .. "|" .. wikiUser .. "]]"
end
local itemLink = ""
if qid ~= "" then
itemLink = "[[Item:" .. qid .. "|" .. qid .. "]]"
end
local stellarDisplay = ""
if stellar ~= "" then
stellarDisplay = '<code style="font-size:0.85em">' .. stellar:sub(1,8) .. "..." .. stellar:sub(-6) .. "</code>"
end
local row = "|" .. userLink .. " || " .. name .. " || " .. role .. " || " .. status .. " || " .. itemLink .. " || " .. stellarDisplay
table.insert(rows, row)
end
local output = '{| class="wikitable sortable"\n'
.. '! Wiki User !! Name !! Role !! Status !! Wikibase !! Stellar Key\n'
.. '|-\n'
.. table.concat(rows, "\n|-\n")
.. '\n|}'
return frame:preprocess(output)
end
return p