Modul:Wikiprojek

Daripada Wikipedia, ensiklopedia bebas.

Pendokumenan untuk modul ini boleh diciptakan di Modul:Wikiprojek/doc

-- Modul ini masih lagi dalam pembangunan. Harap ia tidak dibuang.
-- Ce module implémente [[Modèle:Wikiprojet/Projet]], pour avoir une structure html plus simple.

local p = {}

local dataAvancement = {
	default = {
		nom = 'tidak diketahui',
		couleur = '#F5F5F5; white-space:nowrap;',
		texte = 'Belum dinilai',
	},
	rp = {
		nom = 'RP',
		couleur = '#6699ff',
		texte = '[[Fail:Bulan_bintang.svg|15px|Rencana pilihan]] <abbr class="abbr" title="Rencana pilihan">RP</abbr>',
	},
	rb = {
		nom = 'RB',
		couleur = '#F0FFEA',
		texte = '[[Fail:Rekommenderad grön.svg|14px|RB]] <abbr class="abbr" title="Rencana baik">RB</abbr>',
	},
	sp = {
		nom = 'SP',
		couleur = '#66ff66',
		texte = '[[Fail:Cscr-featured.svg|14px|RB]] <abbr class="abbr" title="Senarai pilihan">SP</abbr>',
	},
	a = {
		nom = 'A',
		couleur = '#66FFFF',
		texte = '<abbr class="abbr" title="Rencana kelas A">A</abbr>',
	},
	b = {
		nom = 'B',
		couleur = '#B2FF66',
		texte = '<abbr class="abbr" title="Rencana kelas B">B</abbr>',
	},
	c = {
		nom = 'C',
		couleur = '#FFFF66',
		texte = '<abbr class="abbr" title="Rencana kelas C">C</abbr>',
	},
	mula = {
		nom = 'Mula',
		couleur = '#ffaa66',
		texte = '<abbr class="abbr" title="Rencana kelas mula">Mula</abbr>',
	},
	['tunas'] = {
		nom = 'Tunas',
		couleur = '#FF6666',
		texte = '<abbr class="abbr" title="Rencana kelas tunas">Mula</abbr>',
	},
}
--dataAvancement['mula'] = dataAvancement.bd
--dataAvancement.c = dataAvancement.bd
--dataAvancement.d = dataAvancement.bd
--dataAvancement.e = dataAvancement['tunas']

local dataImportance = {
	default = {
		nom = 'tidak diketahui',
		couleur = '#F5F5F5; white-space:nowrap;',
		texte = 'Belum dinilai',
	},
	tertinggi = {
		nom = 'tertinggi',
		couleur = '#ff00ff',
		texte = "Tertinggi",
	},
	tinggi = {
		nom = 'tinggi',
		couleur = '#ff88ff',
		texte = "Tinggi",
	},
	sederhana = {
		nom = 'sederhana',
		couleur = '#ffccff',
		texte = "Sederhana",
	},
	rendah = {
		nom = 'rendah',
		couleur = '#ffeeff',
		texte = "Rendah",
	},
}

local introduction = '<div class="intro-wikiprojet" style="margin-bottom:1em"><p>Halaman ini merupakan sebahagian daripada %s %s.</p>'
	.. '<p>[[Wikipedia:WikiProjek|WikiProjek]] ialah adalah sebuah projek usaha sama antara pengguna bagi memperbaiki dan meningkatkan mutu rencana yang berkaitan di Wikipedia. '
	.. 'Anda boleh [%s menyunting halaman ini] '
	.. 'atau lawati halaman projek jika anda ingin menyertainya. '
	.. 'Anda juga boleh ke halaman perbincangan jika anda mempunyai sebarang pertanyaan atau pendapat.</p></div>'
local lienProjet = '[[Wikipedia:WikiProjek %s|%s]]'
local liensProjet = '<b>[[Wikipedia:WikiProjek ¤|¤]]</b> ([[Perbincangan Wikipedia:WikiProjek ¤|perbincangan]]'
	.. '\194\160• [[Wikipedia:WikiProjek ¤/Penilaian|kriteria]])'
--local chaineCategorie = ""

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 = 'WikiProjek/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 = 'WikiProjek/imej',
				args = { projet = nomProjet }
			},
			nomCategorie = frame:expandTemplate{
				title = 'WikiProjek/pengkategorian',
				args = { projet = nomProjet }
			},
			extraCategorie = frame:expandTemplate{
				title = 'WikiProjek/ekstra',
				args = { projet = nomProjet }
			},
		}
		--if projet.image == '' then
		--	local bandeau = require 'Module:InfoboxImage'
		--	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 = 'projek'
	
	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 = 'Kelas',
		RP = '[[Wikipedia:Rencana pilihan|Kelas]]',
		RA = '[[Wikipedia:Rencana baik|Kelas]]',
		SP = '[[Wikipedia:Senarai pilihan|Kelas]]'
	}
	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 #c0c090; border-radius:5px; border-collapse:separate;' )
		:tag( 'caption' )
			:cssText( 'padding-bottom:5px;' )
			:wikitext( '[[Fail:Star half by Amirreza.png|20px|alt=Logo penilaian]] <b>[[Wikipedia:WikiProjek/Penilaian|Penilaian]]</b> halaman: <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( 'Kepentingan' )
				:done()
			:tag( 'th' )
				:attr{ scope = 'col', colspan = 2 }
				:cssText( 'text-align:left; font-weight:normal;' )
				:wikitext( 'untuk [[Wikipedia:WikiProjek|WikiProjek]]' )
		: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( '[[Fail:%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