Module:Flag
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | 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 approximately 325,000 pages, or roughly 1% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Lua-native alternative to popular flag templates. Can be used to reduce post-expand include size of pages with lots of templates, since it avoids calling multilevel templates.
Usage
Generic flag templates
- {{flag}} → {{#invoke:flag|}}
- {{flag country}} → {{#invoke:flag|country}}
- {{flag decoration}} (or {{flagdeco}}) → {{#invoke:flag|decoration}} (or {{#invoke:flag|deco}})
- {{flag icon}} → {{#invoke:flag|icon}}
- {{flag link}} → {{#invoke:flag|link}}
- {{flag+link}} → {{#invoke:flag|+link}}
Sports flag templates
- {{flag athlete}} → {{#invoke:flag|athlete}}
- {{flag medalist}} → {{#invoke:flag|medalist}}
- {{flag team}} → {{#invoke:flag|team}}
- {{flag IOC}} → {{#invoke:flag|IOC}}
- {{flag IOC 2}} → {{#invoke:flag|IOC 2}}
- {{flag IOC athlete}} → {{#invoke:flag|IOC athlete}}
- {{fb}} → {{#invoke:flag|fb}}
- {{fba}} → {{#invoke:flag|fba}}
- {{fb-rt}} → {{#invoke:flag|fb-rt}}
- {{fbicon}} → {{#invoke:flag|fbicon}}
- {{fbaicon}} → {{#invoke:flag|fbaicon}}
- {{ru}} → {{#invoke:flag|ru}}
Examples
Template | Module | ||||
---|---|---|---|---|---|
Code | Output | PEIS | Code | Output | PEIS |
{{flag|CHN}} |
![]() |
443b | {{#invoke:flag||CHN}} |
Script error: The function "" does not exist. | 128b |
{{flag country|CHN}} |
![]() |
577b | {{#invoke:flag|country|CHN}} |
Script error: The function "country" does not exist. | 128b |
{{flag decoration|CHN}} /{{flag deco|CHN}} |
![]() |
452b | {{#invoke:flag|decoration|CHN}} /{{#invoke:flag|deco|CHN}} |
![]() |
107b |
{{flag icon|CHN}} |
![]() |
548b | {{#invoke:flag|icon|CHN}} |
![]() |
117b |
{{flag link|CHN|at the 2004 Summer Olympics}} |
![]() |
497b | {{#invoke:flag|link|CHN|at the 2004 Summer Olympics}} |
Script error: The function "link" does not exist. | 198b |
{{flag+link|History of|CHN}} |
![]() |
663b | {{#invoke:flag|+link|History of|CHN}} |
Script error: The function "+link" does not exist. | 139b |
{{flag team|GBR}} |
![]() |
804b | {{#invoke:flag|team|GBR}} |
Script error: The function "team" does not exist. | 193b |
{{flag athlete|Andy Murray|GBR}} |
![]() |
617b | {{#invoke:flag|athlete|Andy Murray|GBR}} |
Script error: The function "athlete" does not exist. | 210b |
{{flag medalist|Andy Murray|GBR}} |
Andy Murray![]() |
469b | {{#invoke:flag|medalist|Andy Murray|GBR}} |
Script error: The function "medalist" does not exist. | 129b |
{{flag IOC|CAN|1924 Winter|1}} |
![]() |
326b | {{#invoke:flag|IOC|CAN|1924 Winter|1}} |
Script error: The function "IOC" does not exist. | 163b |
{{flag IOC 2|HKG|1954 Asian Games|1}} |
![]() |
368b | {{#invoke:flag|IOC 2|HKG|1954 Asian Games|1}} |
Script error: The function "IOC 2" does not exist. | 184b |
{{flag IOC athlete|Mark Spitz|USA|1972 Summer}} |
![]() |
346b | {{#invoke:flag|IOC athlete|Mark Spitz|USA|1972 Summer}} |
Script error: The function "IOC athlete" does not exist. | 178b |
{{fb|CHN}} |
![]() |
560b | {{#invoke:flag|fb|CHN}} |
Script error: The function "fb" does not exist. | 151b |
{{fb-rt|CHN}} |
China ![]() |
482b | {{#invoke:flag|fb-rt|CHN}} |
Script error: The function "fb-rt" does not exist. | 151b |
{{fbicon|CHN}} |
![]() |
444b | {{#invoke:flag|fbicon|CHN}} |
Script error: The function "fbicon" does not exist. | 163b |
{{fba|CHN}} |
![]() |
625b | {{#invoke:flag|fba|CHN}} |
Script error: The function "fba" does not exist. | 149b |
{{fbaicon|CHN}} |
![]() |
500b | {{#invoke:flag|fbaicon|CHN}} |
Script error: The function "fbaicon" does not exist. | 159b |
{{ru|CHN}} |
![]() |
646b | {{#invoke:flag|ru|CHN}} |
Script error: The function "ru" does not exist. | 210b |
Caveats
When used inside a template, parameters from that template are passed to the module. This can be useful in some situations, but can lead to conflicts (for example, if the parent template has a parameter |country=
that is unrelated to the flag it is supposed to display). To prevent this behavior, add the |frameonly=
parameter to the module call, e.g. {{#invoke:flag|deco|CHN|frameonly=true}}
.
local p = {}
function p._main(frame, name, mode, check)
local args={}
for k,v in pairs(frame:getParent().args) do
if (v or '') ~= '' then
args[k] = v
end
end
for k,v in pairs(frame.args) do
if (v or '') ~= '' then
args[k] = v
end
end
if check then
local opts = {
unknown=frame:expandTemplate{ title = 'main other', args = { '[[Category:Pages using ' .. mw.ustring.lower(name) .. ' template with unknown parameters|_VALUE_' .. frame:getParent():getTitle() .. ']]' } },
preview='Page using [[Template:' .. name .. ']] with unknown parameter "_VALUE_"',
ignoreblank='y',
[1] = '1',
[2] = '2',
[3] = 'variant',
[4] = 'image',
[5] = 'size',
[6] = 'sz',
[7] = 'border',
[8] = 'align',
[9] = 'al',
[10]= 'width',
[11]= 'w',
[12]= 'alt',
[13]= 'ilink',
[14]= 'noredlink',
[15]= 'missingcategory',
[16]= 'name',
[17]= 'clink',
[18]= 'link',
[19]= 'pref',
[20]= 'suff',
[21]= 'plink',
[22]= 'the',
[23]= 'section',
[24]= 'altvar',
[25]= 'avar',
[26]= 'age',
[27]= 'nalign',
[28]= 'nal',
[29]= 'text',
[30]= 'nodata',
[31]= 'opts'
}
check = require('Module:Check for unknown parameters')._check(opts,args)
else
check = ''
end
args['variant'] = args[2] or args['variant']
args[2] = args[1]
args[1] = mode .. (args['opts'] and args['opts'] or '')
args['missingcategory'] = '[[Category:' .. name .. 'with missing country data templates]]'
args['noredlink'] = args['noredlink'] or 'no'
if require('Module:Yesno')(args['placeholder']) ~= true then
args[1] = args[1] .. 'o'
end
return require('Module:Flagg').luaMain(frame,args)..check
end
function p.main(frame) return p._main(frame, 'Flag', 'uncb', false) end
function p.deco(frame) return p._main(frame, 'Flagdeco', 'uxx', false) end
function p.icon(frame) return p._main(frame, 'Flagicon', 'cxxl', true ) end
return p