Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  





2 Examples  





3 Caveats  














Module:Flag






Afrikaans
Авар

Corsu
Cymraeg
فارسی
Hausa
ि
Kapampangan

Ikinyarwanda
Ladino
Magyar
ि
Монгол



ି
Oʻzbekcha / ўзбекча

پښتو
Tok Pisin

Simple English
سنڌي
کوردی
ி
Tiếng Vit
Winaray

 

Edit links
 









Module
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 





Permanently protected module

From Wikipedia, the free encyclopedia
 


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

Examples

Template Module
Code Output PEIS Code Output PEIS
{{flag|CHN}}  CHN 443b {{#invoke:flag||CHN}}  CHN 128b
{{flag country|CHN}}  China 577b {{#invoke:flag|country|CHN}}  China 128b
{{flag decoration|CHN}}/{{flag deco|CHN}} 452b {{#invoke:flag|decoration|CHN}}/{{#invoke:flag|deco|CHN}} 107b
{{flag icon|CHN}} China 548b {{#invoke:flag|icon|CHN}} China 117b
{{flag link|CHN|at the 2004 Summer Olympics}}  China 497b {{#invoke:flag|link|CHN|at the 2004 Summer Olympics}}  China 198b
{{flag+link|History of|CHN}}  China 663b {{#invoke:flag|+link|History of|CHN}}  China 139b
{{flag athlete|Andy Murray|GBR}}  Andy Murray (GBR) 617b {{#invoke:flag|athlete|Andy Murray|GBR}}  Andy Murray (GBR) 210b
{{flag medalist|Andy Murray|GBR}} Andy Murray
 Great Britain
469b {{#invoke:flag|medalist|Andy Murray|GBR}} Andy Murray
 Great Britain
129b
{{flag IOC athlete|Mark Spitz|USA|1972 Summer}}  Mark Spitz (USA) 346b {{#invoke:flag|IOC athlete|Mark Spitz|USA|1972 Summer}}  Mark Spitz (USA) 178b
{{fb|CHN}}  China 560b {{#invoke:flag|fb|CHN}}  China 151b
{{fb-rt|CHN}} China  482b {{#invoke:flag|fb-rt|CHN}} China  151b
{{fbicon|CHN}} China 444b {{#invoke:flag|fbicon|CHN}} China national football team 163b
{{ru|CHN}}  China 646b {{#invoke:flag|ru|CHN}}  China 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 categories = {
  ['Flag icon'] = '[[Category:Flag icons missing country data templates]]',
  ['Flag decoration'] = '[[Category:Flag decoration 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 = args[1]
 elseif name == 'Flag athlete' then
  args.preftext = args[1]
  args[2] = args.code or args[2] or ""
  args.variant = args.variant or args[3]
 elseif name == 'Flag medalist' then
  preftext = (args[1] or "") .. "<br/>"
  args[2] = args.code or args[2] or ""
  args.variant = args.variant or args[3]
 elseif name == 'Flag link' then
  args.suff = args[2]
  args[2] = args[1] or ""
  args.variant = args.variant or args[3]
 else
  sports = {fb = 'fb', ['fb-rt'] = 'fb', fbicon = 'fb', ru = 'ru'}
  if sports[name] then
   args.avar = sports[name]
   if name == 'fb' and yesno(args.align) == true then
    args.align='c'
   end
  end
  args.variant = args.variant or args[2]
  args[2] = args[1] or ""
 end

 args[1] = mode .. (args.opts or '')
 args.missingcategory = categories[name]
 args.noredlink = args.noredlink or 'notext'

 if args.placeholder and yesno(args.placeholder) ~= true then
  args[1] = args[1] .. '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.decoration(frame) return p._main(frame, 'Flag decoration', 'uxx',    false) end
p.deco = p.decoration
p.flagdeco = p.decoration
p['flag decoration'] = p.decoration
function p.icon(frame) return p._main(frame,       'Flag icon',       'cxxl',   true) end
p.flagicon = p.icon
p['flag icon'] = p.icon
function p.link(frame) return p._main(frame,       'Flag link',       'unpe',    false) end
p.flaglink = p.link
p['flag link'] = p.link
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,    'Flag country',    'unce',   false) end
p.flagcountry = p.country
p['flag country'] = p.country
function p.athlete(frame) return p._main(frame,    'Flag athlete',    'unape',  false) end
p.flagathlete = p.athlete
p['flag athlete'] = p.athlete
function p.medalist(frame) return p._main(frame,   'Flag medalist',   'unce',   false) end
p.flagmedalist = p.medalist
p['flag medalist'] = p.medalist
function p.fb(frame) return p._main(frame,         'fb',              'unpe',   false) end
function p.fbrt(frame) return p._main(frame,       'fb-rt',           'unpre',  false) end
p['fb-rt'] = p.fbrt
function p.fbicon(frame) return p._main(frame,     'fbicon',          'pxxl', false) end
function p.ru(frame) return p._main(frame,         'ru',              'unpe', false) end
function p.IOCathlete(frame) return require('Module:Country_alias').flagXYZ(frame:newChild{ title = 'Template:Flag IOC athlete', args = {type = 'athlete-O'} }) end
p.flagIOCathlete = p.IOCathlete
p['IOC athlete'] = p.IOCathlete
p['flag IOC athlete'] = p.IOCathlete
return p

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Flag&oldid=1232455041"

Categories: 
Modules in beta
Flag template system
Hidden category: 
Wikipedia template-protected modules
 



This page was last edited on 3 July 2024, at 20:32 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki