Avoid arithmetics on localized number string ("0,04") in SpecialWatchlist
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index ea73347..41a059f 100644 (file)
@@ -35,6 +35,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
        protected static $daysPreferenceName = 'watchlistdays';
        protected static $limitPreferenceName = 'wllimit';
+       protected static $collapsedPreferenceName = 'rcfilters-wl-collapsed';
 
        private $maxDays;
 
@@ -110,10 +111,15 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        }
 
        public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {
-               return (
-                       $config->get( 'StructuredChangeFiltersOnWatchlist' ) &&
-                       $user->getOption( 'rcenhancedfilters' )
-               );
+               if ( !$config->get( 'StructuredChangeFiltersOnWatchlist' ) ) {
+                       return false;
+               }
+
+               if ( $config->get( 'StructuredChangeFiltersShowWatchlistPreference' ) ) {
+                       return !$user->getOption( 'wlenhancedfilters-disable' );
+               } else {
+                       return $user->getOption( 'rcenhancedfilters' );
+               }
        }
 
        /**
@@ -520,7 +526,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                                                                $this->msg( 'watchlist-unwatch' )->text(), [
                                                                        'class' => 'mw-unwatch-link',
                                                                        'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
-                                                               ], [ 'action' => 'unwatch' ] ) . ' ';
+                                                               ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
                                }
                        } );
                }
@@ -750,45 +756,36 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        }
 
        function cutoffselector( $options ) {
-               // Cast everything to strings immediately, so that we know all of the values have the same
-               // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
-               // default string representation, for example, and would confuse comparisons.
-
-               // Misleadingly, the 'days' option supports hours too.
-               $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
-
-               $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
-               // add the user preference, if it isn't available already
-               if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
-                       $days[] = $userWatchlistOption;
-               }
-
-               $maxDays = (string)$this->maxDays;
-               // add the maximum possible value, if it isn't available already
-               if ( !in_array( $maxDays, $days ) ) {
-                       $days[] = $maxDays;
-               }
-
-               $selected = (string)$options['days'];
+               $selected = (float)$options['days'];
                if ( $selected <= 0 ) {
-                       $selected = $maxDays;
-               }
-
-               // add the currently selected value, if it isn't available already
-               if ( !in_array( $selected, $days ) ) {
-                       $days[] = $selected;
-               }
+                       $selected = $this->maxDays;
+               }
+
+               $selectedHours = round( $selected * 24 );
+
+               $hours = array_unique( array_filter( [
+                       1,
+                       2,
+                       6,
+                       12,
+                       24,
+                       72,
+                       168,
+                       24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
+                       24 * $this->maxDays,
+                       $selectedHours
+               ] ) );
+               asort( $hours );
 
-               $select = new XmlSelect( 'days', 'days', $selected );
+               $select = new XmlSelect( 'days', 'days', $selectedHours / 24 );
 
-               asort( $days );
-               foreach ( $days as $value ) {
-                       if ( $value < 1 ) {
-                               $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
+               foreach ( $hours as $value ) {
+                       if ( $value < 24 ) {
+                               $name = $this->msg( 'hours' )->numParams( $value )->text();
                        } else {
-                               $name = $this->msg( 'days' )->numParams( $value )->text();
+                               $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
                        }
-                       $select->addOption( $name, $value );
+                       $select->addOption( $name, $value / 24 );
                }
 
                return $select->getHTML() . "\n<br />\n";