Modulo:European and national party data/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Test xlate_comp referring to Seggi
import en-wiki sandbox
 
(6 versioni intermedie di 2 utenti non mostrate)
Riga 156:
]]
 
local function xlate_wikidata (data_requested, qid, property_id, qualifier_id, value_of_qualifier, reference, preferred, raw, linked, unit)
mw.logObject( {data_requested, qid, property_id, qualifier_id, value_of_qualifier, reference, preferred, raw, linked}, "xlate_wikidata()" )
local local_reference = reference;
local local_reference = (reference == 'reference=yes') and 'reference' or '';
local local_preferred = preferred;
if local_reference == '' and reference == 'references=yes' then local_reference = 'references' end;
local local_raw = raw;
local local_preferred = (preferred == 'preferred=yes') and 'preferred' or '';
local local_linked = linked;
local local_raw = (raw == 'raw=yes') and 'raw' or '';
local local_linked = (linked == 'linked=yes') and 'linked' or '';
local local_unit = (unit == 'unit=yes') and 'unit' or '';
local Wd = require('Module:European_and_national_party_data/Wd')
 
if local_reference == 'reference=yes' then local_reference = 'reference' elseif local_reference == 'references=yes' then local_reference = 'references' else local_reference = '' end;
if local_preferred == 'preferred=yes' then local_preferred = 'preferred' else local_preferred = '' end;
if local_raw == 'raw=yes' then local_raw = 'raw' else local_raw = '' end;
if local_linked == 'linked=yes' then local_linked = 'linked' else local_linked = '' end;
local wdargs = {local_reference, local_preferred, local_raw, local_linked, local_unit, property_id}
if qid then
table.insert(wdargs, 56, qid)
end
if '' ~= qualifier_id andthen
if '' ~= value_of_qualifier then
wdargs[qualifier_id] = value_of_qualifier;
else
table.insert(wdargs, qualifier_id)
end
end
mw.logObject( wdargs, "wdargs" )
return Wd['_' .. data_requested](wdargs);
end
Riga 196 ⟶ 198:
]]
 
local function xlate_composition_bar (frame, seats, total_seats, color, width, percentage, background_color, border, num1, bar, num2)
if 'en' == cfg.this_project_language or 'ptfr' == cfg.this_project_language then
return frame:expandTemplate ({title='Infobox Parti politique/Sièges', args = {seats, total_seats, ['hex'] = color, ['chiffres1'] = num1, ['barre'] = bar, ['chiffres2'] = num2}});
elseif 'it' == cfg.this_project_language then
return frame:expandTemplate ({title='Seggi', args = {seats, total_seats, ['c'] = color}});
elseif 'es' == cfg.this_project_language then
return frame:expandTemplate ({title='Composition bar', args = {seats, total_seats, ['hex'] = color}});
elseif 'nl' == cfg.this_project_language then
local comp_bar_args_t = {
seats,
total_seats,
color,
width=width,
per=percentage,
['background-color'] = background_color,
border = border,
};
return frame:expandTemplate ({title='Percentagebalk', args = comp_bar_args_t});
else -- for all other languages the assumption is that the template is called composition bar
local comp_bar_args_t = {
seats,
Riga 208 ⟶ 227:
};
return frame:expandTemplate ({title='Composition bar', args = comp_bar_args_t});
elseif 'fr' == cfg.this_project_language then
return frame:expandTemplate ({title='Infobox Parti politique/Sièges', args = {seats, total_seats, ['hex'] = color}});
elseif 'it' == cfg.this_project_language then
return frame:expandTemplate ({title='Seggi', args = {seats, total_seats, ['c'] = color}});
end
end
Riga 290 ⟶ 305:
 
