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 11 avril 2018 à 12:56 et modifiée en dernier par Od1n (discuter | contributions) (alternative, preuve en est plus simple ainsi : comme pour les catégories, intégration dans la boucle existante pour le tableau (et même carrément intégration dans le markup du tableau, mais bon ça fonctionne)). 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 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]] <abbr class="abbr" title="Article de qualité">AdQ</abbr>',
	},
	ba = {
		nom = 'BA',
		couleur = '#66ff66',
		texte = '[[Fichier:Fairytale bookmark silverstar.svg|14px|BA]] <abbr class="abbr" title="Bon article">BA</abbr>',
	},
	a = {
		nom = 'A',
		couleur = '#66ffff',
		texte = '<abbr class="abbr" title="Article avancé">A</abbr>',
	},
	b = {
		nom = 'B',
		couleur = '#ffff66',
		texte = '<abbr class="abbr" title="Article bien construit">B</abbr>',
	},
	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" style="margin-bottom:1em"><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 = ( args.nocat and args.nocat ~= '' ),
	}
	local frame = mw.getCurrentFrame()
	local i = 1
	while args[i] and mw.text.trim( args[i] ) ~= '' do
		local nomProjet = frame:expandTemplate{
			title = 'Wikiprojet/alias',
			args = { projet = args[i] }
		}
		local projet = {
			importance = switch( mw.ustring.lower( mw.text.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
		-- le "border-collapse:separate" est pour la version mobile
		:cssText( 'background:#ededed; width:100%; border-spacing:0; padding:0.4em 0.6em calc(0.4em + 2px); 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
		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 avancementCommun = args.avancement.nom

		local categories = ''
		if not args.nocat then
			categories = string.format( chaineCategorie,
				avancementCommun,
				projet.nomCategorie,
				avancementCommun,
				projet.nomCategorie,
				projet.importance.nom,
				projet.extraCategorie
			)
		end

		-- https://www.mediawiki.org/wiki/Extension:PageAssessments
		-- disabled for now: https://phabricator.wikimedia.org/T153393
		--local assessment = frame:callParserFunction( '#tag:assessment', { projet.nom, avancementCommun, projet.importance.nom } )

		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 )
				--:wikitext( assessment )
				: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