Module:Module sandbox
Appearance
![]() | Welcome to Module:Module sandbox, a Wikipedia module sandbox. This page is itself a module, and it allows you to carry out experiments related to module editing. If you wish to experiment with article editing, use the Wikipedia Sandbox or your own user sandbox.
To edit, click the edit tab above, make your changes and click the Publish changes button when finished. Click here to reset the sandbox. Please do not place malicious Lua code here, or copyrighted, offensive, illegal or libelous content in the sandboxes. For assistance with Lua coding, try the technical forum at the Village Pump. There are also several template sandboxes you can use to carry out experiments:
You can also conduct tests using the Wikipedia Sandbox. For instance, to invoke this module there, edit it so that it includes: {{#invoke:Module sandbox}} |
More info
Sandbox games |
Usage
{{#invoke:Module sandbox|function_name}}
require ('strict');
local get_args = require ('Module:Arguments').getArgs; -- function to fetch frame and parent frame arguments
--[[--------------------------< D E F I N E S >----------------------------------------------------------------
]]
local institutions_t = { -- map institution abbreviation to wikidata qid
COR = 'Q205203',
EC = 'Q8880',
EP = 'Q8889',
EUCO = 'Q8886'
}
local parties_t = { -- map party abbreviation to wikidata qid
ALDE = 'Q25079',
ECPM = 'Q1377279',
ECR = 'Q1577483',
EDP = 'Q734792',
EFA = 'Q639383',
EGP = 'Q950179',
EL = 'Q202649',
ELA = 'Q130219314',
ESN = 'Q130269264',
EPP = 'Q208242',
Patriots = 'Q18907386',
PES = 'Q220945'
}
--[[--------------------------< S E A T S >--------------------------------------------------------------------
expands {{wikidata}} templates:
{{wikidata|property|Q208242|P1410|P208=Q8880}} → '11'
{{wikidata|property|Q55|P395}} → 'NL'
]]
local function seats (frame)
local args_t = get_args (frame); -- get arguments; empty string or whitespace positional parameters set to nil
local institution = args_t[1] and args_t[1]:upper(); -- force to upper case
local party = args_t[2] and args_t[2]:upper();
if not party then -- party not specified
return institutions_t[institution] and frame:expandTemplate ({title='wikidata', args = {'property', institutions_t[institution], 'P1342'}}) or 'error';
elseif party == "ALL" then
return institutions_t[institution] and frame:expandTemplate ({title='wikidata', args = {'property', institutions_t[institution], 'P1342'}}) or 'error';
elseif party == "NONE" then
return institutions_t[institution] and frame:expandTemplate ({title='wikidata', args = {'property', parties_t[EPP], 'P1410', P208 = institutions_t[institution]}});
else
if institution == "EC" or institution == "EUCO" then
return institutions_t[institution] and frame:expandTemplate ({title='wikidata', args = {'property', parties_t[party], 'P1410', P208 = institutions_t[institution]}}) or 'unknown party';
elseif institution == "EP" or institution == "COR" then
return institutions_t[institution] and frame:expandTemplate ({title='wikidata', args = {'property', parties_t[party], 'P1410', P194 = institutions_t[institution]}}) or 'unknown party';
end
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
seats = seats,
}