Module:Ask: Difference between revisions

From 20R1
No edit summary
No edit summary
Line 2: Line 2:


function p.test( frame )
function p.test( frame )
local smw = require( 'ext.smw.api' )
--local smw = require( 'ext.smw.api' )
local queryString = '[[Club Name::+]]|?Start Date|limit=10'
local queryString = '[[Club Name::+]]|?Start Date|limit=10'

Revision as of 23:26, 19 November 2025

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

local p = {}

function p.test( frame )
	--local smw = require( 'ext.smw.api' )
	
	local queryString = '[[Club Name::+]]|?Start Date|limit=10'
	local result = smw.getQueryResult( queryString )
	
	-- Then iterate:
	local data = result:results()  -- table of pages → printouts
end

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 ) 
    	else table.insert( query )
    end
    --table.insert( query, '?Club 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'}
    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