Module:Interface Wikidata : Différence entre versions

De WikiField
Sauter à la navigation Sauter à la recherche
fr>Zebulon84
(+ p.addLinkBack( frame ) pour pouvoir ajouté un linkBack en dehors du modèle Wikidata lorsque le résultat de ce dernier est utilisé dans un autre modèle ne supportant pas le linback)
(Aucune différence)

Version du 20 septembre 2017 à 08:37

La documentation pour ce module peut être créée à Module:Interface Wikidata/doc

local p = {}
local d = require 'Module:Wikidata'

-- fonctions ne pouvant être appelées que depuis un autre module
p.fromLua = {
	
	-- manipulation d'une liste d'affirmations
	getClaims = d.getClaims,
	stringTable = d.stringTable,
	tableToText = d.tableToText,
	formatStatements = d.formatStatements,
	formatQualifiers = d.showQualifier,
	formatAndCat = d.formatAndCat,
	wikidataDate = d.wikidataDate,
	addLinkback = d.addLinkBack,
	addtrackingcat = d.addTrackingCat,
	
	-- manipulation d'une affirmation individelle
	getmainid = d.getMainId,
	formatStatement = d.formatStatement,
	statementDate = d.getFormattedDate, -- récupère la date des qualificatifs
	getFormattedQualifiers = d.getFormattedQualifiers,
	getQualifiers = d.getQualifiers,
	getReferences = d.getReferences,

	-- manipulation de snaks	
	getid = d.getId,
	formatSnak = d.formatSnak,
	
	-- utilisation de qids
	getEntity = d.getEntity,
	formatEntity = d.formatEntity,
	getLink = d.siteLink,
	getLabel = d.getLabel, --getLabel est plus simple que formatEntity

	-- utilisation des propriétés transitives
	isInstance = d.isInstance,
	isSubclass = d.isSubclass,
	addVals = d.addVals,
	transitiveVals = d.transitiveVals,
	inTransitiveVals = d.inTransitiveVals,
	findVal = d.findVal,

	-- gestion des dates
	mainDate = d.mainDate,
	getDate = d.getTheDate,
	keyDate = d.keyDate,

	-- Fonctions diverses
	citeItem = d.citeitem,
	translate = d.translate,
	Dump = d.Dump,
}

-- Fonctions frame pour usage depuis le Wikitexte (avec parfois des options pour gérer des données moins propres
local function cleanargs(args)
	local newargs = {}
	for i, j in pairs(args) do
		if j ~= '' then
			newargs[i] = j
		end
	end
	return newargs
end


function p.formatStatements( frame ) -- pour [[Modèle:Wikidata]]
	local args = {}
	if frame == mw.getCurrentFrame() then
		args = frame:getParent().args -- paramètres du modèle appelant (est-ce vraiment une bonne idée ?)
		for k, v in pairs(frame.args) do
			args[k] = v
		end
	else
		args = frame
	end
	return p.fromLua.formatStatements( args )
end

function p.addLinkBack( frame )
	local args = cleanargs(frame.args)
	if args[1] and args[1]:match"%S" then
		return d.addLinkBack( '', args.entity, mw.text.trim( args[1] ) )
	end
end

function p.formatEntity(frame)
	local args = cleanargs(frame.args)
	local entity = args.entity or args[1]
	if (not entity) or (entity == '') then
		entity = mw.wikibase.getEntityObject()
	end
	return d.formatEntity(entity, args)
end

function p.formatAndCat(frame)
	local args = cleanargs(frame.args)
	return d.formatAndCat(args)
end

function p.citeItem(frame)
	local args = cleanargs(frame.args)
	local item, page = args[1], args['page']
	return p.fromLua.citeItem(item, page)
end

function p.getLabel(frame)
	local args = cleanargs(frame.args)
	local item = args[1]
	local lang = args[2] or "fr"
	return d.getLabel(item, lang)
end


function p.mainDate(frame)
	return d.mainDate(frame.args['entity'])	
end

function p.Dump(frame)
	return d.Dump(frame.args[1])
end

function p.formatQualifiers(frame)
	local args = frame.args
	return d.formatQualifiers(args)
end

function p.getDescription(frame) -- fonction simpliste, mais bon, les descriptions Wikidata, c'est pas non plus super utile
	return  mw.wikibase.description(frame.args[1])
end

function p.getLink(frame)
	local args = frame.args
	local link, proj, lang = p.fromLua.getLink(args[1], args[2], args[3])
	return link
end

function p.translate(frame)
	return d.translate(frame.args[1])
end

function p.findVal(frame)
	local args = frame.args
	return d.findVal(args.source, args.target, args.property, args.recursion, args.instancedepth)
end

function p.transitiveVals(frame)
	local args = frame.args
	return d.transitiveVals(args.item, args, args.maxdepth, args.maxnodes, args.stopval, true)
end

return p