Module talk:Political party/uses

Latest comment: 2 years ago by Gonnym in topic Possible uses

This lists current uses of /shortname, /color, and /abbrev templates.

Current uses

edit

/meta/color:

Modules

edit
Module shortname color abbrev Lines Code
Module:Election results Yes In all places the same code is done:
  • mw.title.new('Template:' .. alliance .. '/meta/color').exists then color = frame:expandTemplate{title = alliance .. '/meta/color'}
  • This would be changed to require("Module:Political party")._fetch({alliance, "color"})
  • With "alliance" being the party.
{{Officeholder table}} Yes Yes Yes Some usages use fallback, other should, but don't. There are many usages but code is just duplicated over and over again. Extracts of code should be split into sub-templates and used. This would reduce the amount of times needed to fix each usage. Abbr is used here because |alt_officeholder_party= only uses a letter here in parenthesis. I'm not sure how reader-friendly that is tbh.

Infoboxes and templates (completed)

edit

Templates listed below have been converted to use the module. They are listed here for future maintenance purposes, as it has been mentioned that a number of these templates could likely be consolidated due to duplicate code.

Template shortname color abbrev Via Current code New code Notes
{{Compact election box}} Yes
  • [[{{{winner_party|}}}|{{Template:{{{winner_party|}}}/meta/shortname}}]]
  • [[{{{loser_party|}}}|{{Template:{{{loser_party|}}}/meta/shortname}}]]
  • [[{{{winner_party|}}}|{{#invoke:Political party|fetch|{{{winner_party|}}}|shortname}}]]
  • [[{{{loser_party|}}}|{{#invoke:Political party|fetch|{{{loser_party|}}}|shortname}}]]
Yes style="background-color: {{Template:{{{winner_party|}}}/meta/color}}" style="background-color: {{#invoke:Political party|fetch|{{{winner_party|}}}|color}}" This produces (in both old and new) a blank background-color attribute if nothing is found.
Yes [[{{{swing_from|}}}|{{#ifexist: Template:{{{swing_from|}}}/meta/abbrev | {{Template:{{{swing_from|}}}/meta/abbrev}} | {{Template:{{{swing_from|}}}/meta/shortname}} }}]] to [[{{{swing_to|}}}|{{#ifexist: Template:{{{swing_to|}}}/meta/abbrev | {{Template:{{{swing_to|}}}/meta/abbrev}} | {{Template:{{{swing_to|}}}/meta/shortname}} }}]] [[{{{swing_from|}}}|{{#invoke:Political party|fetch|{{{swing_from|}}}|abbrev}}]] Uses fallback: abbr->shortname without full name. Current (/meta) code breaks as it has no fallback to input (full name).
{{Compact election box no change}} Same as above
{{Election box candidate for alliance}} Yes [[{{{party}}}|{{Template:{{{party}}}/meta/shortname}}]] ([[{{{side}}}|{{Template:{{{side}}}/meta/shortname}}]] [[{{{party}}}|{{#invoke:Political party|fetch|{{{party}}}|shortname}}]] ([[{{{side}}}|{{#invoke:Political party|fetch|{{{side}}}|shortname}}]] New code provides name fallback.
Yes style="background-color: {{Template:{{{party}}}/meta/color}}" style="background-color: {{#invoke:Political party|fetch|{{{party}}}|color}}" No fallback for color.
{{Election box candidate no party link no change}} Yes {{Template:{{{party}}}/meta/shortname}} {{#invoke:Political party|fetch|{{{party}}}|shortname}} New code provides name fallback.
Yes style="background-color: {{Template:{{{party}}}/meta/color}};" style="background-color: {{#invoke:Political party|fetch|{{{party}}}|color}}; No fallback for color.
{{Election box candidate with party link}} Yes Yes Similar to above.
{{Election box gain no swing}} Yes Yes Same as above.
{{Election box gain with party link}} Yes Yes Similar to above.
{{Election box gain with party link without swing}} Yes Yes Exact same code as {{Election box gain with party link no swing}} - templates should be "merged" to a renamed template.
{{Election box gain with party link and swing no change}} Yes Yes Similar to other code. Checks if exist a template, then uses it or fallbacks on input color and input name.
{{Election box hold with party link}} Yes Yes Similar to other code. Uses color and name from /meta/ templates but does not have a fallback so breaks.
{{Election box hold with party link no change}} Yes Yes Identical to {{Election box hold with party link no swing}} and should be merged. Almost identical to Template:Election box gain no swing and {{Election box new seat win}}. Could be easily merged with only checking some type parameter.
{{Election box hold with party link no swing}} Yes Yes Identical to {{Election box hold with party link no change}} and should be merged. See above.
{{Election box new boundary win}} Yes Yes
{{Election summary party}} Yes Yes
{{Election winner list with party link}} Yes Yes
{{Political party list}} Yes Yes
{{Election box gain}} Yes {{#ifexist:Template:{{{winner}}}/meta/shortname|{{{{{winner}}}/meta/shortname}}|{{{winner}}}}} '''gain''' from {{#ifexist:Template:{{{loser}}}/meta/shortname|{{{{{loser}}}/meta/shortname}}|{{{loser}}}}} {{#invoke:Political party|fetch|{{{winner}}}|shortname}} '''gain''' from {{#invoke:Political party|fetch|{{{loser}}}|shortname}} Fallback makes code shorter.
Yes {{#ifexist:Template:{{{winner}}}/meta/color|background-color: {{{{{winner}}}/meta/color}}}} {{#if: {{#invoke:Political party|fetch|{{{winner}}}|color}} | background-color: {{#invoke:Political party|fetch|{{{winner}}}|color}} }} Could maybe provide a default value to reduce the second call.
{{Election box gain with party link no swing}} Yes Yes Similar to above. New code provides fall back. Exact same code as below - templates should be "merged" to a renamed template.
{{Election box gain with party link no change}} Yes Yes Exact same code as {{Election box gain with party link no swing}} - templates should be "merged" to a renamed template.
{{Election box new seat win}} Yes Yes Almost identical to Template:Election box gain no swing and {{Election box hold with party link no swing}}. Could be easily merged with only checking some type parameter.
{{Elected official with party link}} Yes Yes Uses abbr without fallback. No real reason to use abbr here.
{{Officeholder table coalition}} Yes No fallback. Again code is duplicated. Abbr is used because letters are used in the coalition cell. Again, not sure how reader-friendly this is especially if the letters are an en.wiki made up thing.
{{Officeholder table cabinet}} Yes Yes No fallback. Again code is duplicated. Abbr is used because letters are used in the cabinet cell.
{{UKPP}} Yes Yes
{{Infobox election}} Yes via {{Infobox election/shortname}} {{#switch:{{{name|}}} |Other|other|={{{name|}}} |#default= {{#ifeq:{{{link}}}|no |{{{name}}} |{{#ifexist:Template:{{{name}}}/meta/shortname |[[{{{name}}}|{{Template: {{{name}}}/meta/shortname}}]] |{{{name}}} }} }} }} {{#invoke:Political party|fetch|{{{name|}}}|shortname}} Return the name given if no value
Yes {{Infobox election/row}} {{#if: {{{color1|}}} | border-bottom: 6px solid #{{{color1}}} | {{#ifeq: {{{party_color}}} | no | | {{#if: {{{party1|}}} | {{#ifexist:Template:{{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party1}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}/meta/color | border-bottom: 6px solid {{Template:{{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party1}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}/meta/color}} }} }} }} }}" {{#if: {{{color1|}}} | border-bottom: 6px solid #{{{color1}}} | {{#ifeq: {{{party_color}}} | no | | {{#if: {{{party1|}}} | {{#if: {{#invoke:Political party|fetch|{{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party1}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}|color}} | border-bottom: 6px solid {{#invoke:Political party|fetch|{{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party1}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}|color}}; }} }} }} }}" No default value used.
{{Infobox legislative election}} Yes {{Infobox election/shortname}} See above See above
Yes via {{Infobox legislative election/row}} {{#if: {{{colour|}}} | border-left: 4px solid {{{colour}}}; | {{#ifexist:Template:{{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}/meta/color | border-left: 4px solid {{ {{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}/meta/color}}; }} }} {{#if: {{{colour|}}} | border-left: 4px solid {{{colour}}}; | {{#if {{#invoke:Political party|fetch|{{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}|color}} | border-left: 4px solid {{#invoke:Political party|fetch{{#invoke:delink|delink|wikilinks=target|1={{#invoke:string|replace|source={{{party}}}|pattern=^(%[%[%s*[^%]%[]*%]%]).*$|replace=%1|plain=false}}}}|color}}; }} }} No default value used.


Possible uses

edit

Templates where it could be added

Infobox/template Suggested addition Notes
{{Infobox political party}} color Currently colorcode has to be entered manually. Could automatically look up a colorcode that matches the article title and override that with a manually entered one.

I've played around with this at Template:Infobox political party/sandbox with adding fallbacks (and moving the native_name subheader to an actual |subheader=) and it works. Might be cleaner ways. --Gonnym (talk) 13:38, 29 November 2021 (UTC)Reply

Documentation templates that would probably be deleted

edit