Aller au contenu

Module:Wikiprojet

Cette page est protégée.
Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 2 décembre 2017 à 08:00 et modifiée en dernier par Od1n (discuter | contributions) (ajout classe permettant de supprimer ce texte d'introduction ma foi vachement utile, hein. (il y a des contributeurs qui aiment bien épurer l'interface, à coups de display:none dans le css perso)). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.

 Documentation[voir] [modifier] [historique] [purger]

Utilisation

Ce module génère le tableau d'évaluation des bandeaux {{Wikiprojet}}. Il est conçu pour éviter l'imbrication de tableaux HTML.

Il fait pour le moment appel aux modèles {{Wikiprojet/alias}}, {{Wikiprojet/image}} et {{Wikiprojet/extra}}. Il serait préférable de transférer le contenu de ces modèles dans un sous-module, mais c'est fastidieux à faire et cela n’apporterait pas grand chose au final, ce module n'étant utilisé qu'une fois par page.

Fonctions exportables

  • projet( frame ) – retourne une introduction avec la liste des projets, et le tableau d'évaluation de l'avancement et l'importance de l'article pour chaque projet.

Voir aussi

-- Ce module implémente [[Modèle:Wikiprojet/Projet]], pour avoir une structure html plus simple.

local p = {}
local Outils = require( 'Module:Outils' )

local dataAvancement = {
	default = {	
		nom = 'inconnu',
		couleur = '#666666; color:#fff; white-space:nowrap;' ,
		texte = 'À évaluer',
	},
	adq = { 
		nom = 'AdQ',
		couleur = '#6699ff' ,
		texte = '[[Fichier:Fairytale bookmark gold.svg|14px|AdQ]] ' .. Outils.abr( 'AdQ', 'Article de qualité' ),
	},
	ba = { 
		nom = 'BA',
		couleur = '#66ff66',  
		texte = '[[Fichier:Fairytale bookmark silverstar.svg|14px|BA]] ' .. Outils.abr( 'BA', 'Bon article' ),
	},
	a = { 
		nom = 'A',
		couleur = '#66ffff',  
		texte = Outils.abr( 'A', 'Article avancé' ),
	},
	b = { 
		nom = 'B',
		couleur = '#ffff66',  
		texte = Outils.abr( 'B', 'Article bien construit' ),
	},
	bd = { 
		nom = 'BD',
		couleur = '#ffaa66',  
		texte = 'Bon\194\160début' ,
	},
	['ébauche'] = { 
		nom = 'ébauche',
		couleur = '#ff6666',  
		texte = 'Ébauche' ,
	},
	homonymie = {
		nom = 'homonymie',
		couleur = '#66ff66',  
		texte = 'Homonymie' ,
	},
}
dataAvancement['bon début'] = dataAvancement.bd
dataAvancement.c = dataAvancement.bd
dataAvancement.d = dataAvancement.bd
dataAvancement.e = dataAvancement['ébauche']

local dataImportance = {
	default = {	
		nom = 'inconnue',
		couleur = '#666666; color:#fff; white-space:nowrap;',
		texte = 'À évaluer',
	},
	maximum = {
		nom = 'maximum',
		couleur = '#ff00ff',  
		texte = "Maximum" ,
	},
	['élevée'] = {
		nom = 'élevée',
		couleur = '#ff88ff',  
		texte = "Élevée" ,
	},
	moyenne = {
		nom = 'moyenne',
		couleur = '#ffccff',  
		texte = "Moyenne" ,
	},
	faible = {
		nom = 'faible',
		couleur = '#ffeeff',  
		texte = "Faible" ,
	},
}

local introduction = '<div class="intro-wikiprojet"><p>Cet article est indexé par %s %s.</p>'
	.. '<p>Les [[Projet:Accueil|projets]] ont pour but d’enrichir le contenu de Wikipédia en aidant à la coordination du travail des contributeurs. '
	.. 'Vous pouvez [%s modifier directement cet article] '
	.. 'ou visiter les pages de projets pour prendre conseil ou consulter la liste des tâches et des objectifs.</p></div>'
local lienProjet = '[[Projet:%s|%s]]'
local liensProjet = '<b>[[Projet:¤|¤]]</b> ([[Discussion Projet:¤|discussion]] '
	.. '•\194\160[[Projet:¤/Évaluation|critères]] '
	.. '•\194\160[[Projet:¤/Évaluation/Index|liste]] '
	.. '•\194\160[[Projet:¤/Évaluation/Statistiques détaillées|stats]] '
	.. '•\194\160[[Projet:¤/Évaluation/Historique|hist.]] '
	.. '•\194\160[[Projet:¤/Évaluation/Comité|comité]])'
local chaineCategorie = "[[Catégorie:Article d\'avancement %s/Liste complète]][[Catégorie:%s d\'avancement %s]][[Catégorie:%s d\'importance %s]]%s"

local function switch( key, table )
	return table[key] or table['default']
end

