Modulo:TNT: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m Copying 4 changes by Yurik: "no auto I18n/ prefix, breaks some graphs, fixed doc link, Trim parameter whitespaces, docs link" from mw:Module:TNT. See docs. |
Update from master using #Synchronizer |
||
(4 versioni intermedie di un altro utente non mostrate) | |||
Riga 36:
local p = {}
local i18nDataset = 'I18n/Module:TNT.tab'
local checkType = require('libraryUtil').checkType▼
-- Forward declaration of the local functions
local
function p.msg(frame)
Riga 51 ⟶ 50:
id = mw.text.trim(v)
elseif type(k) == 'number' then
elseif k == 'lang' and v ~= '_' then
lang = mw.text.trim(v)
Riga 60 ⟶ 59:
-- Identical to p.msg() above, but used from other lua modules
-- Example with 2 params: format('I18n/Module:TNT', 'error_bad_msgkey', 'my-key', 'my-dataset')
function p.format(dataset, key, ...)
▲ local checkType = require('libraryUtil').checkType
checkType('format', 1, dataset, 'string')
checkType('format', 2, key, 'string')
checkType('format', 3, params, 'table', true)▼
checkType('format', 4, lang, 'string', true)▼
▲ return formatMessage(dataset, key, params, lang)
end
-- Identical to p.msg() above, but used from other lua modules with the language param
-- "Sandbox/Sample.tab" -> 'commons:Data:Sandbox/Sample.tab'▼
-- Parameters: language code, name of dataset, message key, optional arguments
-- Example with 2 params: formatInLanguage('es', I18n/Module:TNT', 'error_bad_msgkey', 'my-key', 'my-dataset')
function p.formatInLanguage(lang, dataset, key, ...)
local checkType = require('libraryUtil').checkType
checkType('formatInLanguage', 2, dataset, 'string')
return formatMessage(dataset, key, {...}, lang)
-- Obsolete function that adds a 'c:' prefix to the first param.
function p.link(frame)
return link(frame.args[1])
Riga 75 ⟶ 87:
function p.doc(frame)
▲ ) .. formatMessage(i18nDataset, 'edit_doc', {link(dataset)})
end
function p.getTemplateData(
▲ dataset = 'Templatedata/' .. mw.text.trim(page)
-- TODO: add '_' parameter once lua starts reindexing properly for "all" languages
local data = loadData(dataset)
local names = {}
for _, field in
table.insert(names, field.name)
end
local numOnly = true
local params = {}
local paramOrder = {}
for _, row in
local newVal = {}
local name = nil
for pos,
if columnName == 'name' then
name =
else
newVal[columnName] =
end
end
if name then
if (
(type(name) ~= "number")
and (
(type(name) ~= "string")
or not string.match(name, "^%d+$")
)
) then
numOnly = false
end
params[name] = newVal
table.insert(paramOrder, name)
Riga 110 ⟶ 129:
-- Work around json encoding treating {"1":{...}} as an [{...}]
if numOnly then
end
local json = mw.text.jsonEncode({
params=params,
paramOrder=paramOrder,
description=data.description,
})
if numOnly then
end
return json
Riga 124 ⟶ 147:
-- Local functions
sanitizeDataset = function(dataset)
if not dataset then
end
dataset = mw.text.trim(dataset)
return nil
elseif string.sub(dataset,-4) ~= '.tab' then
else▼
end
end
loadData = function(dataset, lang)
if not dataset then
error(formatMessage(i18nDataset, 'error_no_dataset', {}))
end
▲ if string.sub(dataset,-4) ~= '.tab' then
-- Give helpful error to thirdparties who try and copy this module.
▲ dataset = dataset .. '.tab'
if not mw.ext or not mw.ext.data or not mw.ext.data.get then
error(string.format([['''Missing JsonConfig extension, or not properly configured;
Cannot load https://commons.wikimedia.org/wiki/Data:%s.
See https://www.mediawiki.org/wiki/Extension:JsonConfig#Supporting_Wikimedia_templates''']], dataset))
end
Riga 148 ⟶ 190:
-- Given a dataset name, convert it to a title with the 'commons:data:' prefix
link = function(dataset)
▲ return dataset
▲ else
▲ return 'commons:' .. dataset
▲ end
end
|