Module:Wikis

From Support Wiki
Jump to navigation Jump to search

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

local p = {}
local wikis = mw.loadJsonData('Module:Wikis/list.json')
local translations = {
	de = 'German',
	en = 'English',
	es = 'Spanish',
	fr = 'French',
	hu = 'Hungarian',
	it = 'Italian',
	ja = 'Japanese',
	ko = 'Korean',
	pl = 'Polish',
	pt = 'Portuguese',
	['pt-br'] = 'Brazilian Portuguese',
	ru = 'Russian',
	th = 'Thai',
	tr = 'Turkish',
	uk = 'Ukrainian',
	zh = 'Chinese'
}

p.count = function()
	local list = {}
	local total = 0
	local wikitable = {
		'{| class="wikitable sortable"',
		'! Language !! Count'
	}
	for _, v in pairs(wikis) do -- index, table
		for _, b in pairs(v.lang) do -- index, lang code
			if not list[b] then
				list[b] = 0
			end
			list[b] = list[b] + 1
			total = total + 1
		end
	end
	for k, v in next, list do -- index, table
		wikitable[#wikitable + 1] = '|-\n| ' .. mw.language.fetchLanguageName(k, 'en') .. ' || ' .. v
	end
	wikitable[#wikitable + 1] = '|- class="sortbottom"\n!Total\n|' .. total
	wikitable[#wikitable + 1] = '|}'
	return table.concat(wikitable, '\n')
end

p.forks = function()
	local list = {
		fandom = 0,
		gamepedia = 0,
		miraheze = 0,
		unknown = 0,
		selfhosted = 0,
		wikitide = 0,
		wikidot = 0,
		new = 0
	}
	local wikitable = {
		'{| class="wikitable sortable"',
		'! Moved from !! Count'
	}
	for _, v in pairs(wikis) do -- index, table
		local orig = list[v.origin] and v.origin or 'unknown'
		list[orig] = list[orig] + 1
	end
	for k, v in next, list do -- index, table
		wikitable[#wikitable + 1] = '|-\n| ' .. k .. ' || ' .. v
	end
	wikitable[#wikitable + 1] = '|}'
	return table.concat(wikitable, '\n')
end

return p