Module:Top icons: Difference between revisions

From 2006Scape Wiki
Jump to navigation Jump to search
scape_>Gaz Lloyd
No edit summary
m (20 revisions imported)
 
(11 intermediate revisions by 8 users not shown)
Line 3: Line 3:
local sites = {
local sites = {
rsc = {
rsc = {
-- @TODO: update with new url post forking RSC
format = 'The RuneScape Classic Wiki also has an article on: [[classicrsw:%s]]',
format = '[[rsw:%s]]',
params = { 'rsc' },
params = { 'rsc', 'classic', 'c' },
abbr = 'CS',
abbr = 'CS',
title = 'The RuneScape Classic Wiki also has an article on %s.',
title = 'The RuneScape Classic Wiki also has an article on %s.',
},
},
rs = {
rs = {
format = '[[rsw:%s]]',
format = 'The RuneScape Wiki also has an article on: [[rsw:%s]]',
params = { 'runescape', 'rs', 'rsw', 'rs3' },
params = { 'rs' },
abbr = 'RuneScape',
abbr = 'RuneScape',
title = 'The RuneScape Wiki also has an article on %s.',
title = 'The RuneScape Wiki also has an article on %s.',
},
},
wp = {  
wp = {  
format = '[[wikipedia:%s]]',
format = 'Wikipedia also has an article on: [[wikipedia:%s]]',
params = { 'wikipedia', 'wp', 'w' },
params = { 'wp' },
abbr = 'Wikipedia',
abbr = 'Wikipedia',
title = 'Wikipedia also has an article on %s.',
title = 'Wikipedia also has an article on %s.',
},
meta = {
format = '[[meta:%s]]',
params = { 'meta' },
abbr = 'Weird Gloop',
title = 'The Weird Gloop meta wiki also has an article on %s.',
},
},
}
}


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


local allparams = {}
local allparams = {}
Line 29: Line 34:
function p.main(frame)
function p.main(frame)
local args = frame:getParent().args
local args = frame:getParent().args
return p._main(args)
end
function p._main(args)
local pagename = mw.title.getCurrentTitle().fullText
local pagename = mw.title.getCurrentTitle().fullText
local vals = {}
local vals = {}
Line 57: Line 66:
local ret = mw.html.create('div')
local ret = mw.html.create('div')
ret:addClass('rs-external-header-links'):css('display', 'none')
ret:addClass('noexcerpt noprint nomobile navigation-not-searchable rs-external-header-links'):css('display', 'none')
for _,v in ipairs(order) do
for _,v in ipairs(order) do
if vals[v] then
if vals[v] then
Line 71: Line 80:
end
end


return tostring(ret)
return tostring(ret)
end
end


return p
return p

Latest revision as of 00:55, 10 February 2023

Documentation for this module may be created at Module:Top icons/doc

local p = {}

local sites = {
	rsc = {
		format = 'The RuneScape Classic Wiki also has an article on: [[classicrsw:%s]]',
		params = { 'rsc' },
		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 = { 'rs' },
		abbr = 'RuneScape',
		title = 'The RuneScape Wiki also has an article on %s.',
		},
	wp = { 
		format = 'Wikipedia also has an article on: [[wikipedia:%s]]',
		params = { 'wp' },
		abbr = 'Wikipedia',
		title = 'Wikipedia also has an article on %s.',
		},
	meta = {
		format = '[[meta:%s]]',
		params = { 'meta' },
		abbr = 'Weird Gloop',
		title = 'The Weird Gloop meta wiki also has an article on %s.',
		},
	}

local order = { 'rs', 'rsc', 'wp', 'meta' }

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