Module:TNT: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
MeowyCats2 (talk | contribs) m 17 revisions imported |
||
(7 intermediate revisions by 5 users not shown) | |||
Line 20: | Line 20: | ||
-- | -- | ||
-- {{#invoke:TNT | msg | -- {{#invoke:TNT | msg | ||
-- | I18n/Template:Graphs.tab <!-- https://commons. | -- | I18n/Template:Graphs.tab <!-- https://commons.wikimedia.org/wiki/Data:I18n/Template:Graphs.tab --> | ||
-- | source-table <!-- uses a translation message with id = "source-table" --> | -- | source-table <!-- uses a translation message with id = "source-table" --> | ||
-- | param1 }} <!-- optional parameter --> | -- | param1 }} <!-- optional parameter --> | ||
Line 30: | Line 30: | ||
-- | -- | ||
-- {{#invoke:TNT | doc | Graph:Lines }} | -- {{#invoke:TNT | doc | Graph:Lines }} | ||
-- uses https://commons. | -- uses https://commons.wikimedia.org/wiki/Data:Templatedata/Graph:Lines.tab | ||
-- if the current page is Template:Graph:Lines/doc | -- if the current page is Template:Graph:Lines/doc | ||
-- | -- | ||
Line 50: | Line 50: | ||
id = mw.text.trim(v) | id = mw.text.trim(v) | ||
elseif type(k) == 'number' then | elseif type(k) == 'number' then | ||
params[k - 2] = mw.text.trim(v) | |||
elseif k == 'lang' and v ~= '_' then | elseif k == 'lang' and v ~= '_' then | ||
lang = mw.text.trim(v) | lang = mw.text.trim(v) | ||
Line 80: | Line 80: | ||
end | end | ||
-- Obsolete function that adds a ' | -- Obsolete function that adds a 'c:' prefix to the first param. | ||
-- "Sandbox/Sample.tab" -> ' | -- "Sandbox/Sample.tab" -> 'c:Data:Sandbox/Sample.tab' | ||
function p.link(frame) | function p.link(frame) | ||
return link(frame.args[1]) | return link(frame.args[1]) | ||
Line 96: | Line 96: | ||
local data = loadData(dataset) | local data = loadData(dataset) | ||
local names = {} | local names = {} | ||
for _, field in | for _, field in ipairs(data.schema.fields) do | ||
table.insert(names, field.name) | table.insert(names, field.name) | ||
end | end | ||
Line 102: | Line 102: | ||
local params = {} | local params = {} | ||
local paramOrder = {} | local paramOrder = {} | ||
for _, row in | for _, row in ipairs(data.data) do | ||
local newVal = {} | local newVal = {} | ||
local name = nil | local name = nil | ||
for pos, | for pos, columnName in ipairs(names) do | ||
if columnName == 'name' then | if columnName == 'name' then | ||
name = | name = row[pos] | ||
else | else | ||
newVal[columnName] = | newVal[columnName] = row[pos] | ||
end | end | ||
end | end | ||
Line 157: | Line 156: | ||
-- Give helpful error to thirdparties who try and copy this module. | -- 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 | if not mw.ext or not mw.ext.data or not mw.ext.data.get then | ||
error('Missing JsonConfig extension; Cannot load https://commons. | error(string.format([['''Missing JsonConfig extension, or not properly configured; | ||
Cannot load https://commons.wikimedia.org/wiki/Data:%s. Please properly enable the JSONConfig extension at Special:ManageWiki/extensions#mw-prefsection-other | |||
See https://www.mediawiki.org/wiki/Extension:JsonConfig#Supporting_Wikimedia_templates''']], dataset)) | |||
end | end | ||
Line 175: | Line 176: | ||
-- Given a dataset name, convert it to a title with the 'commons:data:' prefix | -- Given a dataset name, convert it to a title with the 'commons:data:' prefix | ||
link = function(dataset) | link = function(dataset) | ||
return ' | return 'c:Data:' .. mw.text.trim(dataset or '') | ||
end | end | ||