Technopedia Center
PMB University Brochure
Faculty of Engineering and Computer Science
S1 Informatics S1 Information Systems S1 Information Technology S1 Computer Engineering S1 Electrical Engineering S1 Civil Engineering

faculty of Economics and Business
S1 Management S1 Accountancy

Faculty of Letters and Educational Sciences
S1 English literature S1 English language education S1 Mathematics education S1 Sports Education
  • Registerasi
  • Brosur UTI
  • Kip Scholarship Information
  • Performance
  1. Weltenzyklopädie
  2. Module:Lien interwiki
Module:Lien interwiki 👆 Click Here! Read More..
Cette page fait l’objet d’une mesure de semi-protection étendue.
Une page de Wikipédia, l'encyclopédie libre.

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

Ce module est utilisé par le modèle {{Lien}}.

Utilisation

Fonctions exportables :

  • main(frame) – pour le modèle {{Lien}}.

Modules externes et autres éléments dont ce module a besoin pour fonctionner :

  • Module:Langue – chargé pour déterminer le nom de la langue à partir de son code.
  • Module:Lien interwiki/data catégorisation – catégories ajoutées en fonction du code de langue.
    • Projet Scribunto Projet Scribunto

La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.

-- luacheck: globals mw, no max line length

local mwTrim = mw.text.trim

local p = {}

function p.main( frame )

	local function lien( interwiki, target, text )
		if target:sub( 1, 1 ) == ':' then
			target = target:sub( 2 )
		end
		if interwiki then
			target = interwiki .. ':' .. target
		end
		if text then
			return '[[:' .. target .. '|' .. text .. ']]'
		else
			return '[[:' .. target .. ']]'
		end
	end

	local function indicateurAvecLien( lang, cible_trad )

		local function makeSpan( libelle )
			local title = 'Article ' .. libelle .. '\194\160: «\194\160' .. cible_trad .. '\194\160»'

			return '<span class="indicateur-langue" title="' .. title:gsub( '"', '&quot;' ) .. '">(' .. lang .. ')</span>'
		end

		if lang == 'wikidata' or lang == 'd' then
			return lien( lang, cible_trad, makeSpan( 'sur Wikidata' ) )
		else
			-- noms pour les langues les plus utilisées, afin d'économiser l'appel au Module:Langue
			local langs = {
				de = 'allemand',
				en = 'anglais',
				es = 'espagnol',
				it = 'italien',
				ja = 'japonais',
				pl = 'polonais',
				pt = 'portugais',
				ru = 'russe',
				zh = 'chinois',
			}

			local nomLangue = langs[ lang ]
			if not nomLangue then
				nomLangue = require( 'Module:Langue' ).nomLangue( mw.ustring.lower( lang ) )
				if nomLangue:find( 'class="error"', nil, true ) then
					nomLangue = nil
				end
			end

			if nomLangue then
				return lien( lang, cible_trad, makeSpan( 'en ' .. nomLangue ) )
			else
				return lien( lang, cible_trad, makeSpan( 'dans une autre langue' ) )
					.. '<span class="error">Erreur : langue non reconnue par le modèle Lien : « ' .. lang .. ' ».</span>'
					.. '[[Catégorie:Article contenant un appel à traduction avec un code langue inconnu|+]]'
			end
		end
	end

	local validArgs = {
		fr     = true,
		[1]    = true,
		lang   = true,
		langue = true,
		trad   = true,
		texte  = true,
		lienfr = true,
		nocat  = true,
	}

	local parentArgs = frame:getParent().args
	local hasInvalidArgs = false
	local args = {}

	for k, v in pairs( parentArgs ) do
		-- détecte la présence de paramètres non reconnus
		if not validArgs[ k ] then
			hasInvalidArgs = true
		end

		-- effectue un trim sur les paramètres non nommés,
		-- et exclut les paramètres dont la valeur est vide
		if type( k ) == 'number' then
			v = mwTrim( v )
		end
		if v ~= '' then
			args[ k ] = v
		end
	end

	local cible_fr = args[ 'fr' ] or args[ 1 ] or args[ 'trad' ]
	local cible_trad = args[ 'trad' ] or args[ 'fr' ] or args[ 1 ]
	local lang = args[ 'langue' ] or args[ 'lang' ] or 'en'
	local nolinkfr = args['lienfr'] == 'non' or args['lienfr'] == 'no'

	local categorise = ( args[ 'nocat' ] ~= 'oui' )

	if not cible_fr then
		return frame:expandTemplate{ title = 'Fix', args = {
			[1]              = '&lsqb;&lsqb;' .. ( args[ 'texte' ] and '&verbar;' .. args[ 'texte' ] or '' ) .. '&rsqb;&rsqb;',
			['message']      = 'modèle à corriger',
			['message_lien'] = 'Catégorie:Page contenant un appel à traduction d\'un article non spécifié',
			['infobulle']    = 'Cet appel à traduction est à corriger car aucun titre de page n\'est spécifié.',
			['catégorie']    = ( categorise and 'Page contenant un appel à traduction d\'un article non spécifié' or nil )
		} }
	end

	local result

	if nolinkfr then
		result = ( args[ 'texte' ] or cible_fr ) .. '\194\160' .. indicateurAvecLien( lang, cible_trad )
	else
		result = lien( nil, cible_fr, args[ 'texte' ] )

		local pageExiste
		local objetPage = mw.title.new( cible_fr )
		if objetPage then
			-- pcall permettant de masquer les erreurs « too many expensive function calls »
			local success = pcall( function ()
				pageExiste = objetPage.exists
			end )
			if not success then
				pageExiste = false
			end
		else
			pageExiste = false -- titre de page invalide
		end

		if pageExiste then
			result = '<span class="ExistingLink">' .. result .. '</span>'
			if categorise then
				result = result .. p._temoin()
			end
		else
			result = result .. '\194\160' .. indicateurAvecLien( lang, cible_trad )

			if categorise then
				result = result .. p._categorisation( lang )
			end
		end
	end

	if hasInvalidArgs then
		local ns = mw.title.getCurrentTitle().namespace
		-- Utilisateur, Discussion utilisateur
		if ns == 2 or ns == 3 then
			result = result .. '[[Catégorie:Page utilisateur contenant un modèle Lien avec un paramètre inconnu]]'
		else
			result = result .. '[[Catégorie:Page contenant un modèle Lien avec un paramètre inconnu]]'
		end
	end

	return result
