Template talk:IP-user other

Latest comment: 4 years ago by Davidgothberg in topic IPv6 support for template ((IP-user other))

About ((IP-user other)) edit

Credits: This template is based on IP-user page detecting code from MediaWiki:Newarticletext. That code was added by User:Sandstein, who noted he got it from User:Ais523. When I found that code I had already been developing my own IP-user page detection code for some time, but Ais523's method is much more efficient.

This method detects strings like this:

  • 12.34.56.78 = IP-user
  • 12.34.56 = IP-user
  • 12.34 = other
  • aa12.34.56.78 = other
  • 12.34.56.78aa = other
  • abcdef = other
  • a123 = other

The string needs to be all numbers, with at least two dots. Detecting "12.34.56" as an IP-user is of course not entirely correct since it only has two dots, but the number of such usernames is probably very small or non-existent. So it is good enough.

--David Göthberg (talk) 22:13, 14 February 2010 (UTC)Reply

This template now also detects IPv6 user pages such as User:2001:B011:7009:18A0:FC2F:9F5F:5B46:306E. It does so by checking that there are colons in the exact right locations. It checks the three first colons, e.g. in the section 2001:B011:7009:18A0 in that address. We could check all the colons, but that would just cost more code and server work. The current matching should be good enough.

--David Göthberg (talk) 02:37, 26 December 2019 (UTC)Reply

For über-geek eyes only edit

The code {{#titleparts:{{PAGENAME}}|1}} strips pagenames like "User:12.34.56.78/subpage" down to "12.34.56.78".

The IPv4 detection code is this:

{{#switch: {{#expr: {{PAGENAME}} }}
| {{#expr: {{PAGENAME}} + 1 }} = Is not a number.
| {{PAGENAME}} = Is a normal number like 12.34 or 12
| #default = Is an IPv4 address
}}

It involves these things:

  • {{#expr: 12.34.56.78 }} returns "12.34". Thus {{#expr: 12.34.56.78 }} != "12.34.56.78", but {{#expr: 12.34 }} == "12.34". Which in the above code is the comparison "{{#expr: {{PAGENAME}} }} == {{PAGENAME}}".
  • Both {{#expr: text }} and {{#expr: text + 1 }} return exactly Expression error: Unrecognized word "text".. The nice part is that the parserFunctions can also compare exceptions, so we can check if {{#expr: text }} == {{#expr: text + 1 }}. They must throw the exact same exception string to match. In the above code it means that {{#expr: {{PAGENAME}} }} == {{#expr: {{PAGENAME}} + 1 }} is true when both throw the exception, but it will not match when the input is a number, since "x != x+1".

--David Göthberg (talk) 22:13, 14 February 2010 (UTC)Reply

IPv6 support for template ((IP-user other)) edit

This message was moved here from my talk page. --David Göthberg (talk) 05:13, 28 December 2019 (UTC)Reply

I must say it is an amazing way to detect IPv4 users without Lua. But things have changed these years and do we need a Lua module to make the implement less hackish and add IPv6 support as well? (I'm not so familiar with English Wikipedia and did not find a wheel to do so) Thanks, WhitePhosphorus (talk) 04:54, 25 December 2019 (UTC)Reply

  Done - I took a look at it. I went ahead and updated {{IP-user other}} so that it now detects IPv6 user pages too. Didn't need Lua for that. The IPv6 detection part is actually cleaner code than the IPv4 detection, since it was simpler to detect IPv6 user page names. Note that the template now uses a {{IP-user other/core}} subtemplate, in case you are copying it to another wiki.
And thanks for pointing out the need for IPv6 detection. I looked around and noticed that some of our system messages such as MediaWiki:Anontalkpagetext only shows on IPv4 user pages. So now that I have updated the ((IP-user other)) template we can use that one to fix all that.
--David Göthberg (talk) 03:05, 26 December 2019 (UTC)Reply