Module:WikidataPopulation

Une page de Wikipédia, l'encyclopédie libre.

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

Utilisation[modifier le code]

Fonctions exportables :

  • nombro() – Récupère le nombre d'habitants ('p1082') de l'article en cours.
  • nombroQ() – Récupère le nombre d'habitants ('p1082') de l'article ('qxxx') de l'article indiqué en paramètre.
  • dato() – Récupère la date ('p585') pour le nombre d'habitants (ne fonctionne pas, une aide serait souhaitée) .

Autres fonctions :

  • fonction() – description2 (courte description de fonction() et autres informations pertinentes).

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

  • mw.title – description (courte description expliquant la dépendance de ce module externe).

Exemples[modifier le code]

Pour des exemples, voir la page de test permettant de tester diverses modifications apportées.

local p = {}


function p.nombro()
	local entity = mw.wikibase.getEntity()
	if not entity then
		return "ne estas ligo"
	end
	local pop = entity:getBestStatements( 'P1082' )
	if (#pop == 0) or (pop[1].mainsnak.snaktype ~= "value") then
		return nil
	end
	local x = pop[1].mainsnak.datavalue.value.amount
	local i=string.find(x,"±")
	if i==nil then i=string.len(x)+1 end
	x=string.sub(x,1,i-1)
	x=string.gsub( x," ", "" )
	x=string.gsub( x,"+", "" )
	return x
end

function p.nombroQ(frame)
	local entity = mw.wikibase.getEntity(frame.args[1])
	if not entity then
		return nil
	end
	local pop = entity:getBestStatements( 'P1082' )
	if (#pop == 0) or (pop[1].mainsnak.snaktype ~= "value") then
		return nil
	end
	local x = pop[1].mainsnak.datavalue.value.amount
	local i=string.find(x,"±")
	if i==nil then i=string.len(x)+1 end
	x=string.sub(x,1,i-1)
	x=string.gsub( x," ", "" )
	x=string.gsub( x,"+", "" )
	return x
end

function p.dato() -- lit la date
	local entity = mw.wikibase.getEntityObject()
	if not entity then
		return nil
	end
    	local pop = entity:getBestStatements( 'P1082' )
	if (#pop == 0) or (pop[1].mainsnak.snaktype ~= "value") then
		return nil
	end
	v = pop[1].qualifiers["P585"]
        v = v[1].datavalue.value.time 
  return v
end

return p