local function analyseArgs( args )
	local newArgs = {
		[0] = {},  -- pour éviter une erreur sur i-1
		avancement = switch( mw.ustring.lower( args.avancement or '' ), dataAvancement ),
		nocat = Outils.trim( args.nocat ),
	}
	local frame = mw.getCurrentFrame()
	local i = 1
	while Outils.trim( args[i] ) do
		local nomProjet = frame:expandTemplate{ 
			title = 'Wikiprojet/alias', 
			args = { projet = args[i] } 
		}
		local projet = {
			importance = switch( mw.ustring.lower( Outils.trim( args[ i + 1 ] ) or '' ), dataImportance ),
			nom = nomProjet,
			image = frame:expandTemplate{ 
				title = 'Wikiprojet/image', 
				args = { projet = nomProjet } 
			},
			nomCategorie = frame:expandTemplate{ 
				title = 'Wikiprojet/catégorisation', 
				args = { projet = nomProjet } 
			},
			extraCategorie = frame:expandTemplate{ 
				title = 'Wikiprojet/extra', 
				args = { projet = nomProjet } 
			},
		}
		if projet.image == '' then
			local bandeau = require 'Module:Bandeau'
			local icone = bandeau.parametreEbauche( frame:newChild { args = { nomProjet, 'icone' } } )
			projet.image = icone or 'Emojione 2754.svg'
			projet.extraCategorie = projet.extraCategorie .. '[[Catégorie:Page avec image Wikiprojet déduite|' .. nomProjet .. ']]'
		end
		table.insert( newArgs, projet )
		i = i + 2
	end
	return newArgs
end

function p.introduction( args )
	local sp = 'le projet'
	if #args > 1 then 
		sp = 'les projets'
	end
	local listeProjets = {}
	for i = 1, #args do
		local nom = args[i].nom
		table.insert( listeProjets, string.format( lienProjet, nom, nom ) )
	end
	return string.format( introduction, 
		sp, 
		mw.text.listToText( listeProjets ), 
		mw.title.getCurrentTitle():fullUrl( 'action=edit' ) 
	)
end

function p.tableauAvancement( args )
	local pageName = mw.title.getCurrentTitle().text
	local titreAvancement = {
		default = '[[Projet:Évaluation/Avancement|Avancement]]',
		AdQ = '[[Wikipédia:Articles de qualité|Label]]',
		BA = '[[Wikipédia:Bons articles|Label]]',
	}
	local evalTable = mw.html.create( 'table' )
	evalTable
		:cssText( 'background:#ededed; width:100%; margin:0.5em 0; border-spacing:0; padding:0.4em; border:1px solid #a7d7f9; border-radius:10px; 	border-collapse:separate;' )
		:tag( 'caption' )
			:cssText( 'padding-bottom:5px;' )
			:wikitext( '[[Image:Fairytale bookmark half gold silverlight.png|20px|alt=logo évaluation]] <b>[[Projet:Évaluation|Évaluation]]</b> de l’article « <b>' )
			:wikitext( mw.text.nowiki( pageName ) )
			:wikitext( '</b> »' )
			:done()
		:tag( 'tr' )
			:tag( 'th' )
				:attr{ scope = 'col' }
				:cssText( 'width:6em; font-weight:normal;' )
				:wikitext( switch( args.avancement.nom, titreAvancement ) )
				:done()
			:tag( 'th' )
				:attr{ scope = 'col' }
				:cssText( 'width:6em; font-weight:normal;' )
				:wikitext( '[[Projet:Évaluation/Importance|Importance]]' )
				:done()
			:tag( 'th' )
				:attr{ scope = 'col', colspan = 2 }
				:cssText( 'text-align:left; font-weight:normal;' )
				:wikitext( 'pour le [[Projet:Accueil|projet]]' )
		:allDone()
	local ligne = mw.html.create( 'tr' )
			:tag( 'td' )
				:attr( 'rowspan', #args )
				:cssText( 'text-align:center; font-weight:bold; background-color:' .. args.avancement.couleur )
				:wikitext( args.avancement.texte )
			:done()
			
	for numProjet, projet in ipairs( args ) do
		local importance = projet.importance
		if projet.importance ~= args[numProjet-1].importance then
			local span = 1
			while numProjet + span <= #args 
				and args[numProjet + span].importance == projet.importance 
			do
				span = span + 1
			end
			ligne
				:tag( 'td' )
					:attr( 'rowspan', span )
					:cssText( 'text-align:center; font-weight:bold; background-color:' .. projet.importance.couleur )
					:wikitext( projet.importance.texte )
					:done()
		end
		
		local categories = ''
		if not args.nocat then
			categories = string.format( chaineCategorie,
				args.avancement.nom,
				projet.nomCategorie,
				args.avancement.nom,
				projet.nomCategorie,
				projet.importance.nom,
				projet.extraCategorie
			)
		end
		
		ligne
			:tag( 'td' )
				:cssText( 'text-align:center; width:40px' )
				:wikitext( string.format( '[[Image:%s|40x20px|%s]]', projet.image, projet.nom ) )
				:done()
			:tag( 'td' )
				:wikitext( ( string.gsub( liensProjet, '¤', projet.nom ) ) )
				:wikitext( categories )
				:done()
		
		evalTable:node( ligne )
		ligne =  mw.html.create( 'tr' )
	end
	if #args == 0 then
		evalTable:node( ligne )
	end
	return tostring( evalTable )
end


function p.projet( frame )
	local args
	if type( frame.getParent ) == 'function' then
		args = analyseArgs( frame:getParent().args )
	else
		args = analyseArgs( frame.args )	-- pour tester dans la console
	end
	if args[1] then
		return p.introduction(args) .. p.tableauAvancement( args )
	elseif args.avancement then
		return p.tableauAvancement( args )
	end
end

return p