Module:Top icons

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Top icons/doc. [edit] [history] [purge]
Module:Top icons's function main is invoked by Template:External.
Module:Top icons is required by Module:Update.
Function list
L 36 — p.main
L 41 — p._main

Module used for Template:External. Can also be imported into modules to display top icons.

This module is a helper module to be used by other modules; it may not be designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUse
_main( wiki1, wiki2, ... )string, string, ...Returns a string that adds top icons for the given wiki names. Values must be one of os, dw, rsc, meta or wp.
_main( wiki1 = pagename1, wiki2 = pagename2, ... )string, string, ...Returns a string that adds top icons for the given wiki names, linking to the specified page names. Wiki names must be one of os, dw, rsc, meta or wp.

--<nowiki>
local p = {}

local sites = {
	os = {
		params = { 'os' },
		interwiki = 'osrsw',
		wikiname = 'The Old School RuneScape Wiki',
	},
	rsc = {
		params = { 'rsc' },
		interwiki = 'classicrsw',
		wikiname = 'The RuneScape Classic Wiki',
	},
	meta = {
		params = { 'meta' },
		interwiki = 'meta',
		wikiname = 'The Meta RuneScape Wiki',
	},
	wp = { 
		params = { 'wp' },
		interwiki = 'wikipedia',
		wikiname = 'Wikipedia',
	},
	dw = {
		params = { 'dw' },
		interwiki = 'rsdww',
		wikiname = 'The RuneScape: Dragonwilds Wiki',
	},
}

local order = { 'os', 'rsc', 'dw', 'meta', 'wp' }

local allparams = {}

function p.main(frame)
	local args = frame:getParent().args
	return p._main(args, frame)
end

function p._main(args, frame)
	local pagename = mw.title.getCurrentTitle().fullText
	local vals = {}

	-- create allparams
	for s,t in pairs(sites) do
		for _,v in ipairs(t.params) do
			allparams[v] = s
		end
	end
	
	-- loop named params
	for i,v in pairs(allparams) do
		if args[i] and not vals[v] then
			vals[v] = args[i]
		end
	end
	
	-- loop unnamed params
	local i = 1
	local v
	while args[i] do
		v = allparams[args[i]] 
		if v and not vals[v] then
			vals[v] = pagename
		end
		i = i + 1
	end

	local ret = mw.html.create('div')
	ret:addClass('noexcerpt noprint nomobile navigation-not-searchable rs-external-header-links'):css('display', 'none')
	for _,v in ipairs(order) do
		if vals[v] then
			local span = ret:tag('span')
			span:wikitext(vals[v])
				:addClass('rs-header-icon rs-header-icon-' .. v)
				:attr({
					['data-wikiname'] = sites[v].wikiname,
					['data-interwiki'] = sites[v].interwiki,
					['data-page'] = vals[v],
				})
		end
	end

	return tostring(ret)
end

return p
--</nowiki>