« Module:Sandbox/TiagoLubiana/Infobox » : différence entre les versions

Contenu supprimé Contenu ajouté
TiagoLubiana (discuter | contributions)
Aucun résumé des modifications
TiagoLubiana (discuter | contributions)
Aucun résumé des modifications
Ligne 33 :
}
 
-- seems specific.
local function addWikidataCat(prop)
maintenance = maintenance .. wd.addTrackingCat(prop)
end
 
-- seems specific too
local function expandQuery(query)
local value, number -- valeur à retourner, nombre de valeurs pour accorder le libellé
if not query.entity then
query.entity = localdata.item
end
if not query.conjtype then
query.conjtype = 'comma'
end
local claims = wd.getClaims(query)
if (not claims) then
return nil
end
return wd.formatAndCat(query), #claims -- pour l'accord au pluriel
end
 
-- seems specific too
local function getWikidataValue(params, wikidataparam)
-- Retrieves the Wikidata value for the value, either in the "wikidata" parameter or in the "property" parameter
if not localdata.item then
return nil
end
 
if params.blockers then -- blockers are local parameters that disable the wikidata query
local blockers = params.blockers
if (type(blockers) == 'string') then
blockers = {blockers}
end
for i, blocker in ipairs(blockers) do
if localdata[blocker] then
return nil
end
end
end
 
local v, valnum -- la valeur à retourner, et le nombre de de valeurs (pour l'accord grammatical)
if not wikidataparam then -- par défaut la valeur wikidata est dans le paramètre "wikidata" mais dans les structures composées comme "title", il y a plusieurs paramètres wikidata
wikidataparam = 'wikidata'
end
 
if params[wikidataparam] then
if type(params[wikidataparam]) == 'function' then
v, valnum = params[wikidataparam](localdata.item)
elseif type(params[wikidataparam]) == 'table' then
v, valnum = expandQuery(params[wikidataparam])
else
v, valnum = params[wikidataparam]
end
end
if not v then
return nil
end
v = linguistic.ucfirst(v)
return v, valnum
end
 
-- seems specific too
local function getValue(val, params)
if type(val) == 'string' then
return localdata[val]
elseif type(val) == 'function' then
return val(localdata, localdata.item, params)
elseif type(val) == 'table' then
for i, j in pairs(val) do -- si plusieurs paramètres possibles (legacy de vieux code), prendre le premier non vide
if localdata[j] then
return localdata[j]
end
end
end
end
 
-- seems specific too
local function addMaintenanceCat(cat, sortkey)
if page.namespace ~= 0 then
return ''
end
if cat then
maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
end
end
 
function p.separator(params)
local style = params['separator style'] or {}
style.height = style.height or '2px'
style['background-color'] = style['background-color'] or maincolor
return mw.html.create('hr'):css( style )
end
 
--[=[
Ligne 896 ⟶ 802 :
return tostring(infobox) .. externaltext, maintenance
end
 
--[=[
Series of Basic, low-level functions
]=]
 
local function addWikidataCat(prop)
maintenance = maintenance .. wd.addTrackingCat(prop)
end
 
local function expandQuery(query)
local value, number -- valeur à retourner, nombre de valeurs pour accorder le libellé
if not query.entity then
query.entity = localdata.item
end
if not query.conjtype then
query.conjtype = 'comma'
end
local claims = wd.getClaims(query)
if (not claims) then
return nil
end
return wd.formatAndCat(query), #claims -- pour l'accord au pluriel
end
 
local function getWikidataValue(params, wikidataparam)
-- Retrieves the Wikidata value for the value, either in the "wikidata" parameter or in the "property" parameter
if not localdata.item then
return nil
end
 
if params.blockers then -- blockers are local parameters that disable the wikidata query
local blockers = params.blockers
if (type(blockers) == 'string') then
blockers = {blockers}
end
for i, blocker in ipairs(blockers) do
if localdata[blocker] then
return nil
end
end
end
 
local v, valnum -- la valeur à retourner, et le nombre de de valeurs (pour l'accord grammatical)
if not wikidataparam then -- par défaut la valeur wikidata est dans le paramètre "wikidata" mais dans les structures composées comme "title", il y a plusieurs paramètres wikidata
wikidataparam = 'wikidata'
end
 
if params[wikidataparam] then
if type(params[wikidataparam]) == 'function' then
v, valnum = params[wikidataparam](localdata.item)
elseif type(params[wikidataparam]) == 'table' then
v, valnum = expandQuery(params[wikidataparam])
else
v, valnum = params[wikidataparam]
end
end
if not v then
return nil
end
v = linguistic.ucfirst(v)
return v, valnum
end
 
local function getValue(val, params)
if type(val) == 'string' then
return localdata[val]
elseif type(val) == 'function' then
return val(localdata, localdata.item, params)
elseif type(val) == 'table' then
for i, j in pairs(val) do -- si plusieurs paramètres possibles (legacy de vieux code), prendre le premier non vide
if localdata[j] then
return localdata[j]
end
end
end
end
 
local function addMaintenanceCat(cat, sortkey)
if page.namespace ~= 0 then
return ''
end
if cat then
maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
end
end
 
function p.separator(params)
local style = params['separator style'] or {}
style.height = style.height or '2px'
style['background-color'] = style['background-color'] or maincolor
return mw.html.create('hr'):css( style )
end
 
 
 
return p