Module:Yesno: Difference between revisions

m Protected "Template:Yesno": Highly visible template ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only administrators] (indefinite))
 
m 1 revision imported: module for checking unknown params in template
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{<includeonly>safesubst:</includeonly>#switch: {{<includeonly>safesubst:</includeonly>lc: {{{1|¬}}} }}
-- Function allowing for consistent treatment of boolean-like wikitext input.
|no
-- It works similarly to the template {{yesno}}.
|n
 
|false
return function (val, default)
|0        = {{{no|<!-- null -->}}}
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
|        = {{{blank|{{{no|<!-- null -->}}}}}}
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
|¬        = {{{¬|}}}
-- following line.
|yes
val = type(val) == 'string' and val:lower() or val
|y
if val == nil then
|true
return nil
|1       = {{{yes|yes}}}
elseif val == true
|#default = {{{def|{{{yes|yes}}}}}}
or val == 'yes'
}}<noinclude>
or val == 'y'
{{Documentation}}
or val == 'true'
</noinclude>
or val == 't'
or val == 'on'
or tonumber(val) == 1
then
return true
elseif val == false
or val == 'no'
or val == 'n'
or val == 'false'
or val == 'f'
or val == 'off'
or tonumber(val) == 0
then
return false
else
return default
end
end