Module:CRTBrandList: Difference between revisions
Create module to dynamically generate CRT brand list from semantic query (via create-page on MediaWiki MCP Server) |
Revert to original category-based approach - direct queries don't scale well with 2000+ CRT models (via update-page on MediaWiki MCP Server) Tag: Manual revert |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- Module:CRTBrandList | -- Module:CRTBrandList | ||
-- Dynamically generates a list of CRT brand buttons by querying | -- Dynamically generates a list of CRT brand buttons by querying | ||
-- all | -- pre-computed brand category pages with semantic properties. | ||
-- Much faster than scanning all CRT model pages. | |||
local p = {} | local p = {} | ||
| Line 15: | Line 16: | ||
function p.list(frame) | function p.list(frame) | ||
local args = frame.args | local args = frame.args | ||
local linkType = args.link | local linkType = trim(args.link) | ||
-- Query all | -- Query brand category pages (fast - only queries category pages, not all CRTs) | ||
local queryWikitext = | local queryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[ | ' [[Is CRT brand category::Yes]]\n' .. | ||
' |? | ' |?Brand name\n' .. | ||
' |format=broadtable\n' .. | ' |format=broadtable\n' .. | ||
' |headers=hide\n' .. | ' |headers=hide\n' .. | ||
| Line 27: | Line 28: | ||
' |mainlabel=-\n' .. | ' |mainlabel=-\n' .. | ||
' |limit=500\n' .. | ' |limit=500\n' .. | ||
' |searchlabel=\n' .. | |||
'}}' | '}}' | ||
local queryResult = frame:preprocess(queryWikitext) | local queryResult = frame:preprocess(queryWikitext) | ||
-- Extract | -- Extract brand names from result | ||
local brandsList = {} | local brandsList = {} | ||
| Line 38: | Line 39: | ||
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('<[^>]+>', '')) | ||
if brand and brand ~= '' | if brand and brand ~= '' then | ||
table.insert(brandsList, brand) | table.insert(brandsList, brand) | ||
end | end | ||
| Line 55: | Line 55: | ||
local output = {} | local output = {} | ||
for _, brand in ipairs(brandsList) do | for _, brand in ipairs(brandsList) do | ||
local templateCall = '{{Brand entry|brand=' .. brand .. '|link=' .. linkType .. '}}' | local templateCall | ||
if linkType then | |||
templateCall = '{{Brand entry|brand=' .. brand .. '|link=' .. linkType .. '}}' | |||
else | |||
templateCall = '{{Brand entry|brand=' .. brand .. '}}' | |||
end | |||
table.insert(output, frame:preprocess(templateCall)) | table.insert(output, frame:preprocess(templateCall)) | ||
end | end | ||