[MediaWiki-commits] [Gerrit] Special:Watchlist: Add user preference to "Show last" option... - change (mediawiki/core)

2015-11-23 Thread Code Review
Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/254880

Change subject: Special:Watchlist: Add user preference to "Show last" options, 
fix float comparison
..

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
(cherry picked from commit b9fbbba4af3e56b504240fc32d1c9199f212)
---
M includes/specials/SpecialWatchlist.php
1 file changed, 19 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/80/254880/1

diff --git a/includes/specials/SpecialWatchlist.php 
b/includes/specials/SpecialWatchlist.php
index 7cc7d5f..3903ee0 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -507,21 +507,36 @@
}
 
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.1;
 
$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 
);
}

-- 
To view, visit https://gerrit.wikimedia.org/r/254880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I16e1713bcd6519695961fcaf094a214954e7769c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.27.0-wmf.7
Gerrit-Owner: Bartosz Dziewoński 
Gerrit-Reviewer: Florianschmidtwelzow 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Special:Watchlist: Add user preference to "Show last" option... - change (mediawiki/core)

2015-11-23 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Special:Watchlist: Add user preference to "Show last" options, 
fix float comparison
..


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
---
M includes/specials/SpecialWatchlist.php
1 file changed, 19 insertions(+), 4 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/specials/SpecialWatchlist.php 
b/includes/specials/SpecialWatchlist.php
index 2feaa9e..1d6bfb3 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -507,21 +507,36 @@
}
 
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.1;
 
$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 
);
}

-- 
To view, visit https://gerrit.wikimedia.org/r/254373
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I16e1713bcd6519695961fcaf094a214954e7769c
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow 
Gerrit-Reviewer: Bartosz Dziewoński 
Gerrit-Reviewer: Florianschmidtwelzow 
Gerrit-Reviewer: Umherirrender 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Special:Watchlist: Add user preference to "Show last" option... - change (mediawiki/core)

2015-11-23 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Special:Watchlist: Add user preference to "Show last" options, 
fix float comparison
..


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
(cherry picked from commit b9fbbba4af3e56b504240fc32d1c9199f212)
---
M includes/specials/SpecialWatchlist.php
1 file changed, 19 insertions(+), 4 deletions(-)

Approvals:
  Thcipriani: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/specials/SpecialWatchlist.php 
b/includes/specials/SpecialWatchlist.php
index 7cc7d5f..3903ee0 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -507,21 +507,36 @@
}
 
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.1;
 
$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 
);
}

-- 
To view, visit https://gerrit.wikimedia.org/r/254880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I16e1713bcd6519695961fcaf094a214954e7769c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.27.0-wmf.7
Gerrit-Owner: Bartosz Dziewoński 
Gerrit-Reviewer: Florianschmidtwelzow 
Gerrit-Reviewer: Thcipriani 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits