Différences entre versions de « Module:Notice Autorité »
Sauter à la navigation
Sauter à la recherche
(Page créée avec « --[[ -- Debug console frame = mw.getCurrentFrame() -- Get a frame object newFrame = frame:newChild{ -- Get one with args title = 'Alfred Baudrillart' , args = { iri =… ») |
|||
| (4 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 29 : | Ligne 29 : | ||
| − | select | + | select DISTINCT ?propLabel ?ID ?formater # ?logo |
where { | where { | ||
| Ligne 36 : | Ligne 36 : | ||
?prop wikibase:directClaim ?propClaim . | ?prop wikibase:directClaim ?propClaim . | ||
?prop wdt:P1630 ?formater . | ?prop wdt:P1630 ?formater . | ||
| − | ?prop wdt:P2378 ?entity . | + | # ?prop wdt:P2378 ?entity . |
| − | ?entity wdt:P154 ?logo . | + | # ?entity wdt:P154 ?logo . |
| − | wd: | + | wd:]] .. f.args["Wikidata ID"] .. [[ ?propClaim ?ID . |
SERVICE wikibase:label { | SERVICE wikibase:label { | ||
| − | bd:serviceParam wikibase:language "en | + | bd:serviceParam wikibase:language "fr,en" . |
} | } | ||
} | } | ||
| + | ORDER BY ?propLabel | ||
LIMIT 100 | LIMIT 100 | ||
]] ) | ]] ) | ||
-- linkedwiki.print_r(result) | -- linkedwiki.print_r(result) | ||
| − | + | local text = [[ | |
| − | + | == Notice Autorité == | |
| + | ]] | ||
| + | local newline=[[ | ||
| + | |||
| + | ]] | ||
local i = 0 | local i = 0 | ||
local row = nill | local row = nill | ||
| + | local link = nil | ||
| + | local logo = nil | ||
row = result['result']['rows'][i] | row = result['result']['rows'][i] | ||
while( row ~= nil ) | while( row ~= nil ) | ||
do | do | ||
--linkedwiki.print_r(row) | --linkedwiki.print_r(row) | ||
| + | link = string.gsub(row["formater"], "$1",row["ID"]) | ||
| + | |||
| + | -- if string.sub( row["logo"], -3 ) == 'svg' then | ||
| + | -- logo = "[[".. string.gsub(row["logo"], "http://commons.wikimedia.org/wiki/Special:FilePath/","File:").."|70px|link=".. link .. "]]" | ||
| + | -- else | ||
| + | -- logo = "[" .. link .. " " .. logo .. "]" | ||
| + | -- end | ||
| − | text = text .. | + | text = text .. "* <span class='plainlinks module-oeuvres-vignettes'>" .. "[".. link .. " ".. row["propLabel"] .. "]".. "</span>" .. newline |
i = i + 1 | i = i + 1 | ||
row = result['result']['rows'][i] | row = result['result']['rows'][i] | ||
end | end | ||
| + | |||
return text | return text | ||
Version actuelle datée du 21 novembre 2021 à 15:26
Utilisation
Ce module a pour fonction de pouvoir afficher les notices d'un auteur via Wikidata
Exemple d'utilisation
{{#invoke:Oeuvres de l'auteur|section
| Wikidata ID = Q666551
}}
Résultat pour Alfred Baudrillart
Erreur Lua : ERREUR SPARQL (voir les détails en activant the mode debug).
Paramétres
Wikidata ID: Id de Wikidata
--[[
-- Debug console
frame = mw.getCurrentFrame() -- Get a frame object
newFrame = frame:newChild{ -- Get one with args
title = 'Alfred Baudrillart' ,
args = {
iri = 'https://gregorius.dsi.universite-paris-saclay.fr/wiki/Alfred_Baudrillart' ,
["Wikidata ID"] = 'Q666551'
}
}
mw.log(p.section( newFrame ) )
]]
local p = {}
local linkedwiki = require 'linkedwiki'
function p.section(f)
local object = linkedwiki.new()
object:setConfig("http://www.wikidata.org")
mw.log(object:getConfig())
local result = object:query( [[
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
select DISTINCT ?propLabel ?ID ?formater # ?logo
where {
?prop wdt:P31/wdt:P279* wd:Q18614948 .
?prop wikibase:directClaim ?propClaim .
?prop wdt:P1630 ?formater .
# ?prop wdt:P2378 ?entity .
# ?entity wdt:P154 ?logo .
wd:]] .. f.args["Wikidata ID"] .. [[ ?propClaim ?ID .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "fr,en" .
}
}
ORDER BY ?propLabel
LIMIT 100
]] )
-- linkedwiki.print_r(result)
local text = [[
== Notice Autorité ==
]]
local newline=[[
]]
local i = 0
local row = nill
local link = nil
local logo = nil
row = result['result']['rows'][i]
while( row ~= nil )
do
--linkedwiki.print_r(row)
link = string.gsub(row["formater"], "$1",row["ID"])
-- if string.sub( row["logo"], -3 ) == 'svg' then
-- logo = "[[".. string.gsub(row["logo"], "http://commons.wikimedia.org/wiki/Special:FilePath/","File:").."|70px|link=".. link .. "]]"
-- else
-- logo = "[" .. link .. " " .. logo .. "]"
-- end
text = text .. "* <span class='plainlinks module-oeuvres-vignettes'>" .. "[".. link .. " ".. row["propLabel"] .. "]".. "</span>" .. newline
i = i + 1
row = result['result']['rows'][i]
end
return text
end
return p