end

function p._temoin()
	local categorie

	local ns = mw.title.getCurrentTitle().namespace
	-- (principal), Portail, Référence
	if ns == 0 or ns == 100 or ns == 104 then
		categorie = '[[Catégorie:Page utilisant Lien pour un article existant]]'
	-- Modèle
	elseif ns == 10 then
		categorie = '[[Catégorie:Page utilisant Lien pour un article existant|*]]'
	-- Discussion, Wikipédia, Projet
	elseif ns == 1 or ns == 4 or ns == 102 then
		categorie = '[[Catégorie:Page de discussion utilisant Lien pour un article existant]]'
	else
		categorie = ''
	end

	return categorie
end

function p._categorisation( lang )
	local ns = mw.title.getCurrentTitle().namespace
	-- (principal), Modèle
	if ns == 0 or ns == 10 then
		local data = mw.loadData( 'Module:Lien interwiki/data catégorisation' )
		return ( data[ lang ] or '[[Catégorie:Article contenant un appel à traduction avec un code langue inconnu|' .. lang .. ']]' )
	else
		return ''
	end
end

return p
Ce document provient de « https://fr.wikipedia.org/w/index.php?title=Module:Lien_interwiki&oldid=228289076 ».
Catégorie :
  • Module en langage Lua
Catégorie cachée :
  • Module en semi-protection étendue

  • indonesia
  • Polski
  • الرية
  • Deutsch
  • English
  • Español
  • Français
  • Italiano
  • مصر
  • Nederlands
  • 本語
  • Português
  • Sinugboanong Binisaya
  • Svenska
  • Українска
  • Tiếng Việt
  • Winaray
  • 中文
  • Русски
Sunting pranala
Pusat Layanan

UNIVERSITAS TEKNOKRAT INDONESIA | ASEAN's Best Private University
Jl. ZA. Pagar Alam No.9 -11, Labuhan Ratu, Kec. Kedaton, Kota Bandar Lampung, Lampung 35132
Phone: (0721) 702022
Email: pmb@teknokrat.ac.id