Lua error in MediaWiki

I am trying to create a MediaWiki and am trying to use a Navbox template. I had everything working fine on my local machine, but when I copied it all to the server, I got Lua script errors, in particular:

Lua error at line 302: attempt to call field 'attr' (a nil value). Backtrace: (tail call): ? Module:Navbox:302: in function "renderMainTable" Module:Navbox:348: in function "renderMainTable" (tail call): ? mw.lua:425: ? (tail call): ? [C]: in function "xpcall" MWServer.lua:73: in function "handleCall" MWServer.lua:266: in function "dispatch" MWServer.lua:33: in function "execute" mw_main.lua:7: in main chunk [C]: ? 

If I edit this file, it just gives an error for all other fields.

My server runs MediaWiki 1.20, if that matters. I tried with Scribunto 1.20, 1.21 and master (making changes to the engines in accordance with 1.20).

If someone can help, it will be great.

Edited modules: Navbox , HtmlBuilder .

+8
lua mediawiki-templates mediawiki scribunto
source share
2 answers

Look carefully, very carefully, at your password-related code compared to Wikipedia code. In fact, I would recommend making the difference between the two.

Your code

 metatable._index = function(t, key) local ret = rawget(t, key) if ret then return ret end ret = metatable[key] if type(ret) == 'function' then return function(...) return ret(t, ...) end else return ret end end 

Wikipedia

 metatable.__index = function(t, key) local ret = rawget(t, key) if ret then return ret end ret = metatable[key] if type(ret) == 'function' then return function(...) return ret(t, ...) end else return ret end end 

Do you see the difference? Meta methods in Lua always start with two underscores __ , not one. I'm not sure how your code got into the state it is in, but it will very well explain all the problems you had, even why attr not available. This was due to the __index __index , in which there is no underscore, which, of course, means that it will not be recognized at all. I am surprised that I noticed, as it is easy to skip this extra underline when skimming.

I would recommend first restoring your HtmlBuilder module to its original state, and then see if this fixes the problem. You might want to restore NavBox and any others that you may have changed if your changes are not too significant, but diff will definitely tell you what differs from your versions.

Just remember that you will change in the future, but do not be afraid to experiment while you have backups!

+6
source share

Let me say that it is very difficult to try to answer your question. In the original post, you do not say much, which will help solve the problem. I will simply describe this line of code that you mentioned:

 function renderMainTable() local tbl = HtmlBuilder.create('table') .attr('cellspacing', 0) .addClass('nowraplinks') .addClass(args.bodyclass) 

I would probably try replacing it with the following:

 function renderMainTable() local tbl = HtmlBuilder.create('table') 
+3
source share

All Articles