Module talk:TNT/Flow

About this board

Not-so-helpful "helpful error" message

3
Rwv37 (talkcontribs)

Trying to set up a MediaWiki-based site, and (apparently foolishly) am trying to get preexisting templates working on it. One problem I'm running into is that in (for example) Template:Ambox, this module complains:

Lua error in Module:TNT at line 158: Missing JsonConfig extension; Cannot load https://commons.wikimedia.org/wiki/Data:I18n/Documentation.tab.

Upon first seeing this, I installed the JsonConfig extension. The behavior did not change at all. After quite some time spent trying to figure out what was going on, I decided to actually look at the code, and found:

-- 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.wikimedia.org/wiki/Data:' .. dataset)
end

So, apparently this "helpful error" message is not merely not-terribly-helpful, but at least in some cases, it's actively misleading. It should not say "Missing JsonConfig extension"... unless that actually is the problem, which, in my case, I do not believe it is.

I assume that that was referring to the "mw.ext" check, which is probably passing for me, and the failure I'm getting is in either mw.ext.data or mw.ext.data.get. Unfortunately, I don't even have any idea what this module is for or what it's trying and failing to do here -- all I know is that it's breaking Template:Ambox (among others), so I don't know for sure. But I figured I should point out this issue with the "helpful error" in any case. -Rwv37 (talk) 10:12, 17 January 2022 (UTC)

Rwv37 (talkcontribs)

Incidentally, in case anyone has this same problem in the future, I just found this thread, in which User: Tacsipacsi's response worked for me. -Rwv37 (talk) 10:27, 17 January 2022 (UTC)

Ciencia Al Poder (talkcontribs)
Reply to "Not-so-helpful "helpful error" message"

Edit request: Correctly handle `null` values in `TemplateData` fields

11
Summary by ExE Boss

{{Edit Protected}}

ExE Boss (talkcontribs)
Yurik (talkcontribs)

Can't -- there is a failing unit test there - I suspect after one of the recent edits. I left a comment to the author - but feel free to fix it.

ExE Boss (talkcontribs)

That failing unit test is unrelated to my change (which passes test_doc).

Yurik (talkcontribs)

I was hoping to just copy/paste things. I will temp-revert the TNT sandbox to see if it works as is

ExE Boss (talkcontribs)

You can also run the tests while editing by using the Preview page with this template feature with Module:TNT/testcases as the target page.

Yurik (talkcontribs)

One more thing - could you add a unit test that shows the bug your change fixes?

This post was hidden by ExE Boss (history)
Yurik (talkcontribs)

Thanks! True, I could test it that way, but it only works if all tests are already in place, plus I do want to have a historical record of "this specific revision worked ok, and i copied it as is" :)

Yurik (talkcontribs)

thanks a lot for all the hard work on this, copied! :)

getting error in Module:TNT

4
AstiGallien (talkcontribs)

i freshly copied Module:TNT from MediaWiki to my wiki and got following error in the testcases:

Module:TNT[edit source]

2 tests failed.

Name Expected Actual
test_doc Lua error -- Module:TNT:124: mw.text.jsonEncode: Cannot use type 'boolean' as a table key
test_link
test_msg / msg31 text message a and b text message b and a
test_msg_errors
test_msg_format
test_msg_format_in_language

is there anything, i missed ?

Erutuon (talkcontribs)

I fixed the boolean table key error with this edit. This module is using pairs to iterate over integer keys starting at 1, but only ipairs is guaranteed to do that. I had never encountered pairs misbehaving, but it did here (tested using this edit). The loop iterated over data.schema.fields[i].name in random order and caused the later loop over data.data to think that the booleans in data.data[i] were names and insert them as keys into params in the table that is given to mw.text.jsonEncode. Replacing pairs with ipairs was the trick: it guarantees that the integer keys are iterated over sequentially.

Erutuon (talkcontribs)

