Module:Similar Vars

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 23:27, 11 October 2024 (Created page with "local navbox = require('Module:Navbox') local VariablesLua = mw.ext.VariablesLua local p = {} -- Create a link the the varb/varp page with the text 'NAME(index)' local function generatePagelink(t) if t['Variable index'] and t['Variable name'] then return '*[['..t[1]..'|'..t['Variable name']..'('..t['Variable index']..')]]' end -- If missing any of the required SMW data, just return the pagelink return '*[['..t[1]..']]' end local function getRelatedVars(content)..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Similar Vars/doc. [edit] [history] [purge]
Module:Similar Vars's function main is invoked by Template:Similar Vars.
Module:Similar Vars requires Module:Navbox.

Generates {{Similar Vars}} navbox used in Varbits project pages.


local navbox = require('Module:Navbox')
local VariablesLua = mw.ext.VariablesLua
local p = {}

-- Create a link the the varb/varp page with the text 'NAME(index)'
local function generatePagelink(t)
	if t['Variable index'] and t['Variable name'] then
		return '*[['..t[1]..'|'..t['Variable name']..'('..t['Variable index']..')]]'
	end
	-- If missing any of the required SMW data, just return the pagelink
	return '*[['..t[1]..']]'
end

local function getRelatedVars(content)
	local data = mw.smw.ask({
		'[[Variable content::'..content..']]',
		'?=#-',
		'?Variable name#-',
		'?Variable index#-',
	})
	local lineTable = {}
	if data == nil then
		return ''
	end
	for _, t in ipairs(data) do
		table.insert(lineTable, generatePagelink(t))
	end
	return table.concat(lineTable, "\n")
end

function p.main(frame)
	local args = frame:getParent().args
	local content = VariablesLua.var('content_var', 'Unknown')
	local raw_content = VariablesLua.var('raw_content_var', 'Unknown')

	args = {}
	args['name'] = 'Similar Vars'
	args['title'] = raw_content .. ' vars'
	
	args['group1'] = getRelatedVars(content)
	args['style1'] = 'text-align:center;'
	if args['group1'] ~= '' then
		return navbox._navbox(args)
	else
		return ''
	end
end

return p