Module:Icon/table

From imedwiki
Jump to navigation Jump to search

This module creates a test case template using data aggregated from Module:Icon/data and Module:Icon/data/sandbox. It is intended to be displayed at Template:Icon/testcases.

Usage

{{#invoke:icon/table|main}}

Output

Icon Description Code Aliases
A-Class article A-Class article a}}
Audited article of limited subject matter Audited article of limited subject matter aa}}
A-Class article candidate A-Class article candidate acc}} aac, acn
B-Class article B-Class article b}}
Wikipedia book Wikipedia book book}}
Bplus-Class article Bplus-Class article bplus}} b+
B-Class review B-Class review br}} bcr
C-Class article C-Class article c}}
Category Category category}} cat, categ
Commons page Commons page commons}}
Demoted article Demoted article da}}
Demoted A-Class article Demoted A-Class article dac}} daa
Delisted good article Delisted good article dga}}
Disambiguation page Disambiguation page disambiguation}} dab, disamb, disambig
Did You Know? Did You Know? dyk}}
Did You Know? Did You Know? dyk2}}
Essay Essay essay}}
Featured article Featured article fa}}
Featured article candidate Featured article candidate fac}} fan
Featured article review Featured article review far}}
Featured article removal candidate Featured article removal candidate farc}}
Former featured article Former featured article ffa}} dfa
Failed featured article candidate Failed featured article candidate ffac}} nofa
Former featured list Former featured list ffl}} dfl
Failed featured list candidate Failed featured list candidate fflc}} nofl
Former featured picture Former featured picture ffp}}
Former featured portal Former featured portal ffpo}}
Former featured sound Former featured sound ffs}}
Former featured topic Former featured topic fft}} dft
Failed good article nominee Failed good article nominee fgan}} gaf, gf, noga
Featured list Featured list fl}}
Featured list candidate Featured list candidate flc}} fln
Featured list removal candidate Featured list removal candidate flrc}} flr
Four Award Four Award four}}
Featured picture Featured picture fp}}
Featured picture candidate Featured picture candidate fpc}} fpn
Before the featured portal process ceased in 2017, this had been designated as a featured portal. Before the featured portal process ceased in 2017, this had been designated as a featured portal. fpo}}
Featured portal candidate Featured portal candidate fpoc}}
Featured portal review Featured portal review fpor}}
Featured sound Featured sound fs}}
Featured sound candidate Featured sound candidate fsc}}
Featured topic Featured topic ft}}
Featured topic candidate Featured topic candidate ftc}} ftn
Featured topic removal candidate Featured topic removal candidate ftrc}}
Good article Good article ga}}
Good article, 2nd opinion Good article, 2nd opinion ga2}}
Good article on hold Good article on hold gah}}
Good article nominee Good article nominee gan}} gac
Good article reassessment Good article reassessment gar}}
Guild of Copy Editors Guild of Copy Editors goce}}
Good topic Good topic gt}}
Good topic candidate Good topic candidate gtc}} gtn
Good topic removal candidate Good topic removal candidate gtrc}}
File File image}} file
In The News In The News itn}}
List-Class article List-Class article list}} comparison
Meta-wiki page Meta-wiki page meta}}
Million Award Million Award million}}
Module Module module}}
Non-article page Non-article page na}}
Needed article Needed article needed}}
Unknown-Class article Unknown-Class article no}}
Failed A-Class article candidate Failed A-Class article candidate noac}} faac
On This Day On This Day otd}}
Outline Outline outline}}
Portal Portal portal}}
Portal peer review Portal peer review ppr}}
Peer review Peer review pr}}
Project page Project page project}}
Question Question q}} question
Quality image on Wikimedia Commons Quality image on Wikimedia Commons qi}}
Redirect Redirect redirect}} red, redir
Start-Class article Start-Class article start}}
Stub-Class article Stub-Class article stub}}
Template Template template}} temp, templ
Today's Featured Article Today's Featured Article tfa}}
Today's Featured List Today's Featured List tfl}}
Valued image on Wikimedia Commons Valued image on Wikimedia Commons vi}}
Vital article Vital article vital}}
Valued picture Valued picture vp}}
Valued picture candidate Valued picture candidate vpc}}
Wikibooks page Wikibooks page wikibooks}}
Wikidata page Wikidata page wikidata}}
Wikinews page Wikinews page wikinews}}
Wikipedia page Wikipedia page wikipedia}}
WikiProject WikiProject wikiproject}}
Wikiquote page Wikiquote page wikiquote}}
Wikisource page Wikisource page wikisource}}
Wikispecies page Wikispecies page wikispecies}}
Wikiversity page Wikiversity page wikiversity}}
Wikivoyage page Wikivoyage page wikivoyage}}
Wiktionary page Wiktionary page wiktionary}}


