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
end
Riga 159 ⟶ 156:
]]
local function xlate_wikidata (
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 == '' and reference == 'references=yes' then local_reference = 'references' end;
local local_preferred = (preferred == 'preferred=yes') and 'preferred' or '';
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')
local wdargs = {local_reference, local_preferred, local_raw, local_linked, local_unit, property_id}
if qid then
table.insert(wdargs, 6, qid)
end
if '' ~= qualifier_id then
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 228 ⟶ 198:
]]
local function xlate_composition_bar (frame, seats, total_seats, color, width, percentage, background_color, border, num1, bar, num2)
if '
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});
end
end
Riga 320 ⟶ 305:
local data = "";
local data_unit = "";
local reference = local_parameter_to_value_or_boolean (frame, 'reference', 'boolean'); -- check
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 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);
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 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 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 (
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 (
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 (
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 (
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 (
end
end
elseif institution == 'EC' or institution == 'EUCO' then
if party == "THISPARTY" then
return xlate_wikidata (
elseif cfg.parties_t[party] then
return xlate_wikidata (
elseif cfg.alliances_t[party] then
return xlate_wikidata (
elseif party:match ('^Q%d+$') then
return xlate_wikidata (
end
else
if party == "THISPARTY" then
return xlate_wikidata (
elseif cfg.parties_t[party] then
return xlate_wikidata (
elseif cfg.alliances_t[party] then
return xlate_wikidata (
elseif party:match ('^Q%d+$') then
return xlate_wikidata (
end
end
Riga 538 ⟶ 515:
local function allpp_get_seats_ref_qid (frame, institution_qid)
return xlate_wikidata (
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 (
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 (
elseif cfg.alliances_t[party] then
retval = xlate_wikidata (
elseif cfg.parties_t[party] then
retval = xlate_wikidata (
elseif party:match ('^Q%d+$') then
retval = xlate_wikidata (
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 (
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 (
elseif party == "NONE" then -- returns seats not occupied by European parties
local retval = xlate_wikidata (
if institution == "EUCO" then -- if EUCO, use P208 and separate case to account for independent politicians
local ind = xlate_wikidata (
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 (
elseif party == "NONE" then -- returns seats not occupied by European parties
local retval = xlate_wikidata (
if institution == "EUCO" then -- if EUCO, use P208 and separate case to account for independent politicians
local ind = xlate_wikidata (
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 (
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 (
local house_seats = house_qid and xlate_wikidata (
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
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 (
local retval_upper = xlate_wikidata (
if '' == retval_lower then
Riga 1 205 ⟶ 1 184:
local function test2 (frame)
return cfg.this_project_language;
end
Riga 1 227 ⟶ 1 196:
test2 = test2,
test_wikidata_entries = test_wikidata_entries,
-- xlate_wikidata = xlate_wikidata
}
|