https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111829

Revision: 111829
Author:   hartman
Date:     2012-02-18 14:35:14 +0000 (Sat, 18 Feb 2012)
Log Message:
-----------
Add support to tablesorter to handle IP/CIDR notation

This fixes bug 34475

Modified Paths:
--------------
    trunk/phase3/RELEASE-NOTES-1.20
    trunk/phase3/resources/jquery/jquery.tablesorter.js
    trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js

Modified: trunk/phase3/RELEASE-NOTES-1.20
===================================================================
--- trunk/phase3/RELEASE-NOTES-1.20     2012-02-18 14:31:05 UTC (rev 111828)
+++ trunk/phase3/RELEASE-NOTES-1.20     2012-02-18 14:35:14 UTC (rev 111829)
@@ -19,6 +19,7 @@
   preference for the non-default skin to look at something using the default 
skin.
 * (bug 31417) New ID mw-content-text around the actual page text, without 
categories,
   contentSub, ... The same div often also contains the class 
mw-content-ltr/rtl.
+* (bug 34475) Add support for IP/CIDR notation to tablesorter
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.

Modified: trunk/phase3/resources/jquery/jquery.tablesorter.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.tablesorter.js 2012-02-18 14:31:05 UTC 
(rev 111828)
+++ trunk/phase3/resources/jquery/jquery.tablesorter.js 2012-02-18 14:35:14 UTC 
(rev 111829)
@@ -484,7 +484,7 @@
                }
                ts.rgx = {
                        IPAddress: [
-                               new RegExp( 
/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/)
+                               new RegExp( 
/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}(\/\d{1,3})?$/)
                        ],
                        currency: [
                                new RegExp( /^[£$€?.]/),
@@ -767,9 +767,15 @@
                },
                format: function( s ) {
                        var     a = s.split( '.' ),
-                               r = '',
-                               l = a.length;
-                       for ( var i = 0; i < l; i++ ) {
+                               r = '';
+                       if( a.length == 4 ) {
+                               var cidr = a[3].split('/');
+                               if (cidr.length > 1 ) {
+                                       a[3] = cidr[0];
+                                       a[4] = cidr[1];
+                               } else a[4] = '000';
+                       }
+                       for ( var i = 0; i < a.length; i++ ) {
                                var item = a[i];
                                if ( item.length == 1 ) {
                                        r += '00' + item;

Modified: 
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
===================================================================
--- trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js 
2012-02-18 14:31:05 UTC (rev 111828)
+++ trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js 
2012-02-18 14:35:14 UTC (rev 111829)
@@ -236,6 +236,38 @@
        ['204.204.132.158'],
        ['247.240.82.209']
 ];
+var ipv4CIDR = [
+       // Some randomly generated fake IPs
+       ['45.238.27.109/36'],
+       ['170.38.91.162/36'],
+       ['247.240.82.209/36'],
+       ['204.204.132.158/24'],
+       ['170.38.91.162/24']
+];
+var ipv4CIDRSorted = [
+       // Sort order should go octet by octet
+       ['45.238.27.109/36'],
+       ['170.38.91.162/24'],
+       ['170.38.91.162/36'],
+       ['204.204.132.158/24'],
+       ['247.240.82.209/36']
+];
+var ipv4Mixed = [
+       // Some randomly generated fake IPs
+       ['45.238.27.109'],
+       ['170.38.91.162'],
+       ['247.240.82.209'],
+       ['204.204.132.158/24'],
+       ['170.38.91.162/24']
+];
+var ipv4MixedSorted = [
+       // Sort order should go octet by octet
+       ['45.238.27.109'],
+       ['170.38.91.162'],
+       ['170.38.91.162/24'],
+       ['204.204.132.158/24'],
+       ['247.240.82.209']
+];
 
 tableTest(
        'Bug 17141: IPv4 address sorting',
@@ -257,7 +289,28 @@
                $table.find( '.headerSort:eq(0)' ).click().click();
        }
 );
+tableTest(
+       'Bug 34475: IPv4/CIDR address sorting',
+       ['IP'],
+       ipv4CIDR,
+       ipv4CIDRSorted,
+       function( $table ) {
+               $table.tablesorter();
+               $table.find( '.headerSort:eq(0)' ).click();
+       }
+);
 
+tableTest(
+       'Bug 34475: Mixed IPv4 and IP/CIDR address sorting',
+       ['IP'],
+       ipv4Mixed,
+       ipv4MixedSorted,
+       function( $table ) {
+               $table.tablesorter();
+               $table.find( '.headerSort:eq(0)' ).click();
+       }
+);
+
 var umlautWords = [
        // Some words with Umlauts
        ['Günther'],


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to