Module talk:Political party/uses

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

Current uses

/meta/color:

  • [https://en.wikipedia.org/w/index.php?search=insource%3A%2F%5C%2Fmeta%5C%2Fcolor%2F&title=Special:Search&profile=advanced&fulltext=1&ns10=1 Template space]
  • [https://en.wikipedia.org/w/index.php?search=insource%3A%2F%5C%2Fmeta%5C%2Fcolor%2F&title=Special:Search&profile=advanced&fulltext=1&ns0=1 Article space]

=Modules=

class=wikitable

! scope="col" | Module

! scope="col" | shortname

! scope="col" | color

! scope="col" | abbrev

! scope="col" | Lines

! scope="col" | Code

Module:Election results{{yes}}* L-518-519

| 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.
{{tl|Officeholder table}}

| {{yes}}

| {{yes}}

| {{yes}}

| {{CEmpty}}

| colspan="3" | 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 {{para|alt_officeholder_party}} only uses a letter here in parenthesis. I'm not sure how reader-friendly that is tbh.

Infoboxes and templates (completed)

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.

class="wikitable mw-collapsible mw-collapsed sortable"

! scope="col" | Template

! scope="col" | shortname

! scope="col" | color

! scope="col" | abbrev

! scope="col" | Via

! scope="col" | Current code

! scope="col" | New code

! scope="col" | Notes

rowspan="3" | {{tl|Compact election box}}

| {{yes}}

| {{CEmpty}}

| {{CEmpty}}

| rowspan="3" {{CEmpty}}

|

}}
  • {{{loser_party
  • |

    | {{CEmpty}}

    |-

    | {{CEmpty}}

    | {{yes}}

    | {{CEmpty}}

    | 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.

    |-

    | {{CEmpty}}

    | {{CEmpty}}

    | {{yes}}

    | {{{swing_from to {{{swing_to

    | {{{swing_from

    | Uses fallback: abbr->shortname without full name. Current (/meta) code breaks as it has no fallback to input (full name).

    |-

    | {{tl|Compact election box no change}}

    | colspan="7" | Same as above

    |-

    | rowspan="2" | {{tl|Election box candidate for alliance}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | rowspan="2" {{CEmpty}}

    | {{Template:{{{party}}}/meta/shortname}} ({{Template:{{{side}}}/meta/shortname}}

    | {{{party}}} ({{{side}}}

    | New code provides name fallback.

    |-

    | {{CEmpty}}

    | {{yes}}

    | {{CEmpty}}

    | style="background-color: {{Template:{{{party}}}/meta/color}}"

    | style="background-color: {{#invoke:Political party|fetch|{{{party}}}|color}}"

    | No fallback for color.

    |-

    | rowspan="2" | {{tl|Election box candidate no party link no change}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | rowspan="2" {{CEmpty}}

    | {{Template:{{{party}}}/meta/shortname}}

    | {{#invoke:Political party|fetch|{{{party}}}|shortname}}

    | New code provides name fallback.

    |-

    | {{CEmpty}}

    | {{yes}}

    | {{CEmpty}}

    | style="background-color: {{Template:{{{party}}}/meta/color}};"

    | style="background-color: {{#invoke:Political party|fetch|{{{party}}}|color}};

    | No fallback for color.

    |-

    | {{tl|Election box candidate with party link}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Similar to above.

    |-

    | {{tl|Election box gain no swing}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Same as above.

    |-

    | {{tl|Election box gain with party link}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Similar to above.

    |-

    | {{tl|Election box gain with party link without swing}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Exact same code as {{tl|Election box gain with party link no swing}} - templates should be "merged" to a renamed template.

    |-

    | {{tl|Election box gain with party link and swing no change}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Similar to other code. Checks if exist a template, then uses it or fallbacks on input color and input name.

    |-

    | {{tl|Election box hold with party link}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Similar to other code. Uses color and name from /meta/ templates but does not have a fallback so breaks.

    |-

    | {{tl|Election box hold with party link no change}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Identical to {{tl|Election box hold with party link no swing}} and should be merged. Almost identical to Template:Election box gain no swing and {{tl|Election box new seat win}}. Could be easily merged with only checking some type parameter.

    |-

    | {{tl|Election box hold with party link no swing}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Identical to {{tl|Election box hold with party link no change}} and should be merged. See above.

    |-

    |{{tl|Election box new boundary win}}||{{yes}}||{{yes}}|| ||

    |-

    |{{tl|Election summary party}}||{{yes}}||{{yes}}|| ||

    |-

    |{{tl|Election winner list with party link}}||{{yes}}||{{yes}}|| ||

    |-

    |{{tl|Political party list}}||{{yes}}||{{yes}}|| ||

    |-

    | rowspan="2" | {{tl|Election box gain}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | rowspan="2" {{CEmpty}}

    | {{#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.

    |-

    | {{CEmpty}}

    | {{yes}}

    | {{CEmpty}}

    | {{#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.

    |-

    | {{tl|Election box gain with party link no swing}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Similar to above. New code provides fall back. Exact same code as below - templates should be "merged" to a renamed template.

    |-

    | {{tl|Election box gain with party link no change}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Exact same code as {{tl|Election box gain with party link no swing}} - templates should be "merged" to a renamed template.

    |-

    | {{tl|Election box new seat win}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | {{CEmpty}}

    | colspan="3" | Almost identical to Template:Election box gain no swing and {{tl|Election box hold with party link no swing}}. Could be easily merged with only checking some type parameter.

    |-

    | {{tl|Elected official with party link}}

    | {{CEmpty}}

    | {{yes}}

    | {{yes}}

    | {{CEmpty}}

    | colspan="3" | Uses abbr without fallback. No real reason to use abbr here.

    |-

    | {{tl|Officeholder table coalition}}

    | {{CEmpty}}

    | {{CEmpty}}

    | {{Yes}}

    | {{CEmpty}}

    | colspan="3" | 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.

    |-

    | {{tl|Officeholder table cabinet}}

    | {{yes}}

    | {{CEmpty}}

    | {{yes}}

    | {{CEmpty}}

    | colspan="3" | No fallback. Again code is duplicated. Abbr is used because letters are used in the cabinet cell.

    |-

    |{{tl|UKPP}}||{{yes}}||{{yes}}|| ||

    |-

    | rowspan="2" | {{tl|Infobox election}}

    | {{yes}}

    | {{CEmpty}}

    | rowspan="2" {{CEmpty}}

    | via {{tl|Infobox election/shortname}}

    | {{#switch:{{{name|}}}

    |Other|other|={{{name|}}}

    |#default=

    {{#ifeq:{{{link}}}|no

    |{{{name}}}

    |{{#ifexist:Template:{{{name}}}/meta/shortname

    |{{Template: {{{name}}}/meta/shortname}}

    |{{{name}}}

    }}

    }}

    }}

    | {{#invoke:Political party|fetch|{{{name|}}}|shortname}}

    | Return the name given if no value

    |-

    | {{CEmpty}}

    | {{Yes}}

    | {{tl|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.

    |-

    | rowspan="2" | {{tl|Infobox legislative election}}

    | {{yes}}

    | {{CEmpty}}

    | rowspan="2" {{CEmpty}}

    | {{tl|Infobox election/shortname}}

    | See above

    | See above

    | {{CEmpty}}

    |-

    | {{CEmpty}}

    | {{yes}}

    | via {{tl|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

    Templates where it could be added

    class=wikitable

    !Infobox/template

    !Suggested addition

    !Notes

    {{tl|Infobox political party}}colorCurrently 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 {{para|subheader}}) and it works. Might be cleaner ways. --Gonnym (talk) 13:38, 29 November 2021 (UTC)

    Documentation templates that would probably be deleted