-------------------------------------------------------------------------------
-- Utility stuff
--
-- Module:Util
--
-- This meta module contains a number of utility functions
-------------------------------------------------------------------------------
local xtable = require('Module:Table')
-- The cfg table contains all localisable strings and configuration, to make it
local string_format = string.format
-- easier to port this module to another wiki.
local string_gsub = string.gsub
local cfg = mw.loadData('Module:Util/config')
local mwi18n = mwcfg.i18n
local cargo = mw.ext.cargo
local i18n = {
bool_false = {'false', '0', 'disabled', 'off', 'no', '', 'deactivated'},
range = '(%s-%s)',
args = {
-- util.args.stat
stat_infix = 'stat',
stat_id = 'id',
stat_min = 'min',
stat_max = 'max',
stat_value = 'value',
-- util.args.weight_list
spawn_weight_prefix = 'spawn_weight',
generation_weight_prefix = 'generation_weight',
},
errors = {
-- util.cast.factory.*
missing_element = 'Element "%s" not found',
-- util.cast.factory.percentage
invalid_argument = 'Argument "%s" is invalid. Please check the documentation for acceptable values.',
not_a_percentage = '%s must be a percentage (in range 0 to 100).',
-- util.cast.boolean
not_a_boolean = 'value "%s" of type "%s" is not a boolean',
-- util.cast.number
not_a_number = 'value "%s" of type "%s" is not an integer',
number_too_small = '"%i" is too small. Minimum: "%i"',
number_too_large = '"%i" is too large. Maximum: "%i"',
-- util.cast.version
malformed_version_string = 'Malformed version string "%s"',
non_number_version_component = '"%s" has an non-number component',
unrecognized_version_number = '"%s" is not a recognized version number',
-- util.args.stats
improper_stat = '%sstat%s is improperly set; id and either value or min/max must be specified.',
-- util.args.weight_list
invalid_weight = 'Both %s and %s must be specified',
-- util.args.version
too_many_versions = 'The number of results (%s) does not match the number version arguments (%s)',
-- util.args.from_cargo_map
missing_key_in_fields = 'Key "%s" not found in the fields mapping of table "%s"',
table_object_as_default = 'Warning: table object as default value on key "%s" in mapping of table "%s"',
missing_key_in_order = 'Fields mapping of table "%s" has the following extra keys that are not handled by order:\n%s',
handler_returned_nil = 'Handler for "%s.fields.%s" returned nil for argument "%s". Check whether the value is correct for the given field type "%s".',
argument_required = 'Argument "%s" is required',
-- util.html.error
module_error = 'Module Error: ',
-- util.misc.raise_error_or_return
invalid_raise_error_or_return_usage = 'Invalid usage of raise_error_or_return.',
-- util.smw.array_query
duplicate_ids_found = 'Found multiple pages for id property "%s" with value "%s": %s, %s',
missing_ids_found = 'No results were found for id property "%s" with the following values: %s',
-- util.string.split_args
number_of_arguments_too_large = 'Number of arguments near = is too large (%s).',
},
}
-- ----------------------------------------------------------------------------
end
local results = cargom_cargo.query(
{'Versions'},
{'release_date', 'version'},
{
where = table.concat(version_ids, ' OR '),
}
)
end
return (string_gsubstring.gsub(str, "({([^}]+)})",
function(whole, i)
return vars[i] or whole
if not _ then
error(string_formatstring.format('Field "%s" doesn\'t exist', field))
end
-- this happen if 'validate' returns nil
if _.required == true and _.value == nil then
error(string_formatstring.format('Field "%s" is required but has been set to nil', field))
end
end
if not _ then
error(string_formatstring.format('Field "%s" doesn\'t exist', field))
end
if not _ then
error(string_formatstring.format('Field "%s" doesn\'t exist', field))
end
if not _ then
error(string_formatstring.format('Field "%s" doesn\'t exist', field))
end
if not _ then
error(string_formatstring.format('Field "%s" doesn\'t exist', field))
end
|