This Lua module is designed to calculate and return the sum of medal values (Gold, Silver, Bronze, or Total) from a specified class within a table on Wikipedia pages. It is particularly useful for automatically updating medal totals in infoboxes and tables.
Syntax:<nowiki>{{#invoke:Sandbox/Miria~01/sumMedals|calculateSum|targetClass|column|{{FULLPAGENAME}}}}</nowiki>
for information:
module name
Examples:
Calculate the total number of Gold medals for "summerMedals" class on the current page:<nowiki>{{#invoke:Sandbox/Miria~01/sumMedals|calculateSum|summerMedals|Gold|{{FULLPAGENAME}}}}</nowiki>
Calculate the total number of Silver medals for "winterMedals" class on a specific page:<nowiki>{{#invoke:Sandbox/Miria~01/sumMedals|calculateSum|winterMedals|Silver|{{FULLPAGENAME}}}}</nowiki>
Calculate the total medal counts for Gold, Silver, Bronze, and Total for "summerMedals" class and return it with four cells (for Gold, Silver, Bronze, and Total) in the last row of the table:<nowiki>{{#invoke:Sandbox/Miria~01/sumMedals|calculateSum|summerMedals|All|{{FULLPAGENAME}}}}</nowiki>
Instructions:
Infobox Usage:
1. To automatically update infoboxes with medal counts for e.g two targetCalss (like summerMedals or winterMedals), use the module in the infobox template as shown in this example:<nowiki>| gold = {{#expr: {{#invoke:Sandbox/Miria~01/sumMedals|calculateSum|summerMedals|Gold|{{FULLPAGENAME}}}} + {{#invoke:Sandbox/Miria~01/sumMedals|winterMedals|targetClass|Gold|{{FULLPAGENAME}}}}}}</nowiki>
<nowiki>| silver = {{#expr: {{#invoke:Sandbox/Miria~01/sumMedals|calculateSum|summerMedals|Silver|{{FULLPAGENAME}}}} + {{#invoke:Sandbox/Miria~01/sumMedals|winterMedals|targetClass|Gold|{{FULLPAGENAME}}}}}}</nowiki>
<nowiki>| bronze = {{#expr: {{#invoke:Sandbox/Miria~01/sumMedals|calculateSum|summerMedals|Bronze|{{FULLPAGENAME}}}} + {{#invoke:Sandbox/Miria~01/sumMedals|winterMedals|targetClass|Gold|{{FULLPAGENAME}}}}}}</nowiki>
Table Usage:
2. In your table, ensure that each line starts with the corresponding class attribute (`class="xxx"`) to specify whether it belongs to "summerMedals" or "winterMedalse as shown in this example:<nowiki>|-</nowiki>
<nowiki>|align=left class="summerMedals"| {{Flagicon|RUS}} {{GamesName|WOG|2014}} || [[Czech Republic at the 2014 Winter Olympics|88]] || 2 || 4 || 3 || '''9''' || [[2014 Winter Olympics medal table|15]]</nowiki>
Replace `xxx` with the appropriate class name.
Note:
If the target class is not found in the table, the module will return 0 for all medal types.