Content deleted Content added
→isIpOrRange: test first! |
→isIpV4Range and isIpV6Range: Reply |
||
(24 intermediate revisions by 6 users not shown) | |||
Line 61:
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange| 1.2.3.4 }}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange| 1.2.3.4 }}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|1.2.3.0/24}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|1.2.3.0/24}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|2606:6000:
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|2606:6000:
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|}}
Line 69:
:{{re|Johnuniq}} This is perfect{{snd}}thanks for your fast work here! Please go ahead and move this to the main module. I really appreciate it. Best, '''[[User:L235|KevinL]]''' (<small>aka</small> [[User:L235|L235]] '''·''' [[User talk:L235#top|t]] '''·''' [[Special:Contribs/L235|c]]) 09:23, 14 December 2020 (UTC)
::@[[User:L235|KevinL]]: Hang on, you've got to test it first! Does it work wherever you're intending to use it? [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:27, 14 December 2020 (UTC)
:::Well, from the examples you wrote above, I'm suitably confident this will work {{smiley}}. I know the code in [[Module:IP]] is well-tested and since this function relies on that I'm sure this will work too; I wasn't familiar with the lua syntax for testing the success of other functions, but I'm quite confident that you are! Based on the tests I've done on the beta cluster the parameter I'll be passing in is exactly in the form that your function accepts. Anyway, I'm quite confident that this works for me! Best, '''[[User:L235|KevinL]]''' (<small>aka</small> [[User:L235|L235]] '''·''' [[User talk:L235#top|t]] '''·''' [[Special:Contribs/L235|c]]) 09:35, 14 December 2020 (UTC)
::::@[[User:L235|KevinL]]: OK, it's not rocket science so I updated the main module. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:55, 14 December 2020 (UTC)
== Reuse Module:IP ==
I'm proposing to reuse [[Module:IP]] for all functions in this module. The change can be found at [[Module:IPAddress/sandbox]]. This would have the following practical effects:
* Accept ranges for all functions. This is my intended use case. There's nothing in the testcases about this, so I'm not sure if current users are relying on isIp/isIpV4/isIpV6 returning false for ranges.
* Generally more lax parsing, such as accepting leading and trailing spaces.
What do you think about this change? If it's something that will break other templates, then I would propose to add new functions to check if a string is an IPv4 or IPv6 IP or range. [[User:MarioGom|MarioGom]] ([[User talk:MarioGom|talk]]) 18:28, 18 March 2021 (UTC)
:Probably desirable although I haven't looked at the details yet. It would be quite a lot more overhead but probably insignificant. Some thought about how Module:IPAddress is used would be good (if it's not used much, overhead doesn't matter). However, if it's going to be redone, please fix the atrocious global functions and fix any modules which use them. This is 2021 and global functions are known bad! For one thing, any module using [[Module:No globals]] will crash if it tries to use these functions. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 00:58, 19 March 2021 (UTC)
::I don't know how reliable it is, but according to "what links here", Module:IPAddress is not used by any modules (apart from itself for some weird reason). It is used by around 210 templates but I suspect that almost all of them are incorrect reporting by the tool, due to use of {{tl|Userspace linking templates}} on the doc pages of those templates. There may be more, but the only templates I can find using this module are {{tl|IsIPAddress}} and {{tl|Xsign}}. The module is used at [[MediaWiki:Newarticletext]]. {{ping|L235}} Did you use this module somewhere? [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:09, 19 March 2021 (UTC)
:::I currently use it in [[Mediawiki:Blockedtext]] but would be quite happy if this was merged into [[Module:IP]]! '''[[User:L235|KevinL]]''' (<small>aka</small> [[User:L235|L235]] '''·''' [[User talk:L235#top|t]] '''·''' [[Special:Contribs/L235|c]]) 18:18, 19 March 2021 (UTC)
::::Ah, so Module:IPAddress is used at [[MediaWiki:Newarticletext]] and [[MediaWiki:Blockedtext]]. The proposal is not to merge the modules but to use [[Module:IP]] to implement the functions provided at [[Module:IPAddress]] while changing the documented behavior so, for example, 1.2.3.4/24 would be an "IP address". That would not affect the isIpOrRange function you are using. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 00:01, 20 March 2021 (UTC)
:::::Sounds good then! I have no permissions to edit this template, can any of you apply the changes in the sandbox? Is there anything that needs to be addressed before? [[User:MarioGom|MarioGom]] ([[User talk:MarioGom|talk]]) 16:44, 27 March 2021 (UTC)
::::::The thing that's outstanding is fixing the globals as mentioned above. I'll have a look at that later. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 00:50, 28 March 2021 (UTC)
:::::::I edited the sandbox to fix the globals. However I added a TODO note which is going to require quite a bit of thought because the changes (to accept ranges as noted above) might not be compatible with how this module is used. I'm not even sure if it is desirable: should 1.2.3.4/5 be regarded as a valid IPv4 address? Also, the testcases need thought. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 08:38, 28 March 2021 (UTC)
::::::::My use case is distinguishing IPv4 address/CIDR from IPv6 address/CIDR (for {{tl|Proxyip}}, {{tl|Proxyip4}}, {{tl|Proxyip6}}). I then use isIpOrRange or other methods to check if it's a range. My guess is that for any template or module using it for usernames it shouldn't make any difference. If you think the breakage risk is too high, then I would go for new functions like isIpV4AddressOrRange and isIpV6AddressOrRange. Although it can be simpler to keep it to 2 orthogonal aspects: IPv4 vs IPv6 and address vs range. [[User:MarioGom|MarioGom]] ([[User talk:MarioGom|talk]]) 14:30, 31 March 2021 (UTC)
:::::::::(disclosure: i wrote this module years ago, i think per some request in wp:vpt or wp:lua): can one of you guys, in one of the next passes, also make the functions in this module "local"? it's a bit of a sticking point... peace - [[User:קיפודנחש|קיפודנחש (aka kipod)]] ([[User talk:קיפודנחש|talk]]) 17:39, 31 March 2021 (UTC)
::::::::::I already cleaned the module and there are now no globals (in the sandbox). Some searching showed it is likely the globals are unused but we'll find out when the sandbox eventually goes live. I've been caught up off-wiki and haven't fully thought about the issue but new functions might be best. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 03:03, 1 April 2021 (UTC)
{{Outdent}} {{u|Johnuniq}}: We have two pending issues. One is whether we want a separate set of functions or not. My ''guess'' is that current usages will probably be ok with the change, but I can separate the functionality if we want to be extra safe. The other is the question of strict/lax parsing. [[Module:IPAddress]] is quite strict while [[Module:IP]] accepts many addresses that are invalid (even if they can be parsed with some assumptions). I thought about proposing a bit of stricter parsing at [[Module:IP]], like not accepting two zero compressions (::) in the same address. But I fear that following that road means it will never be done. [[User:MarioGom|MarioGom]] ([[User talk:MarioGom|talk]]) 17:18, 31 May 2021 (UTC)
:It's two months since my last comment and that's too long for me to remember what this is all about. I edited [[Module:IPAddress]] to include my changes in [[Module:IPAddress/sandbox]] relating to style and to remove global functions. That will make a comparison easier.
{{#invoke:convert/tester|compare|IPAddress}}
:<code>isIpOrRange</code> could be used to determine if given text (with the perhaps too lenient checking of [[Module:IP]]) is a valid IP or range. Then, if it contains <code>/</code> it's a range, and if it contains <code>:</code> it's IPv6. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 05:09, 1 June 2021 (UTC)
== Protected edit request on 3 February 2022 ==
{{edit fully-protected|Module:IPAddress|answered=yes}}
<code>p.isIpOrRange</code> currently requires a frame and prevents other modules (which may not have the first argument as the string to check) from checking if a given string is an IP or range. Please change lines 46 to 59 with the following.
<syntaxhighlight line start="49" lang="lua">
function p._isIpOrRange(s)
local modip = require('Module:IP')
local success, ip = pcall(modip.IPAddress.new, s)
if success then
return 'ip'
end
success, ip = pcall(modip.Subnet.new, s)
if success then
return 'range'
end
return ''
end
function p.isIpOrRange(frame)
-- {{#invoke:IPAddress|isIpOrRange|x}} → 'ip' (IPv4/IPv6) or 'range' (CIDR IPv4/IPv6) or '' (invalid)
return p._isIpOrRange(input(frame))
end
</syntaxhighlight> <span style="background:#ffff55">'''''[[User:Chlod|Chlod]]'''''</span> <small style="font-size:calc(1em - 2pt)">([[User talk:Chlod|say hi!]])</small> 17:43, 3 February 2022 (UTC)
:This looks good, thanks. I updated [[Module:IPAddress/sandbox]] with a slightly tweaked version of the above (just a slight re-ordering to suit what is already in the module) and will do a final check a little later. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 22:47, 3 February 2022 (UTC)
::Done. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 01:01, 4 February 2022 (UTC)
:::Thank you very much! {{smiley}} <span style="background:#ffff55">'''''[[User:Chlod|Chlod]]'''''</span> <small style="font-size:calc(1em - 2pt)">([[User talk:Chlod|say hi!]])</small> 09:53, 4 February 2022 (UTC)
== isIpV4Range and isIpV6Range ==
I've created the new functions isIpV4Range and isIpV6Range which do exactly what it sounds like. This is for use in [[Template:Vandal]] but can probably come in handy in other places as well. If noone objects in the next few days I will take the code in the sandbox live. There are testcases. --[[User:Trialpears|Trialpears]] ([[User talk:Trialpears|talk]]) 18:30, 10 January 2023 (UTC)
:i do not see any such functions in the snadbox.
:i am guessing the functions you describe reside somewhere else. furthermore, i am guessing they are in the same vein as _isIpOrRange().
:presuming this is the case, i'll say what i should have said when this function was added: i think it's utterly silly. not the function itself, of course, but its inclusion in this module. i can't imagine what is the added value of placing in module A a function that does nothing but pipe calls to module B.
:this practice makes sense when some of the "native" functions of A are using this implanted function, but this is not the case here, and _isIpOrRange, as well as the 2 new functions you describe are entirely for "export" purposes. all they do is pipe functionality of [[Module:IP]], and my common sense says they should reside there. what is the value of planting this "foreign body" here?
:tl;dr: please consider placing these new functions in module IP rather than here.
:peace. [[User:קיפודנחש|קיפודנחש (aka kipod)]] ([[User talk:קיפודנחש|talk]]) 19:47, 10 January 2023 (UTC)
::@[[User:קיפודנחש|קיפודנחש]] [https://en.wikipedia.org/w/index.php?title=Module:IPAddress/sandbox&diff=1132811434&oldid=1069755838 Here] is a diff with the code at [[Module:IPAddress/sandbox]] and testcases at [[Module talk:IPAddress/testcases]].
::In principal I'm not opposed to having this in [[Module:IP]] instead, but if were going to have two separate modules, which the [[Wikipedia:Templates_for_discussion/Log/2018_July_1#Module:IP|2018 TfD]] thought was for the best, I feel this fits better here than in [[Module:IP]] since it's intended to be easy to use in templates while IP seems to have functions primarily intended for use in Modules. --[[User:Trialpears|Trialpears]] ([[User talk:Trialpears|talk]]) 20:22, 10 January 2023 (UTC)
:::thanks. don't know how i missed them earlier. i have some excuses, but i doubt anyone here will be interested.
:::those functions seem to be in the right place - they do use the functionality of this module, and do belong here, contrary to my previous assumption they do not, which was made before reading the code. thanks.
:::btw, the addition of these functions (retroactively) justifies the inclusion of _isIpOrRange() here...
:::will be good to add testcases, both positive and negative, before merging the sandbox to the module itself.
:::peace. [[User:קיפודנחש|קיפודנחש (aka kipod)]] ([[User talk:קיפודנחש|talk]]) 00:10, 11 January 2023 (UTC)
|