Module:SongCertifications
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
| This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module is used by the {{Infobox song}} template to format the |certification= parameter and assign categories based on the certification level of a song.
Usage
The module is invoked within the {{Infobox song}} template as follows:
{{#invoke:SongCertifications|getCertification|certification={{{certification|}}}}}
The module processes the |certification= parameter and formats the output while adding appropriate categories:
Gold(case-insensitive): DisplaysGold ●and adds [[Category:Gold Songs]].- A number from
1to9: DisplaysNx Platinum ▲(e.g.,3x Platinum ▲for3) and adds [[Category:Platinum Songs]]. - A number
10or higher: DisplaysNx Diamond ⬥(e.g.,24x Diamond ⬥for24) and adds [[Category:Diamond Songs]]. - Invalid inputs (e.g., non-numeric values other than
Gold, or numbers less than1): Displays the input as-is and adds [[Category:Songs with Invalid Certifications]].
Example
In an article using the {{Infobox song}} template:
{{Infobox song
| name = Example Song
| type = Major Hit Song
| artist = Example Artist
| album = Example Album
| released = January 1, 2020
| genre = Pop
| certification = 24
| rating = 4
}}
This will display the certification as 24x Diamond ⬥ and add the article to [[Category:Diamond Songs]].
Notes
- The module is case-insensitive for
Gold(e.g.,gold,GOLDare accepted). - Invalid inputs, such as
23x Diamond ⬥or non-numeric values other thanGold, are displayed as entered and categorized in [[Category:Songs with Invalid Certifications]] for manual review. - Ensure the categories ([[Category:Gold Songs]], [[Category:Platinum Songs]], [[Category:Diamond Songs]], [[Category:Songs with Invalid Certifications]]) exist on the wiki to avoid redlinks.
See also
- {{Infobox song}} – The template that uses this module.
- Module:SongCategories – Handles type-based categories for the same template.
local p = {}
function p.getCertification(frame)
local certInput = mw.text.trim(frame.args['certification'] or '')
local output = ''
local categories = {}
-- Check for "Gold" (case-insensitive)
if certInput:lower() == 'gold' then
output = '[[Gold]] ●'
table.insert(categories, '[[Category:Gold Songs]]')
-- Check if input is a number
elseif certInput:match('^%d+$') then
local num = tonumber(certInput)
if num >= 1 and num <= 9 then
output = num .. 'x [[Platinum]] ▲'
table.insert(categories, '[[Category:Platinum Songs]]')
elseif num >= 10 then
output = num .. 'x [[Diamond]] ⬥'
table.insert(categories, '[[Category:Diamond Songs]]')
else
-- Invalid number (e.g., 0 or negative)
output = certInput
table.insert(categories, '[[Category:Songs with Invalid Certifications]]')
end
else
-- Invalid input (not "Gold" or a number)
output = certInput
table.insert(categories, '[[Category:Songs with Invalid Certifications]]')
end
return output .. table.concat(categories, '')
end
return p