Module:TNT: Difference between revisions

32 bytes removed ,  5 months ago
m
1 revision imported
No edit summary
m (1 revision imported)
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
(8 intermediate revisions by 4 users not shown)
Line 20:
--
-- {{#invoke:TNT | msg
-- | I18n/Template:Graphs.tab <!-- https://commons.mirahezewikimedia.org/wiki/Data:I18n/Template:Graphs.tab -->
-- | source-table <!-- uses a translation message with id = "source-table" -->
-- | param1 }} <!-- optional parameter -->
Line 30:
--
-- {{#invoke:TNT | doc | Graph:Lines }}
-- uses https://commons.mirahezewikimedia.org/wiki/Data:Templatedata/Graph:Lines.tab
-- if the current page is Template:Graph:Lines/doc
--
Line 50:
id = mw.text.trim(v)
elseif type(k) == 'number' then
table.insert(params,[k - 2] = mw.text.trim(v))
elseif k == 'lang' and v ~= '_' then
lang = mw.text.trim(v)
Line 80:
end
 
-- Obsolete function that adds a 'commonsc:' prefix to the first param.
-- "Sandbox/Sample.tab" -> 'commonsc:Data:Sandbox/Sample.tab'
function p.link(frame)
return link(frame.args[1])
Line 96:
local data = loadData(dataset)
local names = {}
for _, field in pairsipairs(data.schema.fields) do
table.insert(names, field.name)
end
Line 102:
local params = {}
local paramOrder = {}
for _, row in pairsipairs(data.data) do
local newVal = {}
local name = nil
for pos, valcolumnName in pairsipairs(rownames) do
local columnName = names[pos]
if columnName == 'name' then
name = valrow[pos]
else
newVal[columnName] = valrow[pos]
end
end
Line 157 ⟶ 156:
-- Give helpful error to thirdparties who try and copy this module.
if not mw.ext or not mw.ext.data or not mw.ext.data.get then
error('Missing JsonConfig extension; Cannot load https://commons.mirahezewikimedia.org/wiki/Data:' .. dataset)
end
 
Line 175 ⟶ 174:
-- Given a dataset name, convert it to a title with the 'commons:data:' prefix
link = function(dataset)
return 'commonsc:Data:' .. mw.text.trim(dataset or '')
end