Create Lua module for brand directory (via create-page on MediaWiki MCP Server)
 
Fix bracket escaping for SMW query (via update-page on MediaWiki MCP Server)
 
Line 2: Line 2:


function p.brandDirectory(frame)
function p.brandDirectory(frame)
    local smw = mw.smw
     -- Use callParserFunction for SMW query
    if not smw then
     local queryResult = frame:callParserFunction{
        return "SMW not available"
        name = '#ask',
    end
        args = {
   
            '[[Category:CRT models]]',
     -- Query all CRT models and their brands
            '?Has brand',
     local results = smw.ask({
            format = 'array',
        "[[Category:CRT models]]",
            sep = ';;;',
        "?Has brand",
            propsep = ':::',
        limit = 1000
            limit = '1000'
     })
        }
     }
      
      
     if not results then
     if not queryResult or queryResult == "" then
         return "No CRT models found"
         return "No CRT models found"
     end
     end
      
      
     -- Count CRTs per brand
     -- Parse results and count brands
     local brandCounts = {}
     local brandCounts = {}
     for _, row in ipairs(results) do
     for entry in string.gmatch(queryResult, "[^;;;]+") do
         local brand = row["Has brand"]
        -- Each entry is "PageName:::BrandName"
         if brand then
         local parts = mw.text.split(entry, ":::")
             -- Handle case where brand might be a table (multiple values)
         if parts[2] then
            if type(brand) == "table" then
             local brand = mw.text.trim(parts[2])
                brand = brand[1]
             if brand ~= "" then
            end
             if brand and brand ~= "" then
                 brandCounts[brand] = (brandCounts[brand] or 0) + 1
                 brandCounts[brand] = (brandCounts[brand] or 0) + 1
             end
             end
Line 42: Line 41:
     end)
     end)
      
      
     -- Generate HTML output
     -- Generate HTML output with responsive column styles
     local html = mw.html.create('div')
     local html = mw.html.create('div')
         :addClass('brand-directory')
         :addClass('brand-directory')
         :css('column-count', '4')
         :cssText('column-count: 4; column-gap: 2em; margin: 1.5em 0;')
        :css('column-gap', '2em')
        :css('margin', '1.5em 0')
      
      
     for _, brand in ipairs(sortedBrands) do
     for _, brand in ipairs(sortedBrands) do
         local count = brandCounts[brand]
         local count = brandCounts[brand]
         local item = html:tag('div')
         local item = html:tag('div')
             :css('break-inside', 'avoid')
             :cssText('break-inside: avoid; margin-bottom: 0.5em; line-height: 1.6;')
            :css('margin-bottom', '0.5em')
            :css('line-height', '1.6')
          
          
         -- Create link to brand page
         -- Create link to brand page using wikitext
         local brandPage = "CRTs by " .. brand
         local brandPage = "CRTs by " .. brand
         item:wikitext('[[' .. brandPage .. '|' .. brand .. ']]')
         local linkMarkup = "[[" .. brandPage .. "|" .. brand .. "]]"
        item:wikitext(linkMarkup)
         item:tag('span')
         item:tag('span')
             :css('color', '#72777d')
             :cssText('color: #72777d; font-size: 0.9em; margin-left: 0.3em;')
            :css('font-size', '0.9em')
            :css('margin-left', '0.3em')
             :wikitext('(' .. count .. ')')
             :wikitext('(' .. count .. ')')
     end
     end
      
      
     return tostring(html)
    -- Add responsive CSS
    local style = mw.html.create('style')
        :wikitext('@media (max-width: 1200px) { .brand-directory { column-count: 3 !important; } }')
        :wikitext('@media (max-width: 800px) { .brand-directory { column-count: 2 !important; } }')
        :wikitext('@media (max-width: 500px) { .brand-directory { column-count: 1 !important; } }')
   
     return tostring(style) .. tostring(html)
end
end


return p
return p

Latest revision as of 16:41, 10 January 2026

Documentation for this module may be created at Module:BrandDirectory/doc

local p = {}

function p.brandDirectory(frame)
    -- Use callParserFunction for SMW query
    local queryResult = frame:callParserFunction{
        name = '#ask',
        args = {
            '[[Category:CRT models]]',
            '?Has brand',
            format = 'array',
            sep = ';;;',
            propsep = ':::',
            limit = '1000'
        }
    }
    
    if not queryResult or queryResult == "" then
        return "No CRT models found"
    end
    
    -- Parse results and count brands
    local brandCounts = {}
    for entry in string.gmatch(queryResult, "[^;;;]+") do
        -- Each entry is "PageName:::BrandName"
        local parts = mw.text.split(entry, ":::")
        if parts[2] then
            local brand = mw.text.trim(parts[2])
            if brand ~= "" then
                brandCounts[brand] = (brandCounts[brand] or 0) + 1
            end
        end
    end
    
    -- Sort brands alphabetically
    local sortedBrands = {}
    for brand, _ in pairs(brandCounts) do
        table.insert(sortedBrands, brand)
    end
    table.sort(sortedBrands, function(a, b)
        return string.lower(a) < string.lower(b)
    end)
    
    -- Generate HTML output with responsive column styles
    local html = mw.html.create('div')
        :addClass('brand-directory')
        :cssText('column-count: 4; column-gap: 2em; margin: 1.5em 0;')
    
    for _, brand in ipairs(sortedBrands) do
        local count = brandCounts[brand]
        local item = html:tag('div')
            :cssText('break-inside: avoid; margin-bottom: 0.5em; line-height: 1.6;')
        
        -- Create link to brand page using wikitext
        local brandPage = "CRTs by " .. brand
        local linkMarkup = "[[" .. brandPage .. "|" .. brand .. "]]"
        item:wikitext(linkMarkup)
        item:tag('span')
            :cssText('color: #72777d; font-size: 0.9em; margin-left: 0.3em;')
            :wikitext('(' .. count .. ')')
    end
    
    -- Add responsive CSS
    local style = mw.html.create('style')
        :wikitext('@media (max-width: 1200px) { .brand-directory { column-count: 3 !important; } }')
        :wikitext('@media (max-width: 800px) { .brand-directory { column-count: 2 !important; } }')
        :wikitext('@media (max-width: 500px) { .brand-directory { column-count: 1 !important; } }')
    
    return tostring(style) .. tostring(html)
end

return p
MediaWiki Appliance - Powered by TurnKey Linux