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

Contenuto cancellato Contenuto aggiunto
import from en-wiki module
 
import en-wiki sandbox
 
(8 versioni intermedie di 2 utenti non mostrate)
Riga 66:
new_URL = new_URL.gsub(new_URL, pattern, "");
end
 
if 'fr' == cfg.this_project_language then
return "[" .. URL .. " " .. new_URL .. "]";
else
return "[" .. URL .. " " .. new_URL .. "]";
end
end
 
Riga 159 ⟶ 156:
]]
 
local function xlate_wikidata (frame, 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 '';
if 'en' == cfg.this_project_language or 'pt' == cfg.this_project_language then
local local_linked = (linked == 'linked=yes') and 'linked' or '';
if local_reference == 'reference=yes' then local_reference = 'reference' elseif local_reference == 'references=yes' then local_reference = 'references' else local_reference = '' end;
local local_unit = (unit == 'unit=yes') and 'unit' or '';
if local_preferred == 'preferred=yes' then local_preferred = 'preferred' else local_preferred = '' end;
local Wd = require('Module:European_and_national_party_data/Wd')
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
if '' ~= value_of_qualifier then
if qid then
return frame:expandTemplate ({title='wikidata', args = {data_requested, local_reference, local_preferred, local_raw, local_linked, qid, property_id, [qualifier_id] = value_of_qualifier}});
table.insert(wdargs, 6, qid)
--data_requested .. " - " .. qid .. " - " .. property_id .. " - " .. qualifier_id .. " = " .. value_of_qualifier;
end
else
if '' ~= qualifier_id then
return frame:expandTemplate ({title='wikidata', args = {data_requested, local_reference, local_preferred, local_raw, local_linked, qid, property_id}});
if '' ~= value_of_qualifier then
end
wdargs[qualifier_id] = value_of_qualifier;
else
table.insert(wdargs, qualifier_id)
if '' ~= value_of_qualifier then
return frame:expandTemplate ({title='wikidata', args = {data_requested, local_reference, local_preferred, local_raw, local_linked, property_id, [qualifier_id] = value_of_qualifier}});
else
return frame:expandTemplate ({title='wikidata', args = {data_requested, local_reference, local_preferred, local_raw, local_linked, property_id}});
end
end
elseif 'fr' == cfg.this_project_language then
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 = '' else local_linked = '-' end;
if data_requested == 'references' then return '' end;
if qid then
if data_requested == 'label' then
return frame:expandTemplate ({title='Intitulé', args = {qid}});
elseif '' ~= value_of_qualifier then
--example of query not from EUPP page: {{wikidata|entity=Q208242|P1410|qualifier=P208|qualifiervalue=Q8886}}
return frame:expandTemplate ({title='wikidata', args = {["entity"] = qid, property_id, ['displayformat'] = local_raw, ['link'] = local_linked, ["qualifier"] = qualifier_id, ["qualifiervalue"] = value_of_qualifier, ['numval'] = 1}});
else
--example of query not from EUPP page: {{wikidata|entity=Q208242|P465}}
return frame:expandTemplate ({title='wikidata', args = {["entity"] = qid, property_id, ['displayformat'] = local_raw, ['link'] = local_linked, ['numval'] = 1}});
end
else
if data_requested == 'label' then
return frame:expandTemplate ({title='Intitulé'});
elseif '' ~= value_of_qualifier then
--example of query from EUPP page: {{wikidata|P1410|qualifier=P208|qualifiervalue=Q8886}}
return frame:expandTemplate ({title='wikidata', args = {property_id, ['displayformat'] = local_raw, ['link'] = local_linked, ["qualifier"] = qualifier_id, ["qualifiervalue"] = value_of_qualifier, ['numval'] = 1}});
else
return frame:expandTemplate ({title='wikidata', args = {property_id, ['displayformat'] = local_raw, ['link'] = local_linked, ['numval'] = 1}});
end
end
end
mw.logObject( wdargs, "wdargs" )
return Wd['_' .. data_requested](wdargs);
end
 
Riga 228 ⟶ 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 240 ⟶ 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}});
end
end
Riga 320 ⟶ 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 345 ⟶ 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 (frame, 'label', '', '', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
else
data = xlate_wikidata (frame, '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 (frame, '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 (frame, '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 (frame, 'property', '', property_id, '', '', reference, 'preferred=no', 'raw=yes', 'linked=no');
elseif option == "linked" then
data = xlate_wikidata (frame, 'property', '', property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=yes');
else
xlate_wikidata (frame, '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 (frame, 'property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=yes', 'linked=no');
elseif option == "linked" then
data = xlate_wikidata (frame, 'property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=yes');
else
data = xlate_wikidata (frame, 'property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=no');
end
end
end
Riga 395 ⟶ 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 428 ⟶ 405:
 
local function institution_size (frame, institution)
local institution_size = xlate_wikidata (frame, 'property', cfg.institutions_t[institution], 'P1342', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- get the institution size
if '' == institution_size then -- if no institution size
return make_error_msg (substitute (cfg.error_messages_t.unknown_inst, {institution}));
Riga 443 ⟶ 420:
 
local function member_state_delegation_size (frame, member_state_qid)
local delegation_size = xlate_wikidata (frame, 'property', member_state_qid, 'P1410', 'P194', 'Q8889', 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- get the delegation size
if '' == delegation_size then -- if no delegation size
return make_error_msg (substitute (cfg.error_messages_t.not_member_state, {member_state_qid}));
Riga 467 ⟶ 444:
end
 
return house_qid and xlate_wikidata (frame, 'property', house_qid, 'P1342', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no') or 0; -- house_qid is nil when no upper or lower house
end
 
Riga 507 ⟶ 484:
local member_state_qid = allpp_get_data (frame, mw.wikibase.getEntityIdForCurrentPage(), cfg.data_prop_t.country, 'raw-noref');
local house_qid = house_qid_from_member_state_qid (institution, member_state_qid)
return xlate_wikidata (frame, 'references', '', 'P1410', 'P194', house_qid, 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif party:match ('^Q%d+$') then
local member_state_qid = allpp_get_data (frame, party, cfg.data_prop_t.country, 'raw-noref');
local house_qid = house_qid_from_member_state_qid (institution, member_state_qid)
return xlate_wikidata (frame, 'references', party, 'P1410', 'P194', house_qid, 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
end
end
elseif institution == 'EC' or institution == 'EUCO' then
if party == "THISPARTY" then
return xlate_wikidata (frame, 'references', '', 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif cfg.parties_t[party] then
return xlate_wikidata (frame, 'references', cfg.parties_t[party], 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif cfg.alliances_t[party] then
return xlate_wikidata (frame, 'references', cfg.alliances_t[party], 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif party:match ('^Q%d+$') then
return xlate_wikidata (frame, 'references', party, 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
end
else
if party == "THISPARTY" then
return xlate_wikidata (frame, 'references', '', 'P1410', 'P194', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif cfg.parties_t[party] then
return xlate_wikidata (frame, 'references', cfg.parties_t[party], 'P1410', 'P194', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif cfg.alliances_t[party] then
return xlate_wikidata (frame, 'references', cfg.alliances_t[party], 'P1410', 'P194', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif party:match ('^Q%d+$') then
return xlate_wikidata (frame, 'references', party, 'P1410', 'P194', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
end
end
Riga 538 ⟶ 515:
 
local function allpp_get_seats_ref_qid (frame, institution_qid)
return xlate_wikidata (frame, 'references', '', 'P1410', 'P194', institution_qid, 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
end
 
Riga 578 ⟶ 555:
return tonumber (party_seats) and round (100 * party_seats / member_state_delegation_size (frame, member_state_qid)) or party_seats;
else
return tonumber (party_seats) and round (100 * party_seats / xlate_wikidata (frame, 'property', cfg.institutions_t[institution], 'P1342', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no')) or party_seats;
end
end
Riga 602 ⟶ 579:
local retval = "";
if party == "THISPARTY" then -- flag used when module is called from the page of a European party; less expensive
retval = xlate_wikidata (frame, 'property', '', 'P1410', body_prop, cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- init some of the {{wikidata}} parameters with THISPARTY (only when called from the page of a European party)
elseif cfg.alliances_t[party] then
retval = xlate_wikidata (frame, 'property', cfg.alliances_t[party], 'P1410', body_prop, cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- init some of the {{wikidata}} parameters
elseif cfg.parties_t[party] then
retval = xlate_wikidata (frame, 'property', cfg.parties_t[party], 'P1410', body_prop, cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- init some of the {{wikidata}} parameters
elseif party:match ('^Q%d+$') then
retval = xlate_wikidata (frame, 'property', party, 'P1410', body_prop, cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- init some of the {{wikidata}} parameters
end
 
Riga 642 ⟶ 619:
for _, qid in pairs (cfg.parties_t) do -- loop through all parties in <cfg.parties_t>
local local_qid = qid; -- set the last {{wikidata}} parameter
sum = sum + xlate_wikidata (frame, 'property', local_qid, 'P1410', body_prop, cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- expand and tally
end
 
Riga 665 ⟶ 642:
local function eupp_seats_in_eu_institutions (frame, party, institution)
if party == "IND" and institution == "EUCO" then -- special case of independent politicians on European Council
return xlate_wikidata (frame, 'property', cfg.misc_parties_t['IND'], 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
 
elseif party == "NONE" then -- returns seats not occupied by European parties
local retval = xlate_wikidata (frame, 'property', cfg.institutions_t[institution], 'P1342', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no'); -- get number of seats in the institution
 
if institution == "EUCO" then -- if EUCO, use P208 and separate case to account for independent politicians
local ind = xlate_wikidata (frame, 'property', cfg.misc_parties_t['IND'], 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
return retval - (eupp_sum_seats_in_eu_institutions (frame, institution, cfg.body_prop_t[institution]) + ind);
 
Riga 706 ⟶ 683:
local function eupp_seat_share_in_eu_institutions (frame, party, institution)
if party == "IND" and institution == "EUCO" then -- special case of independent politicians on European Council
return allpp_make_share_in_eu_institutions (frame, xlate_wikidata (frame, 'property', cfg.misc_parties_t['IND'], 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no'), institution);
 
elseif party == "NONE" then -- returns seats not occupied by European parties
local retval = xlate_wikidata (frame, 'property', cfg.institutions_t[institution], 'P1342', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
 
if institution == "EUCO" then -- if EUCO, use P208 and separate case to account for independent politicians
local ind = xlate_wikidata (frame, 'property', cfg.misc_parties_t['IND'], 'P1410', 'P208', cfg.institutions_t[institution], 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
return allpp_make_share_in_eu_institutions (frame, retval - (eupp_sum_seats_in_eu_institutions (frame, institution, cfg.body_prop_t[institution]) + ind), institution);
 
Riga 749 ⟶ 726:
end
return house_qid and xlate_wikidata (frame, 'property', national_party_qid, 'P1410', 'P194', house_qid, 'reference=no', 'preferred=no', 'raw=no', 'linked=no') or 0;
end
 
Riga 829 ⟶ 806:
local house_qid = house_qid_from_member_state_qid (house_type, member_state_qid);
local npp_seats = house_qid and xlate_wikidata (frame, 'property', party_qid, 'P1410', 'P194', house_qid, 'reference=no', 'preferred=no', 'raw=no', 'linked=no') or 0;
local house_seats = house_qid and xlate_wikidata (frame, 'property', house_qid, 'P1342', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no') or 0;
if data == "seats" then
Riga 870 ⟶ 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
return make_error_msg (substitute (cfg.error_messages_t.parameter_invalid, {width}), template_name); -- yep, abandon with error message
end
if 'fr' == cfg.this_project_language then -- the French version of the wikidata template does not allow only grabbing the reference (it is always attached to the value, which breaks the composition bar)
reference = false;
end
 
Riga 920 ⟶ 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 082 ⟶ 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 096 ⟶ 1 076:
elseif data_type == "website" then
return allpp_get_data (frame, party, cfg.data_prop_t.website);
 
 
else
Riga 1 157 ⟶ 1 136:
local upper_house_qid = cfg.tab_data_t[row].upper_house_qid;
local upper_house_name = cfg.tab_data_t[row].upper_house;
local retval_lower = xlate_wikidata (frame, 'property', national_party_qid, 'P1410', 'P194', lower_house_qid, 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
local retval_upper = xlate_wikidata (frame, 'property', national_party_qid, 'P1410', 'P194', upper_house_qid, 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
if '' == retval_lower then
Riga 1 205 ⟶ 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 (frame, '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 227 ⟶ 1 196:
test2 = test2,
test_wikidata_entries = test_wikidata_entries,
-- xlate_wikidata = xlate_wikidata
}