Vikipedia diskuto:Lua/Moduloj/Wikidata

Paĝenhavo ne ekzistas en aliaj lingvoj.
El Vikipedio, la libera enciklopedio
Ŝablona programado Diskutoj Lua Testoj Subpaĝoj
Modulo Esperanto English Deutsch

Modulo: Dokumentado


Possible to add formatEntity ? [from https://fr.wikipedia.org/wiki/Module:Wikidata][redakti fonton]

Thanks! Here the code : function wd.formatEntity( entity, params )

if (not entity) then return nil --formatError('entity-not-found') end local id = entity if type(id) == 'table' then id = id.id end

params = params or {} local lang = params.lang or defaultlang local speciallabels = params.speciallabels local displayformat = params.displayformat local labelformat = params.labelformat local defaultlabel = params.defaultlabel or id local linktype = params.link local defaultlink = params.defaultlink local defaultlinkquery = params.defaultlinkquery

if speciallabels and speciallabels[id] then --speciallabels override the standard label + link combination return speciallabels[id] end if params.displayformat == 'raw' then return id end

local link, label

label = wd.getLabel(entity, lang, labelformat)

-- détermination du fait qu'on soit ou non en train de rendre l'élément sur la page de son article local rendering_entity_on_its_page = wd.isPageOfQId(id)


if not label then if (defaultlabel == '-') then return nil end link = wd.siteLink(id, 'wikidata') return '' .. id .. '' .. addCat(modules.i18n['to translate']) -- si pas de libellé, on met un lien vers Wikidata pour qu'on comprenne à quoi ça fait référence end

if (linktype == '-') or rendering_entity_on_its_page then return label end

local link = wd.siteLink(entity, linktype, lang)

-- defaultlinkquery will try to link to another page on this Wiki if (not link) and defaultlinkquery then if type(defaultlinkquery) == 'string' then defaultlinkquery = {property = defaultlinkquery} end defaultlinkquery.excludespecial = true defaultlinkquery.entity = entity local claims = wd.getClaims(defaultlinkquery) if claims then for i, j in pairs(claims) do local id = wd.getMainId(j) link = wd.siteLink(id, linktype, lang) if link then break end end end end

if link then return '' .. label .. '' end

-- if not link, you can use defaultlink: a sidelink to another Wikimedia project if (not defaultlink) then defaultlink = {'enwiki'} end if defaultlink and (defaultlink ~= '-') then local linktype local sidelink, site, langcode

if type(defaultlink) == 'string' then defaultlink = {defaultlink} end for i, j in ipairs(defaultlink) do sidelink, site, langcode = wd.siteLink(entity, j, lang) if sidelink then break end end if not sidelink then sidelink, site = wd.siteLink(entity, 'wikidata') end

local icon, class, title = site, nil, nil -- le texte affiché du lien if site == 'wiki' then icon, class, title = langcode, "indicateur-langue", wd.translate('see-another-language', mw.language.fetchLanguageName(langcode, defaultlang)) elseif site == 'wikidata' then icon, class, title = 'd', "indicateur-langue", wd.translate('see-wikidata') else title = wd.translate('see-another-project', site) end local val = '' .. '' .. icon .. '' return label .. ' (' .. val .. ')' end return label end Bouzinac (diskuto) 21:17, 14 dec. 2021 (UTC)[Respondi]