Content deleted Content added
→Null?: new section |
m Reverted edits by 205.207.203.15 (talk) (HG) (3.4.13) |
||
(85 intermediate revisions by 52 users not shown) | |||
Line 1:
{{permprot}}
{{copied|from=Module:Yesno|from_oldid=828075573|to=:incubator:Module:Wp/nod/Yesno|to_diff=4237022}}
==Testcases and documentation==
<pre>
{| class="wikitable"
|+ Test Cases (via [[Template:Yesno/doc]])
Line 53 ⟶ 56:
| {{#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}}
Line 91 ⟶ 94:
| no
|}
</pre>
:<small>Note: Pre tags added to suppress script errors. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 14:25, 20 September 2013 (UTC)</small>
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 <code>and not any</code> from the Lua code will make the module behave like exactly like the template.
Line 100 ⟶ 105:
:::Yesno has ~8M transclusions. No question it should handle the legacy 1:1. Test it. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 22:31, 11 March 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:
* <nowiki>{{yesno|blank= eggs|no=ham}}</nowiki>
* <nowiki>{{yesno||blank= eggs|no=ham}}</nowiki>
This is what is actually documented:
* <nowiki>{{yesno|blank= eggs|no=ham|¬=bread}}</nowiki>
:I have changed the documentation. Not the table above. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 13:16, 23 March 2013 (UTC)
Line 110 ⟶ 115:
{{tl|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. [[User:Dragons flight|Dragons flight]] ([[User talk: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.
<span style="font-family:'Arial';">[[User:E Super Maker|E Super Maker]]</span> ([[User talk:E Super Maker|😲 shout]]) 15:47, 23 November 2019 (UTC)
== test failed ==
Line 125 ⟶ 131:
== Null? ==
The code now says {{code|1=<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. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 17:47, 23 March 2013 (UTC)
:Yes, I agree that it doesn't really make sense. It's just in there to be 100% backwards-compatible with the current template. Those html comments should really have been removed from {{tl|yesno}} when it was made subst-able, which would have prevented us from having to second-guess whether they actually affect the output of any substitutions in any meaningful way. I suppose it's possible to download a database dump and to run a search on it to find out, but that's probably a bit much for my poor ailing laptop. Or we could just remove the comments and hope nothing breaks - I'm fairly sure that no-one would have written any template code that purposefully used them. There's no way to be sure that there is no code that was inadvertently written to be dependent on the error, though, and that worries me. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 18:24, 23 March 2013 (UTC)
::Drop it. Come what may. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 00:17, 24 March 2013 (UTC)
== Rewrite ==
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 {{tl|yesno}} seemed like the best answer. The new version should hopefully retain the basics of {{tl|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 Work<sup>TM</sup>.) — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 14:37, 20 September 2013 (UTC)
== All testcases failed ==
is there some issue with the module, all tests on the [[Module talk:Yesno/testcases]] has failed. --[[User:Jarekt|Jarekt]] ([[User talk:Jarekt|talk]]) 16:37, 20 December 2013 (UTC)
== Protected edit request on 24 February 2014 ==
{{edit protected|<!-- Page to be edited -->|answered=yes}}
<!-- Begin request -->the information is deceptive
<!-- End request -->please delete
[[Special:Contributions/2600:1013:B018:986F:4493:7A2A:52E2:103A|2600:1013:B018:986F:4493:7A2A:52E2:103A]] ([[User talk:2600:1013:B018:986F:4493:7A2A:52E2:103A|talk]]) 04:21, 24 February 2014 (UTC)
:[[File:Red question icon with gradient background.svg|20px|link=|alt=]] '''Not done:''' please be more specific about what needs to be changed.<!-- Template:EP --> Note that this is the talk page for [[Module:Yesno]] and there is no information here. What information on which page do you think is deceptive? — <span class="nowrap">{{U|[[User:Technical 13|Technical 13]]}}</span> <sup>([[User talk:Technical 13|t]] • [[Special:EmailUser/Technical 13|e]] • [[Special:Contributions/Technical 13|c]])</sup> 04:27, 24 February 2014 (UTC)
== New version ==
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? — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 15:22, 7 April 2014 (UTC)
:I see no issue with it. [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 18:57, 7 April 2014 (UTC)
::The new version is live as of the 18th. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 12:33, 22 April 2014 (UTC)
== Doc questions (blank string true/false) ==
# In the documentation, I changed the "nil" example into singular. Or are there are other forms of nil covered and to be documented? (uppercase?, a non-initialised variable?).
# The last paragraph is about the <code><nowiki>''</nowiki></code> value (blank string). It says:
:''Although the blank string usually evaluates to false in wikitext, it evaluates to true in Lua.'' Is this correct here?
:According to this same documentation, it is treated as "not a boolean". It says it returns the default (parameter) value, not the 'true' value. That is: not recognised as a boolean, iic. And elsewhere the doc says "<code><nowiki>yesno('')</nowiki></code> returns nil". (I did not test any). -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 09:06, 8 April 2014 (UTC)
::On nil: there is only one kind of nil. However, there may be many variables in any given module whose value may be nil, hence "nil values". There is no "uppercase nil", and in Lua there is no such thing as a non-initialised variable, as variables are initialised when they are first used. On the blank string: saying that it "evaluates to true" is talking about when it is used in if/then statements or with the <code>and</code> and <code>or</code> operators. For example, the following code will return true:
<syntaxhighlight lang="lua">
if '' then
return true
else
return false
end
</syntaxhighlight>
::Does that clear things up? — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 09:26, 8 April 2014 (UTC)
:::Does it clear things up? Don't know. Documentation did not change. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 12:10, 8 April 2014 (UTC)
::::I mean, do you understand it now? — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 12:34, 8 April 2014 (UTC)
== Render T as true as well? ==
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. <span style="border:1px solid maroon; padding:0 2px">[[User:CRwikiCA|<span style="font-family:'Courier';color:maroon">CRwikiCA</span>]] [[User talk:CRwikiCA|<i style="color:navy">talk</i>]]</span> 15:15, 14 April 2015 (UTC)
;Request
{{edit protected|ans=y}}
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:
<syntaxhighlight lang="lua" line>
-- 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
</syntaxhighlight>
Where lines 15 and 23 are new compared to the current code. <span style="border:1px solid maroon; padding:0 2px">[[User:CRwikiCA|<span style="font-family:'Courier';color:maroon">CRwikiCA</span>]] [[User talk:CRwikiCA|<i style="color:navy">talk</i>]]</span> 18:17, 23 April 2015 (UTC)
:No opposition, so {{done}} — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 10:43, 27 April 2015 (UTC)
::I would be interested to know cases where such "t/f" values may be encountered. I know that in command prompts we may encounter "y/n" choices. But I cannot recall having ever encountered "t/f".
::Refs [[phab:T137584|T137584]] (« Allow Scribunto code to add a category without changing output »), which would allow to know on what (and how many) pages these values are actually used.
::[[User:Od1n|Od1n]] ([[User talk:Od1n|talk]]) 00:05, 20 October 2024 (UTC)
== Support on/off detection ==
{{edit fully-protected|answered=yes}}
Please add support for {{kbd|on}} and {{kbd|off}} values (as equivalents of {{kbd|1}} and {{kbd|0}}, respectively), for consistency with the regular-template version {{tlx|Yesno}}, per RfC at [[Template talk:Yesno#Support on/off detection]]. <span style="white-space:nowrap;font-family:'Trebuchet MS'"> — [[User:SMcCandlish|'''SMcCandlish''']] [[User talk:SMcCandlish|☏]] [[Special:Contributions/SMcCandlish|¢]] 😼 </span> 23:44, 22 February 2018 (UTC)
:Very simple change, but i've [[Module:Yesno/sandbox|sandboxed]] the change and ran the testcases.. [[User:Galobtter|Galobtter]] ([[User talk:Galobtter|pingó mió]]) 07:52, 25 February 2018 (UTC)
:[[File:Yes check.svg|20px|link=|alt=]] '''Done'''<!-- Template:EP --> — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 12:14, 28 February 2018 (UTC)
::Thank you {{U|Galobtter}}, for the coding work (Lua gives me a headache), and {{U|MSGJ}}, for just getting it implemented, instead of either of you being a thorn in the side about it like several parties were for no defensible reason at the RfC. I've never encountered so much "resist sensible change just because I feel like it" nonsense on a minor technical matter as I did in this particular case. It was weird, verging on inexplicable. <span style="white-space:nowrap;font-family:'Trebuchet MS'"> — [[User:SMcCandlish|'''SMcCandlish''']] [[User talk:SMcCandlish|☏]] [[Special:Contributions/SMcCandlish|¢]] 😼 </span> 18:37, 26 May 2018 (UTC)
== Upgrade of protection level ==
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. [[User:KylieInTheSkylie|KylieInTheSkylie]] ([[User talk:KylieInTheSkylie|talk]]) 02:23, 6 April 2020 (UTC)
:Just realized that full protection is not [[wp:ECP| Extended confirmed protection.]] Please disregard this. [[User:KylieInTheSkylie|KylieInTheSkylie]] ([[User talk:KylieInTheSkylie|talk]]) 02:23, 6 April 2020 (UTC)
== Multilingual version? ==
What about a multilingual version? Would there be any conflicts? [[User:Trigenibinion|Trigenibinion]] ([[User talk:Trigenibinion|talk]]) 17:21, 12 March 2021 (UTC)
:It seems this is normally called the same in other languages, where they appear to tend to support English as well as the translation, so this should be usable in a multilingual module. [[User:Trigenibinion|Trigenibinion]] ([[User talk:Trigenibinion|talk]]) 17:57, 12 March 2021 (UTC)
:: There is no need for a multilingual version of this module to exist on this wiki, since its content is in only one language. Furthermore, were one created, it would be a recreation of [[Module:YesnoTNT]], which was deleted per [[Wikipedia:Templates for discussion/Log/2019 December 11#Module:YesnoTNT]], and I would move for it to be speedy deleted per [[WP:CSD#G4]] [[User:Pppery|* Pppery *]] [[User talk:Pppery|<sub style="color:#800000">it has begun...</sub>]] 20:36, 13 March 2021 (UTC)
== Option: Binary-only? ==
I want to "propose" to add an option (feature) that makes the module return '''{{code|T/F}} only, never {{code|nil}}'''. For example, it could have para {{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? -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 04:56, 23 December 2021 (UTC)
:It's easy enough to just handle the nil in your own code, for example: <syntaxhighlight lang="lua" inline>myvariable = yesno(value) or false</syntaxhighlight> -- [[User:WOSlinker|WOSlinker]] ([[User talk:WOSlinker|talk]]) 20:09, 23 December 2021 (UTC)
::This can also mostly be handled by specifying the default parameter (i.e. <syntaxhighlight lang="lua" inline>myvariable = yesno(value, false)</syntaxhighlight>), although this does leave the case <syntaxhighlight lang="lua" inline>yesno(nil, false)</syntaxhighlight>, which evaluates to <syntaxhighlight lang="lua" inline>nil</syntaxhighlight>. 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. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 22:11, 23 December 2021 (UTC)
:::OK, thx. I can use this code solution with confidence now, no research-&-test needed. Might as well add it to the /doc. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 16:35, 24 December 2021 (UTC)
::::The abovementioned <code>yesno(value) or true/false</code> has a common pitfall and should be avoided: if value is "false", <code>yesno(value) or true</code> would gives "true", instead of the presumably expected "false". See section « Standard solution: and/or » on [http://lua-users.org/wiki/TernaryOperator this page]. [[User:Od1n|Od1n]] ([[User talk:Od1n|talk]]) 18:15, 22 September 2024 (UTC)
|