This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This template is used on many pages, and changes to it will be widely noticed. Please test any changes in the template's /sandbox or /testcases subpages, or in a user subpage, and consider discussing changes at the talk page before implementing them.
localp={}localdefault_color='#F8F9FA'localcategories={party_not_in_list='[[Category:Pages using Political party with unknown party]]',shortname_not_in_list='[[Category:Pages using Political party with missing shortname]]',color_not_in_list='[[Category:Pages using Political party with missing color]]',}localfunctioncreate_error(error_message)returnstring.format('<strong class="error">%s</strong>',error_message)endlocalfunctiongetFirstLetter(party)localindex=mw.ustring.sub(party,1,1)-- Set index for non-A-Z startsifstring.match(index,'%A')thenreturn'1'endreturnstring.upper(index)endlocalfunctionstripToNil(text)-- If text is a string, return its trimmed content, or nil if empty.-- Otherwise return text (which may, for example, be nil).iftype(text)=='string'thentext=text:match('(%S.-)%s*$')localdelink=require('Module:Delink')._delinktext=delink({text,wikilinks="target"})endreturntextend-- Example of having all the data - color and names - in one table. Requires one page to be edited instead of two when adding a new party.functionp._fetch(args)ifnotargs[1]thenreturncreate_error("parameter 1 should be a party name.")endifnotargs[2]thenreturncreate_error("parameter 2 should be the output type.")endlocalparty=stripToNil(args[1])localout_type=stripToNil(args[2])ifout_type=='colour'thenout_type='color'endlocalindex=getFirstLetter(party)-- Load data from submodulelocaldata=mw.loadData('Module:Political party/'..index)localdata_all=data.fulllocalparty_alt=data.alternate[party]localparty_infoifparty_altthenifdata_all[party_alt]thenparty_info=data_all[party_alt]elseindex=getFirstLetter(party_alt)data=mw.loadData('Module:Political party/'..index)party_info=data.full[party_alt]endelseparty_info=data_all[party]end-- Check if database value exists-- * Not even in database - return given error or input-- * No color - return error-- * No shortname/abbrev - return first non-blank of abbrev->shortname->inputifnotparty_infothenifout_type=='color'thenreturnargs.errorordefault_colorelsereturnargs.errororpartyendendlocalreturn_value=party_info[out_type]ifreturn_value==""thenifout_type=='color'thenreturnargs.errororcreate_error("Value not in template. Please request that it be added.")elseifout_type=='abbrev'thenifparty_info.shortname~=""thenreturnparty_info.shortnameelsereturnpartyendelseifout_type=='shortname'thenifparty_info.abbrev~=""thenreturnparty_info.abbrevelsereturnpartyendelsereturnpartyendendifout_type=='color'andstring.find(return_value,'#')thenreturn_value=string.gsub(return_value,'#','#')endreturnreturn_valueendfunctionp.fetch(frame)-- Initialise and populate variableslocalgetArgs=require("Module:Arguments").getArgslocalargs=getArgs(frame)returnp._fetch(args)endreturnp