Editing Module:TNT
From WikiOasis Meta
More actions
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 33: | Line 33: | ||
-- if the current page is Template:Graph:Lines/doc | -- if the current page is Template:Graph:Lines/doc | ||
-- | -- | ||
local p = {} | local p = {} | ||
| Line 91: | Line 86: | ||
end | end | ||
function p.doc(frame) | function p.doc(frame) | ||
local dataset = sanitizeDataset(frame.args[1] | local dataset = 'Templatedata/' .. sanitizeDataset(frame.args[1]) | ||
return frame:extensionTag('templatedata', p.getTemplateData(dataset)) .. | |||
return frame:extensionTag('templatedata', | formatMessage(i18nDataset, 'edit_doc', {link(dataset)}) | ||
end | end | ||
function p.getTemplateData(dataset) | function p.getTemplateData(dataset) | ||
-- TODO: add '_' parameter once lua starts reindexing properly for "all" languages | -- TODO: add '_' parameter once lua starts reindexing properly for "all" languages | ||
local data | local data = loadData(dataset) | ||
local names = {} | local names = {} | ||
for _, field in ipairs(data.schema.fields) do | for _, field in ipairs(data.schema.fields) do | ||
| Line 118: | Line 100: | ||
end | end | ||
local params = {} | local params = {} | ||
local paramOrder = {} | local paramOrder = {} | ||
| Line 132: | Line 113: | ||
end | end | ||
if name then | if name then | ||
params[name] = newVal | params[name] = newVal | ||
table.insert(paramOrder, name) | table.insert(paramOrder, name) | ||
| Line 147: | Line 119: | ||
-- Work around json encoding treating {"1":{...}} as an [{...}] | -- Work around json encoding treating {"1":{...}} as an [{...}] | ||
params['zzz123']='' | |||
local json = mw.text.jsonEncode({ | local json = mw.text.jsonEncode({ | ||
params=params, | params=params, | ||
paramOrder=paramOrder, | paramOrder=paramOrder, | ||
description=data.description | description=data.description | ||
}) | }) | ||
json = string.gsub(json,'"zzz123":"",?', "") | |||
return json | return json | ||
end | end | ||
| Line 182: | Line 148: | ||
end | end | ||
loadData = function(dataset, lang | loadData = function(dataset, lang) | ||
dataset = sanitizeDataset(dataset) | dataset = sanitizeDataset(dataset) | ||
if not dataset then | if not dataset then | ||
| Line 191: | Line 157: | ||
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(string.format([['''Missing JsonConfig extension, or not properly configured; | error(string.format([['''Missing JsonConfig extension, or not properly configured; | ||
Cannot load https://commons.wikimedia.org/wiki/Data:%s. | 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)) | See https://www.mediawiki.org/wiki/Extension:JsonConfig#Supporting_Wikimedia_templates''']], dataset)) | ||
end | end | ||
local | local data = mw.ext.data.get(dataset, lang) | ||
if data == false then | if data == false then | ||
| Line 223: | Line 168: | ||
error('Missing Commons dataset ' .. i18nDataset) | error('Missing Commons dataset ' .. i18nDataset) | ||
else | else | ||
error(formatMessage(i18nDataset, 'error_bad_dataset', {link( | error(formatMessage(i18nDataset, 'error_bad_dataset', {link(dataset)})) | ||
end | end | ||
end | end | ||
return data | return data | ||
end | end | ||