This module (and the documentation) are based (partially) on Module:Icon/table from the free encyclopedia wikipedia and is licensed under GNU license for free documentation and the Creative Commons Attribution/Share Alike. On wikipedia there is a List of authors accessible. More about importing from wikipedia on page Imedwiki:Importing from wikipedia.

-- Create a table of icons to display on the template test case page

require("Module:No globals")

local p = {}
local m_iconData = mw.loadData("Module:Icon/data")
local m_iconSandboxData = mw.loadData("Module:Icon/data/sandbox")

local function mergeTables(...)
	local ret = {}
	for _, t in ipairs{...} do
		for k, v in pairs(t) do
			ret[k] = v
		end
	end
	return ret
end

local function reconstituteAliases(iconDataCollection)
	local ret = {}
	for code, iconData in pairs(iconDataCollection) do
		local outputData = ret[iconData.canonicalCode] or {
			aliases = {},
			image = iconData.image,
			tooltip = iconData.tooltip,
			link = iconData.link,
		}
		if code ~= iconData.canonicalCode then
			table.insert(outputData.aliases, code)
		end
		ret[iconData.canonicalCode] = outputData
	end
	return ret
end

local function makeTableData(iconDataCollection)
	local ret = {}
	for code, iconData in pairs(reconstituteAliases(iconDataCollection)) do
		if code ~= '_DEFAULT' then
			table.insert(ret, {code = code, description = iconData.tooltip, aliases = iconData.aliases})
		end
	end
	table.sort(
		ret,
		function(t1, t2)
			return t1.code < t2.code
		end
	)
	for _, t in ipairs(ret) do
		table.sort(t.aliases)
	end
	return ret
end

function p.testcases(frame)
	local tableData = makeTableData(mergeTables(m_iconData, m_iconSandboxData))
	local ret = {
		'{| class="wikitable sortable"',
		'! Code',
		'! [[Template:Icon|Template]]',
		'! [[Template:Icon/sandbox|Sandbox]]',
		'! Description',
	}
	
	local function addRow(code, description)
		table.insert(ret, '|-')
		table.insert(ret, '| <code>' .. mw.text.nowiki('{{icon|' .. code .. '}}') .. '</code>')
		table.insert(ret, '| style="text-align: center" | ' .. frame:expandTemplate{title = 'icon', args = {code}})
		table.insert(ret, '| style="text-align: center" | ' .. frame:expandTemplate{title = 'icon/sandbox', args = {code}})
		table.insert(ret, '| ' .. description)
	end
	
	for _, rowData in ipairs(tableData) do
		addRow(rowData.code, rowData.description)
		for _, alias in ipairs(rowData.aliases) do
			addRow(alias, rowData.description)
		end
	end
	table.insert(ret, '|}')
	return table.concat(ret, '\n')
end

function p.main(frame)
	local tableData = makeTableData(m_iconData)
	local ret = {
		'{| class="wikitable sortable"',
		'! Icon',
		'! Description',
		'! Code',
		'! Aliases'
	}
	for _, rowData in ipairs(tableData) do
		table.insert(ret, '|-')
		table.insert(ret, '| style="text-align: center" | ' .. frame:expandTemplate{title = 'icon', args = {rowData.code}})
		table.insert(ret, '| ' .. rowData.description)
		table.insert(ret, '| <code>' .. mw.text.nowiki('{{icon|' .. rowData.code .. '}}') .. '</code>')
		local aliasText = {}
		for _, alias in ipairs(rowData.aliases) do
			table.insert(aliasText, '<code>' .. alias .. '</code>')
		end
		table.insert(ret, '| ' .. table.concat(aliasText, ', '))
	end
	table.insert(ret, '|}')
	return table.concat(ret, '\n')
end

return p