Module:Interprojet

La bibliothèque libre.

La documentation pour ce module peut être créée à Module:Interprojet/Documentation

local p = {}

local sites = { -- préfixe interwiki, liste des paramètres, label et id du site
	{ 'w', { 'Wikipedia', 'w', 'wAutore' }, 'Wikipédia', 'wikipedia' },
	{ 'q', { 'Wikiquote', 'q' }, 'Wikiquote', 'wikiquote' },
	{ 'b', { 'Wikibooks', 'b' }, 'Wikibooks', 'wikibooks' },
	{ 'commons', { 'commons', 'Commons', 'CommonsAutore' }, 'Commons', 'commons' },
	{ 'd', { 'Wikidata', 'd' }, 'Wikidata', 'wikidata' },
	{ 'wikispecies', { 'wikispecies', 'WikiSpecies' }, 'Wikispecies', 'wikispecies' },
	{ 'n', { 'WikiNews', 'n' }, 'Wikinews', 'wikinews' },
	{ 'v', { 'Wikiversity', 'v' }, 'Wikiversité', 'wikiversity' },
	{ 'm', { 'm', 'meta' }, 'Meta', 'metawiki' },
	{ 'wikt', { 'WikTionary', 'wikt' }, 'Wiktionnaire', 'wiktionary' },
	{ 'voy', { 'Wikivoyage', 'voy' }, 'Wikivoyage', 'wikivoyage' }
}

function p.interprojet( frame )
	local frame = frame:getParent()

	local content = mw.html.create( 'div' )
		:attr( 'id', 'interProject' )
		:addClass( 'ws-noexport' )
		:css( 'display', 'none' )
		:css( 'speak', 'none' );

	for _, site in pairs( sites ) do
		local val = ''
		for _, param in pairs( site[2] ) do
			if val == '' and frame.args[param] ~= nil then
				val = frame.args[param]
			end
		end

		if val ~= '' then
			local node = content:tag( 'span' )
			node:attr( 'id', 'interprojet-' .. site[4] )
			node:wikitext( '[[' .. site[1] .. ':' .. val .. '|' .. site[3] .. ']]' )
			node:done()
		end
	end

	return content:done()
end

return p