Module:Ask

From 20R1
Revision as of 23:16, 19 November 2025 by Alex (talk | contribs)

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

local p = {}

function p.query( frame )
    local args = frame.args
    local property= args.property or 'Club Name'
    local filter= args.filter or '+'
    local condition = args.condition or ''

    local query = '[[' .. property.. '::' .. filter.. ']]'
    if condition ~= '' then table.insert( query, condition ) end
    --table.insert( query, '?Name' )
    --table.insert( query, '?Population' )
    table.insert( query, 'format=table' )
    table.insert( query, 'limit=' .. (args.limit or '50') )

    local results = smw.ask( query )
    if not results then return 'No results' end

    local html = {'<table class="wikitable">\n<tr><th>Page</th><th>Name</th><th>Population</th></tr>\n'}
    for _, row in ipairs( results ) do
        table.insert( html, string.format(
            '<tr><td>[[:%s]]</td><td>%s</td><td>%s</td></tr>\n',
            row.fulltext,
            row.printouts.Name and row.printouts.Name[1] or '',
            row.printouts.Population and row.printouts.Population[1] or ''
        ) )
    end
    table.insert( html, '</table>' )
    return table.concat( html )
end

return p