From: Aryeh Gregor Date: Thu, 24 Dec 2009 23:01:19 +0000 (+0000) Subject: Handle minus signs in sortable tables X-Git-Tag: 1.31.0-rc.0~38478 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=4f278f513d5bf24c7252732a168e3646cc5af101;p=lhc%2Fweb%2Fwiklou.git Handle minus signs in sortable tables Bug 21946. Patch by Conrad Irwin (cirwin). --- diff --git a/CREDITS b/CREDITS index 4d4f360070..728fce7252 100644 --- 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 diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 97531c5c98..3b69594efd 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index f2505312a0..95b2e06974 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -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) {