https://wiki.climatefresk.org/?title=Module:Yesno&feed=atom&action=historyModule:Yesno - Historique des versions2024-03-29T10:27:34ZHistorique des versions pour cette page sur le wikiMediaWiki 1.39.3https://wiki.climatefresk.org/index.php?title=Module:Yesno&diff=1626&oldid=prevArthirob : Création du module Yesno2020-10-02T06:37:03Z<p>Création du module Yesno</p>
<p><b>Nouvelle page</b></p><div>-- Function allowing for consistent treatment of boolean-like wikitext input.<br />
-- It works similarly to the template {{yesno}}.<br />
<br />
return function (val, default, emptyDefault)<br />
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you<br />
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the<br />
-- following line.<br />
if type(val) == 'string' then val = val:lower() end<br />
if val == nil then<br />
return nil<br />
elseif val == true <br />
or val == 'yes'<br />
or val == 'y'<br />
or val == 'oui'<br />
or val == 'o'<br />
or val == 'true'<br />
or tonumber(val) == 1<br />
then<br />
return true<br />
elseif val == false<br />
or val == 'no'<br />
or val == 'n'<br />
or val == 'non'<br />
or val == 'false'<br />
or tonumber(val) == 0<br />
then<br />
return false<br />
elseif emptyDefault ~= nil and type(val) == 'string' and val:match( '^%s*$' ) then<br />
return emptyDefault<br />
else<br />
return default<br />
end<br />
end</div>Arthirob