From Terraria Wiki
Jump to navigation Jump to search
Lua.svg Documentation The documentation below is transcluded from Module:Test/doc. (edit | history)

A test module to avoid disturbing "real" pages.

See Terraria Wiki:Lua for more information about Lua and links to other help resources.

Feel free to test this module at Terraria Wiki:Sandbox.

-- We only invoke this module once per page, therefore we do not need to use mw.loadData()
-- This cache is set in Module:Language_info/data
-- Note: 
-- If a template that's being used by large number of page changed, it will causing all of these page's cache to be invalidated and requires regeneration.
-- This may crash wiki platform and cause visitor get 5xx error. So we use luacache to decouple data template and template which uses it.
-- By doing this, editing on data template won't cause massive pages to be regenerated.
local cache = require 'mw.ext.LuaCache'
local info = cache.get(':_language_info:data')
if not info then
	info = cache.get(':_language_info:data') or {}

return {
	interwiki_links = function(frame)
		local key = frame.args['en']
		local lang = frame.args['lang']
		local str = ''
		-- local str = '<div style="display:none">languageinfo: en: '..key..' lang: '..lang..'</div>' -- debug code
		for k,v in pairs(info) do
			if k ~= lang then
				if v[key] then
					str = str .. '__' .. k .. ':'.. v[key] .. ']]'
		return str