From: Florian Date: Fri, 20 Nov 2015 06:45:46 +0000 (+0100) Subject: Special:Watchlist: Add user preference to "Show last" options, fix float comparison X-Git-Tag: 1.31.0-rc.0~8905^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=b9fbbba4af3e56b504240fc32d1c9199f4444212;p=lhc%2Fweb%2Fwiklou.git Special:Watchlist: Add user preference to "Show last" options, fix float comparison Also, simplified the "selected" check: if ( $a == $b ) { return true; } else { return false; } doesn't make sense, if you can use: return $a == $b; Bug: T119172 Bug: T119181 Change-Id: I16e1713bcd6519695961fcaf094a214954e7769c --- diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 2feaa9e21f..1d6bfb32e4 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -507,21 +507,36 @@ class SpecialWatchlist extends ChangesListSpecialPage { } function cutoffselector( $options ) { + $userWatchlistOption = $this->getUser()->getOption( 'watchlistdays' ); + $list = array(); $selectOptions = ''; $hours = array( 1, 2, 6, 12 ); $days = array( 1, 3, 7 ); + // add the user preference, if it isn't available already + if ( $userWatchlistOption >= 1 && !in_array( $userWatchlistOption, $days ) ) { + $days[] = $userWatchlistOption; + asort( $days ); + } elseif ( $userWatchlistOption < 1 && !in_array( $userWatchlistOption * 24, $hours ) ) { + $hours[] = $userWatchlistOption * 24; + asort( $hours ); + } foreach ( $hours as $h ) { - $name = $this->msg( 'hours', $h ); + $name = $this->msg( 'hours' )->numParams( $h ); $value = $h / 24; - $selected = ( $value == $options['days'] ) ? true : false; + // due to the possible addition of a user value, it's possible, that both + // values ($value and $options['days']) are floats with unexpected comparison + // behaviour. Comparing them directly can result in a "not equality" result, + // even if the "visible" floats would be the same (e.g. if the user value is + // float(0.4)). See PHP docs about Comparing floats. + $selected = abs( $value - $options['days'] ) < 0.00001; $selectOptions .= Xml::option( $name, $value, $selected ); } foreach ( $days as $d ) { - $name = $this->msg( 'days', $d ); + $name = $this->msg( 'days' )->numParams( $d ); $value = $d; - $selected = ( $value == $options['days'] ) ? true : false; + $selected = $value == $options['days']; $selectOptions .= Xml::option( $name, $value, $selected ); }