No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
function p.randomCargoRecord(frame) | function p.randomCargoRecord(frame) | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local tableName = | local args = getArgs(frame); | ||
local tableName = args[1] | |||
if tableName == nil or tableName == "" then | if tableName == nil or tableName == "" then | ||
hasErrors = true | hasErrors = true | ||
return string.format("<code>tableName</code> parameter is required") | |||
end | end | ||
if hasErrors then return CATEGORY_INVALID_ARGS end | if hasErrors then return CATEGORY_INVALID_ARGS end |
Revision as of 06:36, 27 December 2023
Documentation for this module may be created at Module:RandomCargoRecord/doc
local p = {} local cargo = mw.ext.cargo function p.randomCargoRecord(frame) local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame); local tableName = args[1] if tableName == nil or tableName == "" then hasErrors = true return string.format("<code>tableName</code> parameter is required") end if hasErrors then return CATEGORY_INVALID_ARGS end local countFields = 'COUNT(*)=total' local countArgs = {} local countResults = cargo.query(tableName, countFields, countArgs) local total = countResults.total local queryFields = 'game,link' local countOffset = math.random(1, total) local args = { format = table, fields = queryFields, limit = 1, offset = countOffset } local result = cargo.query(tableName, fields, args) for r = 1, #results do local result = results[r] return string.format("<h1>%s</h1>", result.link) end end