Module:Ask: Difference between revisions
From 20R1
No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
local query = '[[' .. property.. '::' .. filter.. ']]' | local query = '[[' .. property.. '::' .. filter.. ']]' | ||
if condition ~= '' then table.insert( query, condition ) end | if condition ~= '' then table.insert( query, condition ) end | ||
--table.insert( query, '?Name' ) | --table.insert( query, '?Club Name' ) | ||
--table.insert( query, '?Population' ) | --table.insert( query, '?Population' ) | ||
table.insert( query, 'format=table' ) | table.insert( query, 'format=table' ) | ||
| Line 17: | Line 17: | ||
if not results then return 'No results' end | 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'} | local html = {'<table class="wikitable">\n<tr><th>Page</th><th>Name</th><th>Population</th></tr>\n'} | ||
for _, row in ipairs( results ) do | for _, row in ipairs( results ) do | ||
table.insert( html, string.format( | table.insert( html, string.format( | ||
'<tr><td>[[:%s]]</td><td>%s</td><td>%s</td></tr>\n', | '<tr><td>[[:%s]]</td><td>%s</td><td>%s</td></tr>\n', | ||
row.fulltext | row.fulltext | ||
row.printouts.Name and row.printouts.Name[1] or '', | --row.printouts.Name and row.printouts.Name[1] or '', | ||
row.printouts.Population and row.printouts.Population[1] or '' | --row.printouts.Population and row.printouts.Population[1] or '' | ||
) ) | ) ) | ||
end | end | ||
Revision as of 23:19, 19 November 2025
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, '?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
