Message info
 
To:CodeReview comments list From:MediaWiki Mail Subject:[MediaWiki-CodeReview] [MediaWiki r111829]: New comment added Date:Sun, 19 Feb 2012 22:20:56 +0000
 

"TheDJ" posted a comment on MediaWiki.r111829.
URL: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/111829#c31226

Commit summary for MediaWiki.r111829:

Add support to tablesorter to handle IP/CIDR notation

This fixes bug 34475

TheDJ's comment:

i'm not sure how to do this. I've been tinkering with a base2 version of this formatter, but higher ip addresses flip the sign whenever I try to get a numeric or string value out of this.

<source lang=javascript>

var a = s.split( '.' ),
r,
u;
if( a.length == 4 ) {
var cidr = a[3].split('/');
if (cidr.length > 1 ) {
a[3] = cidr[0];
a[4] = cidr[1];
} else a[4] = '32';
}
for ( var i = 0; i < a.length; i++ ) {
var item = parseInt(a[i]);
item &= 255;
switch(i) {
case 0:
r = (item << 24);
break;
case 1:
r |= (item << 16);
break;
case 2:
r |= (item << 8);
break;
case 3:
r |= item;
break;
case 4:
u = r; /* preserve unmasked value */
if( item <= 32 ) {
item = 32 - item;
if( item > 0 ) {
r = r >> item;
r = r << item;
}
}
break;
}
}
</source>

This does not work for instance with "192.168.31.2" . If anyone has more experience with bit operations in JS, then I welcome the feedback.

_______________________________________________
MediaWiki-CodeReview mailing list
MediaWiki-CodeReview@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview