« Module:Index template » : différence entre les versions
Contenu supprimé Contenu ajouté
améliore le support de Wikidata |
ajoute Wikidata pour plus de champ et début du découpage Wikidata du code du modèle (pour pouvoir le partager avec le header) |
||
Ligne 6 :
['Q23622'] = 'dictionary',
['Q187685'] = 'phdthesis'
}
local indexToWikidata = {
-- type est géré spécialement
['titre'] = 'P1476',
['sous_titre'] = 'P1680',
['volume'] = 'P478',
['auteur'] = 'P50',
['traducteur'] = 'P655',
['editeur_scientifique'] = 'P98',
['illustrateur'] = 'P110',
['editeur'] = 'P123',
-- TODO ['School'] = 'PXXX',
['lieu'] = 'P291',
['annee'] = 'P577',
-- TODO ['publication'] = 'PXX',
-- TODO ['bibliotheque'] = 'PXX',
-- TODO ['clef'] = 'PXX',
['BNF_ARK'] = 'P4258',
-- TODO ['source'] = 'PXX',
-- TODO ['image'] = 'PXX',
}
function indexDataWithWikidata(frame)
--create a clean table of parameters with blank parameters removed
local args = {}
for k,v in pairs(frame.args) do
if v ~= '' then
args[k] = v
end
end
local item = nil
if args.wikidata_item then
item = mw.wikibase.getEntity(args.wikidata_item)
if item == nil then
mw.addWarning('L\'identifiant d\'entité Wikidata [[d:' .. args.wikidata_item .. '|' .. args.wikidata_item .. ']] mise dans le paramètre "entité Wikidata" de la page Livre: ne semble pas valide.')
end
end
if not item then
return {
['args'] = args,
['item'] = nil
}
end
-- type depuis Wikidata
if not args.type then
for _, statement in pairs(item:getBestStatements('P31')) do
if statement.mainsnak.datavalue ~= nil then
local typeId = statement.mainsnak.datavalue.value.id
if wikidataTypeToIndexType[typeId] then
args.type = wikidataTypeToIndexType[typeId]
end
end
end
end
for arg, propertyId in pairs(indexToWikidata) do
if not args[arg] then
local values = {}
for _, statement in pairs(item:getBestStatements(propertyId)) do
table.insert(values, mw.wikibase.formatValue(statement.mainsnak))
end
if next(values) then
args[arg] = mw.text.listToText(values) .. ' [[File:OOjs UI icon edit-ltr.svg|Voir et modifier les données sur Wikidata|10px|baseline|class=noviewer|link=d:' .. item.id .. '#' .. propertyId .. ']]'
end
elseif arg == 'titre' then
args.titre = withWikidataLink(args.titre, 'Livres avec un lien Wikidata')
else
args[arg] = withWikidataLink(args[arg])
end
end
-- title
if not args.titre then
args.titre = item:getLabel()
end
return {
['args'] = args,
['item'] = item
}
end
function withWikidataLink(wikitext, category)
if wikitext == nil then
return nil
end
new_wikitext = mw.ustring.gsub(wikitext, '%[%[([^|%]]*)%]%]', function(page)
Ligne 46 ⟶ 113 :
title = title.redirectTarget
end
local tag = mw.html.create('span')
tag:wikitext('[[' .. page .. '|' .. label .. ']]')
if itemId ~= nil then
tag:wikitext(' [[Image:Wikidata.svg|10px|link=d:' .. itemId .. '|Voir l\'entité sur Wikidata]]')
if category ~= nil then
tag:wikitext('[[
end
end
Ligne 79 ⟶ 140 :
function indexTemplate(frame)
--create a clean table of parameters with blank parameters removed
local
local item = data.item
local page = mw.title.getCurrentTitle()
local html = mw.html.create()
html:wikitext('[[Catégorie:Livres avec un identifiant Wikidata]]<indicator name="wikidata">[[File:Wikidata.svg|20px|élément Wikidata|link=d:' .. item.id .. ']]</indicator>')
end
Ligne 144 ⟶ 185 :
local metadataTable = metadataContainer:tag('table')
if args.titre then
if args.type == 'journal' then
addRow(metadataTable, 'Journal', args.titre)
else
addRow(metadataTable, 'Titre',
end
else
Ligne 158 ⟶ 196 :
addRow(metadataTable, 'Sous-titre', args.sous_titre)
addRow(metadataTable, 'Volume', args.volume)
addRow(metadataTable, 'Auteur',
addRow(metadataTable, 'Traducteur',
addRow(metadataTable, 'Éditeur',
addRow(metadataTable, 'Illustrateur',
addRow(metadataTable, 'École',
addRow(metadataTable, 'Maison d’édition',
addRow(metadataTable, 'Lieu d’édition',
addRow(metadataTable, 'Année d’édition', args.annee)
addRow(metadataTable, 'Publication originale', args.publication)
|