Module:Dependencies

From COMP15212 Wiki
Revision as of 12:47, 26 July 2019 by gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This module adds dependencies to Semantic MediaWiki and prints the dependencies on screen. In the future it will print the dependencies in a prettier way. This module needs to be called directly rather than through a template because of its use of a variable number of arguments.


local p = {}
p.add = function(frame)
	local output = "{| class=dependstable\n"
	output = output .. "! Depends on \n| "
	
	--[[ Each argument is a pair of string,int where the string is the name of the article being depended on
	     and int is the strength of the dependency]]
	local hasDep = false
	for i, v in ipairs(frame.args) do
		local spliterator = (v..","):gmatch("(.-),")
		local dependency = spliterator()
		local strength = spliterator()
		frame:expandTemplate{ title = 'SetDependency', args = { dependency, strength, tostring(mw.title.getCurrentTitle().fullText) } }
        output = output ..  "[[".. dependency .."]] • "
        hasDep = true
	end
	if hasDep then
		output = string.sub(output, 0, -5)
	else
		output = output .. "This article has no dependencies."
	end
	output = output .. " \n|}"
	return output
end
return p