Module:Top icons: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
|  (Created page with "local p = {}  local sites = { 	rsc = { 		format = 'The RuneScape Classic Wiki also has an article on: classicrsw:%s', 		params = { 'rsc', 'classic', 'c' }, 		abbr = 'CS', 		title = 'The RuneScape Classic Wiki also has an article on %s.', 		}, 	rs = { 		format = 'The RuneScape Wiki also has an article on: rsw:%s', 		params = { 'runescape', 'rs', 'rsw', 'rs3' }, 		abbr = 'RuneScape', 		title = 'The RuneScape Wiki also has an article on %s.', 		}, 	wp = {  		format...") | No edit summary | ||
| Line 3: | Line 3: | ||
| local sites = { | local sites = { | ||
| 	rsc = { | 	rsc = { | ||
| 		format = 'The  | 		format = 'The Near-Reality Wiki also has an article on: [[classicrsw:%s]]', | ||
| 		params = { 'rsc', 'classic', 'c' }, | 		params = { 'rsc', 'classic', 'c' }, | ||
| 		abbr = 'CS', | 		abbr = 'CS', | ||
| 		title = 'The  | 		title = 'The Near-Reality Wiki also has an article on %s.', | ||
| 		}, | 		}, | ||
| 	rs = { | 	rs = { | ||
| 		format = 'The  | 		format = 'The Near-Reality Wiki also has an article on: [[rsw:%s]]', | ||
| 		params = { 'runescape', 'rs', 'rsw', 'rs3' }, | 		params = { 'runescape', 'rs', 'rsw', 'rs3' }, | ||
| 		abbr = 'RuneScape', | 		abbr = 'RuneScape', | ||
| 		title = 'The  | 		title = 'The Near-Reality Wiki also has an article on %s.', | ||
| 		}, | 		}, | ||
| 	wp = {   | 	wp = {   | ||
Latest revision as of 20:21, 4 October 2022
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.
This module is used in Template:External to generate the top icons. It can also be called from other modules using its helper function.
This module is a helper module to be used by other modules; it may not be designed to be invoked directly. See Near-Reality:Lua/Helper modules for a full list and more information.
| Module | Function | Type | Use | 
|---|---|---|---|
| Top icons | _main(args) | String | Returns a string that adds top icons to the page. argsmust be a table of arguments. Numbered arguments must have values ofrs,rsc,metaorwp. To provide a specific pagename on the top icon link, specify named arguments with those same indices, with the value being the external pagename. | 
local p = {}
local sites = {
	rsc = {
		format = 'The Near-Reality Wiki also has an article on: [[classicrsw:%s]]',
		params = { 'rsc', 'classic', 'c' },
		abbr = 'CS',
		title = 'The Near-Reality Wiki also has an article on %s.',
		},
	rs = {
		format = 'The Near-Reality Wiki also has an article on: [[rsw:%s]]',
		params = { 'runescape', 'rs', 'rsw', 'rs3' },
		abbr = 'RuneScape',
		title = 'The Near-Reality Wiki also has an article on %s.',
		},
	wp = { 
		format = 'Wikipedia also has an article on: [[wikipedia:%s]]',
		params = { 'wikipedia', 'wp', 'w' },
		abbr = 'Wikipedia',
		title = 'Wikipedia also has an article on %s.',
		},
	wg = {
		format = '[[meta:%s]]',
		params = { 'meta', 'wg' },
		abbr = 'Weird Gloop',
		title = 'The Weird Gloop meta wiki also has an article on %s.',
		},
	}
local order = { 'rs', 'rsc', 'wp', 'wg' }
local allparams = {}
function p.main(frame)
	local args = frame:getParent().args
	return p._main(args)
end
function p._main(args)
	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(string.format(sites[v].format, vals[v]))
				:addClass('rs-header-icon rs-header-icon-'..v)
				:attr({
						['data-title'] = string.format(sites[v].title, vals[v]),
						['data-site'] = v,
						['data-text'] = sites[v].abbr,
					})
		end
	end
	return tostring(ret)
end
return p