Modulo:European and national party data/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
test xlate_param in formatDate |
import en-wiki sandbox |
||
(3 versioni intermedie 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 == '
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_raw == 'raw=yes' then local_raw = 'raw' else local_raw = '' end;
local wdargs = {local_reference, local_preferred, local_raw, local_linked, local_unit, property_id}
if qid then
table.insert(wdargs,
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 reference = local_parameter_to_value_or_boolean (frame, 'reference', 'boolean'); -- check
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
else▼
reference = '';▼
end▼
local party_qid = ""; -- init party_qid
Riga 333 ⟶ 329:
return make_error_msg (substitute (cfg.error_messages_t.unknown_party, {party}), template_name);
end
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
if not party then▼
▲ data = xlate_wikidata ('label', party_qid, '', '', '', 'reference=no', 'preferred=no', 'raw=no', 'linked=no');
elseif property_id == "individual members date" then -- special case
elseif property_id == cfg.data_prop_t.public_funding then -- special case
if data > 1 then data_unit = data_unit .. 's' end;
else
▲ data = xlate_wikidata ('qualifier', party_qid, 'P2124', 'P585', '', 'reference=no', 'preferred=yes', 'raw=no', 'linked=no');
data_unit = '';
end
else -- for all other cases
▲ if not party then -- direct call when no party is specified
▲ data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=yes', 'linked=no');
▲ data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=yes');
▲ data = xlate_wikidata ('property', party_qid, property_id, '', '', reference, 'preferred=no', 'raw=no', 'linked=no');
end
Riga 383 ⟶ 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
▲ end
end
Riga 858 ⟶ 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 904 ⟶ 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 067 ⟶ 1 059:
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);
Riga 1 073 ⟶ 1 065:
return allpp_get_data (frame, party, 'individual members date');
elseif data_type == "individual members year" then
return mw.getContentLanguage():formatDate(
elseif data_type == "label" then
return allpp_get_data (frame, party, 'label');
|