Handle minus signs in sortable tables
authorAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 24 Dec 2009 23:01:19 +0000 (23:01 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 24 Dec 2009 23:01:19 +0000 (23:01 +0000)
Bug 21946.  Patch by Conrad Irwin (cirwin).

CREDITS
RELEASE-NOTES
skins/common/wikibits.js

diff --git a/CREDITS b/CREDITS
index 4d4f360..728fce7 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -72,6 +72,7 @@ following names for their contribution to the product.
 * Brent G
 * Brianna Laugher
 * Carlin
+* Conrad Irwin
 * Crb
 * Dan Nessett
 * Daniel Arnold
index 97531c5..3b69594 100644 (file)
@@ -299,6 +299,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * EditPage refactored to allow extensions to derive new edit modes much easier.
 * (bug 21826) Subsections of Special:Version now also have anchors
 * (bug 19791) Add URL of file source as comment to thumbs (for ImageMagick)
+* (bug 21946) Sorted wikitables do not properly handle minus signs
 
 === Bug fixes in 1.16 ===
 
index f250531..95b2e06 100644 (file)
@@ -593,8 +593,8 @@ function ts_resortTable(lnk) {
                preprocessor = ts_dateToSortKey;
        } else if (/^\d\d[\/.-]\d\d[\/.-]\d\d$/.test(itm)) {
                preprocessor = ts_dateToSortKey;
-       // pound dollar euro yen currency cents
-       } else if (/(^[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test(itm)) {
+               // (minus sign)([pound dollar euro yen currency]|cents)
+       } else if (/(^([-\u2212] *)?[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test(itm)) {
                preprocessor = ts_currencyToSortKey;
        } else if (ts_number_regex.test(itm)) {
                preprocessor = ts_parseFloat;
@@ -705,9 +705,9 @@ function ts_initTransformTable() {
        // if percents and regular numbers aren't being mixed.
        ts_number_regex = new RegExp(
                "^(" +
-                       "[+-]?[0-9][0-9,]*(\\.[0-9,]*)?(E[+-]?[0-9][0-9,]*)?" + // Fortran-style scientific
+                       "[+-\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[+-\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific
                        "|" +
-                       "[+-]?" + digitClass + "+%?" + // Generic localised
+                       "[+-\u2212]?" + digitClass + "+%?" + // Generic localised
                ")$", "i"
        );
 }
@@ -774,13 +774,12 @@ function ts_parseFloat( s ) {
                }
                s = newNum;
        }
-
-       num = parseFloat(s.replace(/,/g, ""));
-       return (isNaN(num) ? 0 : num);
+       num = parseFloat(s.replace(/[, ]/g, "").replace("\u2212", "-"));
+       return (isNaN(num) ? -Infinity : num);
 }
 
 function ts_currencyToSortKey( s ) {
-       return ts_parseFloat(s.replace(/[^0-9.,]/g,''));
+       return ts_parseFloat(s.replace(/[^-\u22120-9.,]/g,''));
 }
 
 function ts_sort_generic(a, b) {