Loading AI tools
From Wikipedia, the free encyclopedia
Module:Yesno is permanently protected from editing because it is a heavily used or highly visible module. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit protected}} to notify an administrator to make the requested edit.
|
Text and/or other creative content from this version of Module:Yesno was copied or moved into incubator:Module:Wp/nod/Yesno with this edit. The former page's history now serves to provide attribution for that content in the latter page, and it must not be deleted as long as the latter page exists. |
{| class="wikitable" |+ Test Cases (via [[Template:Yesno/doc]]) |- ! Module output ! Template output ! Expected |- | {{#invoke:Yesno|yesno|yes}} | {{yesno|yes}} | yes |- | {{#invoke:Yesno|yesno|YeS}} | {{yesno|YeS}} | yes |- | {{#invoke:Yesno|yesno|Y}} | {{yesno|Y}} | yes |- | {{#invoke:Yesno|yesno|y}} | {{yesno|y}} | yes |- | {{#invoke:Yesno|yesno|no}} | {{yesno|no}} | ''(blank)'' |- | {{#invoke:Yesno|yesno|}} | {{yesno|}} | ''(blank)'' |- | {{#invoke:Yesno|yesno}} | {{yesno}} | ''(blank)'' |- | {{#invoke:Yesno|yesno|¬}} | {{yesno|¬}} | ''(blank)'' |- | {{#invoke:Yesno|yesno|purplemonkeydishwasher}} | {{yesno|purplemonkeydishwasher}} | yes |- | {{#invoke:Yesno|yesno|yes|yes=bacon}} | {{yesno|yes|yes=bacon}} | bacon |- | {{#invoke:Yesno|yesno|no|no=ham}} | {{yesno|no|no=ham}} | ham |- | {{#invoke:Yesno|yesno|blank= eggs}} | {{yesno|blank= eggs}} | |- | {{#invoke:Yesno|yesno|no=ham}} | {{yesno|no=ham}} | |- | {{#invoke:Yesno|yesno|blank= eggs|no=ham}} | {{yesno|blank= eggs|no=ham}} | |- | {{#invoke:Yesno|yesno|¬|¬=sausage}} | {{yesno|¬|¬=sausage}} | sausage |- | {{#invoke:Yesno|yesno|purplemonkeydishwasher|def=cup-of-tea}} | {{yesno|purplemonkeydishwasher|def=cup-of-tea}} | cup-of-tea |- | {{#invoke:Yesno|yesno|purplemonkeydishwasher|yes=bacon}} | {{yesno|purplemonkeydishwasher|yes=bacon}} | bacon |- | {{#invoke:Yesno|yesno|purplemonkeydishwasher|def=cup-of-tea|yes=bacon}} | {{yesno|purplemonkeydishwasher|def=cup-of-tea|yes=bacon}} | cup-of-tea |- | {{#invoke:Yesno|yesno|yes|yes=no|no=yes}} | {{yesno|yes|yes=no|no=yes}} | no |- | {{#invoke:Yesno|yesno|no|yes=no|no=yes}} | {{yesno|no|yes=no|no=yes}} | yes |- | {{#invoke:Yesno|yesno| no |no=no}} | {{yesno| no |no=no}} | no |}
As you can see, the template does not behave exactly as its documentation claims it does. I was not sure which to regard as authoritative: the ideal or actual implementation. I ultimately went with the former. Removing and not any
from the Lua code will make the module behave like exactly like the template.
--Ori.livneh (talk) 10:46, 28 February 2013 (UTC)
The documentation is wrong. The "egg" example assumes thet the input value is blank. But in the code examples the input parameter is omitted. Compare:
This is what is actually documented:
{{yesno}} is quite simple, so I'm not sure if there is a point in replacing it with functionally equivalent Lua. There are many cases where Lua can be much faster and easier to read, but I'm not sure that is the case here. In fact, because of the slight overhead with #invoke, simple parser functions can actually be slightly faster than the equivalent Lua. I haven't tested that here, but I wouldn't be surprised if there is no performance advantage in a case like this. Seems like a strange template to target for Lua conversion. Dragons flight (talk) 14:57, 12 March 2013 (UTC)
It’s just for compatibility. For some weird reason, yesno might not work and this will.
E Super Maker (😲 shout) 15:47, 23 November 2019 (UTC)
One fail found in unit test: value "1= ¬ " (with whitespace). Reason:whitespace not removed before this check. Possible solution; treat '¬' as a character, separate from nil. (if val == nil or val == '¬' then ...). -DePiep (talk) 11:54, 23 March 2013 (UTC)
val = args[1]
into val = tostring(args[1])
. To prevent treating "000" as number. -DePiep (talk) 14:09, 23 March 2013 (UTC)Solved. Module is changed, although the numeric issue different from my (incorrect) suggestion. -DePiep (talk) 14:19, 23 March 2013 (UTC)
The code now says <nowiki>no = "<!-- null -->"</nowiki>
. But a "" (nullstring) is not the same as ASCII NULL (0x0000). Also I see no use for adding wiki comment to code this way. -DePiep (talk) 17:47, 23 March 2013 (UTC)
I've rewritten this as a pure Lua function. The new version is a lot simpler, and is also designed to work with Lua data types such as booleans, tables, and functions. Dragons flight's criticism above is well-founded, and giving up on the idea of replacing {{yesno}} seemed like the best answer. The new version should hopefully retain the basics of {{yesno}} while playing well with Lua, and allow meta-modules that deal with boolean-style wikitext input to be consistent with each other. (In other words, users won't have to remember whether it was "category=yes" or "category=true" - it should Just WorkTM.) — Mr. Stradivarius ♪ talk ♪ 14:37, 20 September 2013 (UTC)
is there some issue with the module, all tests on the Module talk:Yesno/testcases has failed. --Jarekt (talk) 16:37, 20 December 2013 (UTC)
This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
the information is deceptive
please delete 2600:1013:B018:986F:4493:7A2A:52E2:103A (talk) 04:21, 24 February 2014 (UTC)
I've put a new version of this module in the sandbox. The new version uses the native Lua string.lower function instead of the Scribunto mw.ustring.lower function. According to my tests it is about 25x faster this way. Would anyone object to me updating the module? — Mr. Stradivarius ♪ talk ♪ 15:22, 7 April 2014 (UTC)
''
value (blank string). It says:yesno('')
returns nil". (I did not test any). -DePiep (talk) 09:06, 8 April 2014 (UTC)and
and or
operators. For example, the following code will return true:if '' then
return true
else
return false
end
I have seen some applications use T as an option for true as well. It might, therefore, be useful to have the letter T (t) represent a true value as well. CRwikiCA talk 15:15, 14 April 2015 (UTC)
This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
I request a change to the module to recognize T or t and F or f as true and false entries. This would make the full code the following:
-- Function allowing for consistent treatment of boolean-like wikitext input.
-- It works similarly to the template {{yesno}}.
return function (val, default)
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
-- following line.
val = type(val) == 'string' and val:lower() or val
if val == nil then
return nil
elseif val == true
or val == 'yes'
or val == 'y'
or val == 'true'
or val == 't'
or tonumber(val) == 1
then
return true
elseif val == false
or val == 'no'
or val == 'n'
or val == 'false'
or val == 'f'
or tonumber(val) == 0
then
return false
else
return default
end
end
Where lines 15 and 23 are new compared to the current code. CRwikiCA talk 18:17, 23 April 2015 (UTC)
This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Please add support for on and off values (as equivalents of 1 and 0, respectively), for consistency with the regular-template version {{Yesno}}
, per RfC at Template talk:Yesno#Support on/off detection. — SMcCandlish ☏ ¢ 😼 23:44, 22 February 2018 (UTC)
I believe we should make this template editor protected (I've seen templates with way less of the amount of transclusions than this one being template protected). Just a suggestion before I would put it up in the list. KylieInTheSkylie (talk) 02:23, 6 April 2020 (UTC)
What about a multilingual version? Would there be any conflicts? Trigenibinion (talk) 17:21, 12 March 2021 (UTC)
I want to "propose" to add an option (feature) that makes the module return T/F
only, never nil
. For example, it could have para |whennil=<True or False>
.
The background is that there are many situations (I meet in programming Lua) where a 'nil' return value is not helpful and still has to be handled separately into binary logic.
But even better, maybe I can learn why this was not added from the start, or why it could be considered bad design/coding. Maybe it could be solved by creating a wrapper like "Module:YesnoNevernil", or is that bad design again? -DePiep (talk) 04:56, 23 December 2021 (UTC)
myvariable = yesno(value) or false
-- WOSlinker (talk) 20:09, 23 December 2021 (UTC)
myvariable = yesno(value, false)
), although this does leave the case yesno(nil, false)
, which evaluates to nil
. The reason I originally programmed the module this way is so that it can be mostly backwards-compatible with Template:Yesno, which it is intended to replace. Originally the plan was to do a straight conversion of Template:Yesno to Lua, but it turned out that doing that was actually slower than just using the template, given the template's simplicity and the initial cost of switching between PHP and Lua. So instead this module became Lua-only, with most of the behaviour of Template:Yesno. The intention there was that module writers could easily incorporate it into modules that convert more complex templates without having to change the template logic too much. — Mr. Stradivarius ♪ talk ♪ 22:11, 23 December 2021 (UTC)
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.