Module:AVBrandList: Difference between revisions
Arclight changed the content model of the page Module:AVBrandList from "wikitext" to "Scribunto module" |
Increase query limit and suppress "further results" link for consistency (via update-page on MediaWiki MCP Server) |
||
| Line 15: | Line 15: | ||
function p.list(frame) | function p.list(frame) | ||
-- Query all AV devices and get their brands | -- Query all AV devices and get their brands | ||
-- | -- Use high limit and searchlabel= to suppress "further results" | ||
local queryWikitext = | local queryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
| Line 24: | Line 24: | ||
' |link=none\n' .. | ' |link=none\n' .. | ||
' |mainlabel=-\n' .. | ' |mainlabel=-\n' .. | ||
' |limit= | ' |limit=5000\n' .. | ||
' |searchlabel=\n' .. | |||
'}}' | '}}' | ||
| Line 34: | Line 35: | ||
if queryResult then | if queryResult then | ||
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do | for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do | ||
local brand = trim(cellContent:gsub('<[^>]+>', '')) | local brand = trim(cellContent:gsub('<[^>]+>', '')) | ||
| Line 47: | Line 47: | ||
table.sort(brandsList) | table.sort(brandsList) | ||
if #brandsList == 0 then | if #brandsList == 0 then | ||
return '<p><em>No AV device brands found.</em></p>' | return '<p><em>No AV device brands found.</em></p>' | ||
Revision as of 21:23, 4 February 2026
Documentation for this module may be created at Module:AVBrandList/doc
-- Module:AVBrandList
-- Dynamically generates a list of AV device brand buttons by querying
-- all unique brands from the AV devices category.
local p = {}
local function trim(s)
if s == nil then return nil end
s = tostring(s)
s = s:gsub('^%s+', ''):gsub('%s+$', '')
if s == '' then return nil end
return s
end
function p.list(frame)
-- Query all AV devices and get their brands
-- Use high limit and searchlabel= to suppress "further results"
local queryWikitext =
'{{#ask:\n' ..
' [[Category:AV devices]]\n' ..
' |?Has brand\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
' |mainlabel=-\n' ..
' |limit=5000\n' ..
' |searchlabel=\n' ..
'}}'
local queryResult = frame:preprocess(queryWikitext)
-- Extract unique brands from the result
local brandsSet = {}
local brandsList = {}
if queryResult then
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
local brand = trim(cellContent:gsub('<[^>]+>', ''))
if brand and brand ~= '' and not brandsSet[brand] then
brandsSet[brand] = true
table.insert(brandsList, brand)
end
end
end
-- Sort alphabetically
table.sort(brandsList)
if #brandsList == 0 then
return '<p><em>No AV device brands found.</em></p>'
end
-- Build the output: render each brand using Template:AV brand entry
local output = {}
for _, brand in ipairs(brandsList) do
local templateCall = '{{AV brand entry|brand=' .. brand .. '}}'
table.insert(output, frame:preprocess(templateCall))
end
return table.concat(output, '\n')
end
return p