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 Lua module is used on
approximately 307,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.
Template | Module | ||||
---|---|---|---|---|---|
Code | Output | PEIS | Code | Output | PEIS |
{{
flag|CHN}} |
CHN | 443b | {{
#invoke:flag||CHN}} |
CHN | 128b |
{{
flagcountry|CHN}} |
China | 577b | {{
#invoke:flag|country|CHN}} |
China | 128b |
{{
flagdeco|CHN}} |
452b | {{
#invoke:flag|deco|CHN}} |
107b | ||
{{
flagicon|CHN}} |
548b | {{
#invoke:flag|icon|CHN}} |
117b | ||
{{
flag+link|History of|CHN}} |
China | 663b | {{
#invoke:flag|+link|History of|CHN}} |
China | 139b |
{{
flagathlete|
Andy Murray|GBR}} |
Andy Murray ( GBR) | 617b | {{
#invoke:flag|athlete|
Andy Murray|GBR}} |
Andy Murray ( GBR) | 210b |
{{
flagmedalist|
Andy Murray|GBR}} |
Andy Murray Great Britain |
469b | {{
#invoke:flag|medalist|
Andy Murray|GBR}} |
Andy Murray Great Britain |
129b |
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 categories = {
Flagicon = '[[Category:Flagicons with missing country data templates]]',
Flagdeco = '[[Category:Flagdeco with missing country data templates]]',
}
local yesno = require('Module:Yesno')
--Get input arguments
local args = require('Module:Arguments').getArgs(frame,{frameOnly = ((frame.args.frameonly or '') ~= ''), valueFunc =
function(key,value)
if value then
value = mw.text.trim(value)
--Change empty string to nil for all args except 'image' and 'border'
if key=="image" or key=="border" or value~="" then
return value
end
end
return nil
end
})
local preftext = ""
if name == 'Flag+link' then
args.pref = args1
elseif name == 'Flagathlete' then
args.preftext = args1
args2 = args.code or args2 or ""
args.variant = args.variant or args3
elseif name == 'Flagmedalist' then
preftext = (args1 or "") .. "<br/>"
args2 = args.code or args2 or ""
args.variant = args.variant or args3
else
args.variant = args.variant or args2
args2 = args1 or ""
end
args1 = mode .. (args.opts or '')
args.missingcategory = categoriesname
args.noredlink = args.noredlink or 'notext'
if args.placeholder and yesno(args.placeholder) ~= true then
args1 = args1 .. 'o'
end
if mw.title.getCurrentTitle().namespace == 0 then
local unknown = '[[Category:Pages using ' .. mw.ustring.lower(name) .. ' template with unknown parameters|_VALUE_' ..
frame:getParent():getTitle() .. ']]'
else
local unknown = ''
end
if check then
local opts = {
unknown=unknown,
preview='Page using [[Template:' .. name .. ']] with unknown parameter "_VALUE_"',
ignoreblank='y',
'1',
'2',
'variant',
'image',
'size',
'sz',
'border',
'align',
'al',
'width',
'w',
'alt',
'ilink',
'noredlink',
'missingcategory',
'name',
'clink',
'link',
'pref',
'suff',
'plink',
'the',
'section',
'altvar',
'avar',
'age',
'nalign',
'nal',
'text',
'nodata',
'opts',
'placeholder',
'getParent',
'frameonly'
}
check = require('Module:Check for unknown parameters')._check(opts,args)
else
check = ''
end
return preftext .. require('Module:Flagg').luaMain(frame,args) .. check
end
function p.main(frame) return p._main(frame, 'Flag', 'unc', false) end
p.flag = p.main
p'' = p.main
function p.deco(frame) return p._main(frame, 'Flagdeco', 'uxx', false) end
p.flagdeco = p.deco
function p.icon(frame) return p._main(frame, 'Flagicon', 'cxxl', true) end
p.flagicon = p.icon
function p.pluslink(frame) return p._main(frame, 'Flag+link', 'unpefo', false) end
p'+link' = p.pluslink
p'flag+link' = p.pluslink
function p.country(frame) return p._main(frame, 'Flagcountry', 'unce', false) end
p.flagcountry = p.country
function p.athlete(frame) return p._main(frame, 'Flagathlete', 'unape', false) end
p.flagathlete = p.athlete
function p.medalist(frame) return p._main(frame, 'Flagmedalist', 'unce', false) end
p.flagmedalist = p.medalist
return p
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 Lua module is used on
approximately 307,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.
Template | Module | ||||
---|---|---|---|---|---|
Code | Output | PEIS | Code | Output | PEIS |
{{
flag|CHN}} |
CHN | 443b | {{
#invoke:flag||CHN}} |
CHN | 128b |
{{
flagcountry|CHN}} |
China | 577b | {{
#invoke:flag|country|CHN}} |
China | 128b |
{{
flagdeco|CHN}} |
452b | {{
#invoke:flag|deco|CHN}} |
107b | ||
{{
flagicon|CHN}} |
548b | {{
#invoke:flag|icon|CHN}} |
117b | ||
{{
flag+link|History of|CHN}} |
China | 663b | {{
#invoke:flag|+link|History of|CHN}} |
China | 139b |
{{
flagathlete|
Andy Murray|GBR}} |
Andy Murray ( GBR) | 617b | {{
#invoke:flag|athlete|
Andy Murray|GBR}} |
Andy Murray ( GBR) | 210b |
{{
flagmedalist|
Andy Murray|GBR}} |
Andy Murray Great Britain |
469b | {{
#invoke:flag|medalist|
Andy Murray|GBR}} |
Andy Murray Great Britain |
129b |
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 categories = {
Flagicon = '[[Category:Flagicons with missing country data templates]]',
Flagdeco = '[[Category:Flagdeco with missing country data templates]]',
}
local yesno = require('Module:Yesno')
--Get input arguments
local args = require('Module:Arguments').getArgs(frame,{frameOnly = ((frame.args.frameonly or '') ~= ''), valueFunc =
function(key,value)
if value then
value = mw.text.trim(value)
--Change empty string to nil for all args except 'image' and 'border'
if key=="image" or key=="border" or value~="" then
return value
end
end
return nil
end
})
local preftext = ""
if name == 'Flag+link' then
args.pref = args1
elseif name == 'Flagathlete' then
args.preftext = args1
args2 = args.code or args2 or ""
args.variant = args.variant or args3
elseif name == 'Flagmedalist' then
preftext = (args1 or "") .. "<br/>"
args2 = args.code or args2 or ""
args.variant = args.variant or args3
else
args.variant = args.variant or args2
args2 = args1 or ""
end
args1 = mode .. (args.opts or '')
args.missingcategory = categoriesname
args.noredlink = args.noredlink or 'notext'
if args.placeholder and yesno(args.placeholder) ~= true then
args1 = args1 .. 'o'
end
if mw.title.getCurrentTitle().namespace == 0 then
local unknown = '[[Category:Pages using ' .. mw.ustring.lower(name) .. ' template with unknown parameters|_VALUE_' ..
frame:getParent():getTitle() .. ']]'
else
local unknown = ''
end
if check then
local opts = {
unknown=unknown,
preview='Page using [[Template:' .. name .. ']] with unknown parameter "_VALUE_"',
ignoreblank='y',
'1',
'2',
'variant',
'image',
'size',
'sz',
'border',
'align',
'al',
'width',
'w',
'alt',
'ilink',
'noredlink',
'missingcategory',
'name',
'clink',
'link',
'pref',
'suff',
'plink',
'the',
'section',
'altvar',
'avar',
'age',
'nalign',
'nal',
'text',
'nodata',
'opts',
'placeholder',
'getParent',
'frameonly'
}
check = require('Module:Check for unknown parameters')._check(opts,args)
else
check = ''
end
return preftext .. require('Module:Flagg').luaMain(frame,args) .. check
end
function p.main(frame) return p._main(frame, 'Flag', 'unc', false) end
p.flag = p.main
p'' = p.main
function p.deco(frame) return p._main(frame, 'Flagdeco', 'uxx', false) end
p.flagdeco = p.deco
function p.icon(frame) return p._main(frame, 'Flagicon', 'cxxl', true) end
p.flagicon = p.icon
function p.pluslink(frame) return p._main(frame, 'Flag+link', 'unpefo', false) end
p'+link' = p.pluslink
p'flag+link' = p.pluslink
function p.country(frame) return p._main(frame, 'Flagcountry', 'unce', false) end
p.flagcountry = p.country
function p.athlete(frame) return p._main(frame, 'Flagathlete', 'unape', false) end
p.flagathlete = p.athlete
function p.medalist(frame) return p._main(frame, 'Flagmedalist', 'unce', false) end
p.flagmedalist = p.medalist
return p