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

Contenuto cancellato Contenuto aggiunto
Ahecht (discussione | contributi)
simplify
import en-wiki sandbox
 
(Una versione intermedia di un altro utente 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 == 'reference=yes') and 'reference' or '';
if local_reference == 'reference=yes' thenand local_reference = 'reference' elseif local_reference == 'references=yes' then local_reference = 'references' else local_reference = '' end;
local local_preferred = (preferred == 'preferred=yes') and 'preferred' or '';
local local_raw = raw;
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 then
Riga 201 ⟶ 198:
]]
 
local function xlate_composition_bar (frame, seats, total_seats, color, width, percentage, background_color, border, num1, bar, num2)
if 'fr' == 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}});
Riga 308 ⟶ 305:
 
local data = "";
local local_rawdata_unit = raw"";
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
local unit = (option == "unit") and "unit=yes" or "unit=no"; -- check linked and format correctly
local party_qid = ""; -- init party_qid
Riga 336 ⟶ 335:
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);
elseif property_id == "individual members date" then -- special case
data = xlate_wikidata ('qualifier', party_qid, 'P2124', 'P585', '', 'reference=no', 'preferred=yes', raw, linked, unit);
elseif property_id == cfg.data_prop_t.public_funding then -- special case
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_unit = '';
end
else -- for all other cases
data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', raw, linked, unit);
end
Riga 360 ⟶ 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 835 ⟶ 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 881 ⟶ 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 050 ⟶ 1 065:
return allpp_get_data (frame, party, 'individual members date');
elseif data_type == "individual members year" then
return mw.getContentLanguage():formatDate(xlate_param ('"Y')",allpp_get_data (frame, party, 'individual members date', 'raw'));
elseif data_type == "label" then
return allpp_get_data (frame, party, 'label');
Riga 1 181 ⟶ 1 196:
test2 = test2,
test_wikidata_entries = test_wikidata_entries,
-- xlate_wikidata = xlate_wikidata
}