local data = "";
local data_unit = "";
local reference = local_parameter_to_value_or_boolean (frame, 'reference', 'boolean'); -- check verbosereference and make boolean
reference = (reference and option ~= "raw-noref") and 'references=yes' or ''; -- if reference is true, then the call will return a reference
local verbose = local_parameter_to_value_or_boolean (frame, 'verbose', 'boolean'); -- check verbose and make boolean
local raw = (option == "raw" or option == "raw-noref") and "raw=yes" or "raw=no"; -- check raw and format correctly
local linked = (option == "linked") and "linked=yes" or "linked=no"; -- check linked and format correctly
if reference and option ~= "raw-noref" then -- if reference is true, then the call will return a reference
local unit = (option == "unit") and "unit=yes" or "unit=no"; -- check linked and format correctly
reference = 'references=yes';
else
reference = '';
end
local party_qid = ""; -- init party_qid
Riga 315 ⟶ 329:
return make_error_msg (substitute (cfg.error_messages_t.unknown_party, {party}), template_name);
end
if not party then -- direct call when no party is specified
party_qid = "" -- This should not be needed since the function
end -- should error out above if no party specified.
if property_id == "label" then -- if the label of the Wikidata element is requested
data = xlate_wikidata ('label', party_qid, '', '', '', 'reference=no', 'preferred=no', raw, linked, unit);
if not party then
data = xlate_wikidata ('label', '', '', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
else
data = xlate_wikidata ('label', party_qid, '', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
end
elseif property_id == "individual members date" then -- special case
data = xlate_wikidata ('qualifier', party_qid, 'P2124', 'P585', '', 'reference=no', 'preferred=yes', raw, linked, unit);
if not party then
elseif property_id == cfg.data_prop_t.public_funding then -- special case
data = xlate_wikidata ('qualifier', '', P2124, '', P585, 'reference=no', 'preferred=yes', 'raw=no', 'linked=no');
data = tonumber(xlate_wikidata ('property', party_qid, property_id, '', '', '', '', 'raw=yes', '', ''));
data_unit = xlate_wikidata ('property', party_qid, property_id, '', '', '', '', '', '', 'unit=yes');
if nil ~= data then
if data > 1 then data_unit = data_unit .. 's' end;
else
data = '';
data = xlate_wikidata ('qualifier', party_qid, 'P2124', '', 'P585', 'reference=no', 'preferred=yes', 'raw=no', 'linked=no');
data_unit = '';
end
else -- for all other cases
data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', raw, linked, unit);
if not party then -- direct call when no party is specified
if option == "raw" or option == "raw-noref" then
data = xlate_wikidata ('property', '', property_id, '', '', reference, 'preferred=no', 'raw=yes', 'linked=no');
elseif option == "linked" then
data = xlate_wikidata ('property', '', property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=yes');
else
xlate_wikidata ('property', '', property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=no');
end
else -- otherwise we add the qID
if option == "raw" or option == "raw-noref" then
data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=yes', 'linked=no');
elseif option == "linked" then
data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=yes');
else
data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=no');
end
end
end
Riga 365 ⟶ 368:
return make_error_msg (substitute (cfg.error_messages_t.no_data, {party_qid, property_id}));
end
 
if property_id == cfg.data_prop_t.public_funding and '' ~= data then
return data;
return mw.getContentLanguage():formatNum(data) .. " " .. data_unit;
else
return data;
end
end
 
Riga 840 ⟶ 847:
local background_color = local_parameter_to_value_or_boolean (frame, 'background-color');
local border = local_parameter_to_value_or_boolean (frame, 'border');
local num1 = local_parameter_to_value_or_boolean (frame, 'num1');
local bar = local_parameter_to_value_or_boolean (frame, 'bar');
local num2 = local_parameter_to_value_or_boolean (frame, 'num2');
if width and not validate_width (width) then
Riga 886 ⟶ 896:
end
elseif party_type == "european_entity" and (institution == "LOWER_HOUSE" or institution == "UPPER_HOUSE") then
return xlate_composition_bar (frame, party_seats, institution_seats, color, width, percentage, background_color, border, num1, bar, num2);
else
return xlate_composition_bar (frame, party_seats, institution_seats, color, width, percentage, background_color, border, num1, bar, num2) .. ((reference and allpp_seats_ref (frame, party, institution)) or '');
end
end
Riga 1 048 ⟶ 1 058:
elseif data_type == "foundation date" then
return allpp_get_data (frame, party, cfg.data_prop_t.foundation_date);
elseif data_type == "foundation year" then
return mw.getContentLanguage():formatDate("Y",allpp_get_data (frame, party, cfg.data_prop_t.foundation_date, 'raw'));
elseif data_type == "individual members" then
return allpp_get_data (frame, party, cfg.data_prop_t.individual_members);
elseif data_type == "individual members date" then
return allpp_get_data (frame, party, 'individual members date');
elseif data_type == "individual members year" then
return mw.getContentLanguage():formatDate("Y",allpp_get_data (frame, party, 'individual members date', 'raw'));
elseif data_type == "label" then
return allpp_get_data (frame, party, 'label');
Riga 1 062 ⟶ 1 076:
elseif data_type == "website" then
return allpp_get_data (frame, party, cfg.data_prop_t.website);
 
 
else
Riga 1 171 ⟶ 1 184:
 
local function test2 (frame)
return cfg.this_project_language;
local args_t = get_args (frame);
local party = args_t[1] and args_t[1]:upper(); -- force to upper case
--if local_reference == 'reference=yes' then local_reference = 'reference' elseif local_reference == 'references=yes' then local_reference = 'references' else local_reference = '' end;
--if local_preferred == 'preferred=yes' then local_preferred = 'preferred' else local_preferred = '' end;
local local_raw = '';
local local_linked = '-';
--local qid = args_t[1];
--local property = args_t[2];
--return allpp_get_data (frame, party_qid, cfg.data_prop_t.country, 'raw-noref');
--return tostring(xlate_wikidata ('property', party, cfg.data_prop_t.website, '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no'));
return frame:expandTemplate ({title='wikidata', args = {["entity"] = party, cfg.data_prop_t.website, ['link'] = "-", ['numval'] = 1}});
end
 
Riga 1 193 ⟶ 1 196:
test2 = test2,
test_wikidata_entries = test_wikidata_entries,
-- xlate_wikidata = xlate_wikidata
}