The text message b and a thing was also caused by pairs. this edit fixed it at least in the testcases, though something bad may happen when there are gaps in parameters msg|I18n/Module:TNT/testcases.tab|text_link|3=a|5=b (it probably wouldn't use b) if anybody for some odd reason decides to use that syntax.

Erutuon (talkcontribs)

I'm guessing that the Scribunto installation on this wiki is a different version than on Wikimedia sites, because I've never encountered pairs randomly iterating over integer keys. The parser profiling table says "Lua virtual size" and "Lua estimated memory usage", whereas I see "Lua memory usage" on Wikimedia sites. Maybe that's a feature of the version that calls to Lua on the command line. Wildly guessing though.

Reply to "getting error in Module:TNT"

Lua error in Module:TNT

6
Grandtutor (talkcontribs)

I'm getting a lot of the following on templates I've imported from Wikipedia:

Lua error in Module:TNT at line 159: Missing JsonConfig extension; Cannot load https://commons.wikimedia.org/wiki/Data:I18n/Documentation.tab.

Honestly, I'm not sure if the problem is with Lua, Module:TNT or with JsonConfig, which is properly installed. For quick referernce, line 159 in Module:TNT is a part of this function:

-- 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.wikimedia.org/wiki/Data:' .. dataset)

end

Thanks for any input.

Nagiimos (talkcontribs)

Hi

Did you find the anwer ?

I have the same issue :(

Nagiimos (talkcontribs)

Seems we have to enable mw.data.ext.

Can be done by adding in localsettings.php: $wgJsonConfigEnableLuaSupport = true;.

AstiGallien (talkcontribs)

once having fixed that, i get following error:

Lua error -- Module:TNT:124: mw.text.jsonEncode: Cannot use type 'boolean' as a table key


Json is configured as follows:


wfLoadExtension( 'JsonConfig' );

$wgJsonConfigEnableLuaSupport = true;

// https://www.mediawiki.org/wiki/Extension:JsonConfig#Configuration

$wgJsonConfigModels['Tabular.JsonConfig'] = 'JsonConfig\JCTabularContent';

$wgJsonConfigs['Tabular.JsonConfig'] = [

'namespace' => 486,

'nsName' => 'Data',

// page name must end in ".tab", and contain at least one symbol

'pattern' => '/.\.tab$/',

'license' => 'CC0-1.0',

'isLocal' => false,

];

// Enable Tabular data namespace on Commons - T148745

$wgJsonConfigInterwikiPrefix = 'commons';

$wgJsonConfigs['Tabular.JsonConfig']['remote'] = [

'url' => 'https://commons.wikimedia.org/w/api.php'

];

Nagiimos (talkcontribs)

Thanx !

I missed this jsonconfig part !

AstiGallien (talkcontribs)

does work for you ? i still get Errors, see getting error in Module:TNT


did you install Extension(s) ?

Reply to "Lua error in Module:TNT"

How would one remove Module:TNT?

9
白龙 (talkcontribs)

Hi. I am an admin of an Wiki site in Mainland China, and we ported some modules from Mediawiki Wiki and Wikipedia (namely Module:Documentation); a lot of them depends on Module:TNT. Our wiki is small, has only one language (Chinese), and doesn't expect additional languages in the foreseeable future; thus, we don't need and don't have the skill to maintain TNT. And, the GFW makes TNT a pain as it still depends on Wikimedia (which would be blocked).

We would like to remove TNT from our port. Could anyone please point us as to how to do so? Any help is greatly appreciated.

The RedBurn (talkcontribs)

Update: sorry, I thought you were talking about a Wikimedia project.

I'm not sure why you would want to do that. By the way, every wiki has only one language.

You don't have to maintain the TNT module, it's synced by a bot. Its purpose is to allow every wiki to reuse modules and templates and be able to update them without having to retranslate them. You just translate the strings of the template or module in a .tab file on Commons and then you can sync your local copy of the template/module with the new version without having to modify it each time to add the translation.

Yurik (talkcontribs)

I don't think there is a way to "just remove it" -- every template and module uses it to localize itself, so you would have to replace every TNT usage with the actual string from the corresponding data table.

Dinoguy1000 (talkcontribs)

You mentioned you imported some things from Wikipedia; as far as I know, no Wikipedia language version makes use of Module:TNT or any similar system, so you might have some luck looking on Wikipedia for the templates/modules you need, and skipping MediaWiki.org entirely.

白龙 (talkcontribs)

Thanks! We just really liked the style of Template:Documentation on MediaWiki.org. We'll just try to deal with that one and avoid MediaWiki.org and go with Wikipedia modules in the future.

This post was hidden by 白龙 (history)
Pppery (talkcontribs)
Dinoguy1000 (talkcontribs)

Aah, fair. Clearly I need to be more careful about speaking outside of my competencies. =)

Reply to "How would one remove Module:TNT?"

Provide language for doc function

3
Mps (talkcontribs)

Hi, I would like to change local data = loadData(dataset) to local data = loadData(dataset, frame.args.lang) in the doc function.

The reason being, I would like to be able to do:

{{#invoke:TNT|doc|Graph:Lines|lang={{int:lang}}}}

This would allow that the TemplateData content is displayed in the language set by the user, and not by the Wikipedia language version. Currently, if a user on the German Wikipedia has set his preferred language to English, the UI as well as the TemplateData captions and so on are in English, but the the data coming from the translation dataset is in German.

I tried to use the Scribunto/Lua equivalent of {{int:lang}}, i.e. mw.message.new("lang"):plain(), but strangely this also returns the Wikipedia content language and not the user language.

I'm specifically asking to be on the safe side as you specifically put a TODO above the line I want to change.

Yurik (talkcontribs)

@Mps hi, thx for writing. I think that TNT should use user's language as oppose to content language in very few cases. TNT produces parts of content, not parts of the user interface. So for example, if you are reading an article with a graph, you expect the text under the graph to be in the same language as the rest of the article. On the other hand, the toolbars and commands at the top should all be in the user-selected language, as that's part of the interface.

That said, I totally agree that template data may benefit from being in the interface language.

As for your question... I don't know for sure, but I have a suspicion that it was done on purpose - WMF doesn't want content to have non-content language, because that fragments the cache, and greatly increases server load. Imagine, instead of having one version of the page, WMF has to have potentially 300 the moment you add some UI-language-dependent template to it.

So, if the {{int:...}} approach works, I would simply create a template wrapper for calling TNT module. What do you think?

P.S. I also think it might be a good idea to use something like https://beta.observablehq.com/ to have a simple conversion tool -- to convert existing template data to a table json format.

Mps (talkcontribs)

Hi @Yurik:, sorry for not answering earlier. Yes a wrapper template seems to be the best choice as it could also help remove the fluff, i.e. providing the method name which is always the same and even the name of the template to describe as this could also be inferred e.g. via {{#titleparts:{{PAGENAME}}|1}}, so that in most cases the user would just need to inject the TNT wrapper template without any parameters to get proper localized template data.

Regarding the PS: A converter for existing template data JSON to data table JSON would certainly be helpful. I can't really say much about beta.observablehq.com as I am myself not much of of a web guy. So I don't know how much of a fitting framework it is.

Reply to "Provide language for doc function"
Mps (talkcontribs)

I think in the example Original/Template:Graphs.tab should be changed to I18n/Template:Graphs.tab as this looks more like the preferred way to name and mark localization resource tables.

Yurik (talkcontribs)

Thanks @Mps, agree. You are very welcome to make changes too btw :)

Reply to "Example"
There are no older topics
Return to "TNT/Flow" page.