Module:Cargo
Jump to navigation
Jump to search
The query
function of this module is an alternative to #cargo_query
with format=template
. It should not be used as an alternative to #cargo_query
for any other format
.
The latter is subject to an intermittent bug that causes output to appear as unrendered HTML requiring a purge to correct. The query
function avoids the bug by processing the template transclusion in Lua after running the query through Cargo, rather than having Cargo perform both steps.
Usage is similar to a #cargo_query
call:
{{#invoke:cargo|query |tables= |fields= |where= |join= |groupBy= |having= |orderBy= |template= |intro= |outro= |default= |limit= |offset= }}
See Extension:Cargo/Querying data for more information, as the parameters here have the same usage as in #cargo_query
with the following exceptions:
table
cannot be used as an alternative totables
join
is used instead ofjoin on
groupBy
is used instead ofgroup by
orderBy
is used instead oforder by
- This function always behaves as if
named args
isyes
local p = {}
function p.makeError(msg)
return tostring(
mw.html.create('strong')
:addClass('error')
:wikitext('Cargo Query Error: ', msg)
:done()
) .. '[[Category:Pages with cargo query errors]]'
end
function p.query( frame )
local success, results = pcall(mw.ext.cargo.query, frame.args.tables, frame.args.fields, {
where = frame.args.where,
join = frame.args.join,
groupBy = frame.args.groupBy,
having = frame.args.having,
orderBy = frame.args.orderBy,
limit = frame.args.limit,
offset = frame.args.offset,
} )
if not success then
return p.makeError(results)
end
local out
if #results > 0 then
out = frame.args.intro or ''
for index = 1, #results, 1 do
out = out .. '\n' .. frame:expandTemplate{ title = frame.args.template, args = results[index] }
end
out = out .. '\n' .. ( frame.args.outro or '' )
else
out = frame.args.default or ''
end
if frame.args.debug == "yes" then
out = out .. "\n----\n" .. frame.args.where .. "\n----\nResults: " .. #results
end
return out
end
return p