[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Cap 'days' param in RC/Watchlist at $wgRCMaxAge

2017-07-26 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/367846 )

Change subject: Cap 'days' param in RC/Watchlist at $wgRCMaxAge
..


Cap 'days' param in RC/Watchlist at $wgRCMaxAge

Without this, setting the 'days' param to a very high value
causes exceptions while doing timestamp math.

Bug: T149890
Change-Id: I5aee5f027cced8860eb966e2d6bdb07764ce861a
---
M includes/specials/SpecialRecentchanges.php
M includes/specials/SpecialWatchlist.php
2 files changed, 12 insertions(+), 4 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified
  Jforrester: Looks good to me, but someone else must approve



diff --git a/includes/specials/SpecialRecentchanges.php 
b/includes/specials/SpecialRecentchanges.php
index 1248007..f0c2bc4 100644
--- a/includes/specials/SpecialRecentchanges.php
+++ b/includes/specials/SpecialRecentchanges.php
@@ -373,6 +373,7 @@
 
public function validateOptions( FormOptions $opts ) {
$opts->validateIntBounds( 'limit', 0, 5000 );
+   $opts->validateBounds( 'days', 0, $this->getConfig()->get( 
'RCMaxAge' ) / ( 3600 * 24 ) );
parent::validateOptions( $opts );
}
 
@@ -387,7 +388,7 @@
$query_options, $join_conds, $opts );
 
// Calculate cutoff
-   $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
+   $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
$cutoff = $dbr->timestamp( $cutoff_unixtime );
 
$fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
diff --git a/includes/specials/SpecialWatchlist.php 
b/includes/specials/SpecialWatchlist.php
index 65131ec..549362f 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -34,6 +34,8 @@
 class SpecialWatchlist extends ChangesListSpecialPage {
public function __construct( $page = 'Watchlist', $restriction = 
'viewmywatchlist' ) {
parent::__construct( $page, $restriction );
+
+   $this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 
* 24 );
}
 
public function doesWrites() {
@@ -173,6 +175,11 @@
return $opts;
}
 
+   public function validateOptions( FormOptions $opts ) {
+   $opts->validateBounds( 'days', 0, $this->maxDays );
+   parent::validateOptions( $opts );
+   }
+
/**
 * Get all custom filters
 *
@@ -255,7 +262,7 @@
// Calculate cutoff
if ( $opts['days'] > 0 ) {
$conds[] = 'rc_timestamp > ' .
-   $dbr->addQuotes( $dbr->timestamp( time() - 
intval( $opts['days'] * 86400 ) ) );
+   $dbr->addQuotes( $dbr->timestamp( time() - 
$opts['days'] * 3600 * 24 ) );
}
}
 
@@ -499,7 +506,7 @@
if ( $opts['days'] > 0 ) {
$days = $opts['days'];
} else {
-   $days = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 
* 24 );
+   $days = $this->maxDays;
}
$timestamp = wfTimestampNow();
$wlInfo = $this->msg( 'wlnote' )->numParams( $numRows, round( 
$days * 24 ) )->params(
@@ -599,7 +606,7 @@
$days[] = $userWatchlistOption;
}
 
-   $maxDays = (string)( $this->getConfig()->get( 'RCMaxAge' ) / ( 
3600 * 24 ) );
+   $maxDays = (string)$this->maxDays;
// add the maximum possible value, if it isn't available already
if ( !in_array( $maxDays, $days ) ) {
$days[] = $maxDays;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5aee5f027cced8860eb966e2d6bdb07764ce861a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Catrope 
Gerrit-Reviewer: Catrope 
Gerrit-Reviewer: Florianschmidtwelzow 
Gerrit-Reviewer: Jforrester 
Gerrit-Reviewer: Krinkle 
Gerrit-Reviewer: Sbisson 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Cap 'days' param in RC/Watchlist at $wgRCMaxAge

2017-07-25 Thread Catrope (Code Review)
Catrope has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367846 )

Change subject: Cap 'days' param in RC/Watchlist at $wgRCMaxAge
..

Cap 'days' param in RC/Watchlist at $wgRCMaxAge

Without this, setting the 'days' param to a very high value
causes exceptions while doing timestamp math.

Bug: T149890
Change-Id: I5aee5f027cced8860eb966e2d6bdb07764ce861a
---
M includes/specials/SpecialRecentchanges.php
M includes/specials/SpecialWatchlist.php
2 files changed, 4 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/46/367846/1

diff --git a/includes/specials/SpecialRecentchanges.php 
b/includes/specials/SpecialRecentchanges.php
index 1248007..72b7ca2 100644
--- a/includes/specials/SpecialRecentchanges.php
+++ b/includes/specials/SpecialRecentchanges.php
@@ -387,7 +387,8 @@
$query_options, $join_conds, $opts );
 
// Calculate cutoff
-   $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
+   $seconds = max( $opts['days'] * 86400, $this->getConfig()->get( 
'RCMaxAge' ) );
+   $cutoff_unixtime = time() - $seconds;
$cutoff = $dbr->timestamp( $cutoff_unixtime );
 
$fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
diff --git a/includes/specials/SpecialWatchlist.php 
b/includes/specials/SpecialWatchlist.php
index 65131ec..51ddd60 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -254,8 +254,9 @@
 
// Calculate cutoff
if ( $opts['days'] > 0 ) {
+   $seconds = max( $opts['days'] * 86400, 
$this->getConfig()->get( 'RCMaxAge' ) );
$conds[] = 'rc_timestamp > ' .
-   $dbr->addQuotes( $dbr->timestamp( time() - 
intval( $opts['days'] * 86400 ) ) );
+   $dbr->addQuotes( $dbr->timestamp( time() - 
$seconds ) );
}
}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5aee5f027cced8860eb966e2d6bdb07764ce861a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Catrope 

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