From: Geoffrey Mon Date: Sun, 4 Jun 2017 01:12:21 +0000 (-0400) Subject: Fix action=feedcontributions date filtering parameters X-Git-Tag: 1.31.0-rc.0~3039^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/journal.php?a=commitdiff_plain;h=287ddb4c9a345ff8a30651401f5992063eb9c010;p=lhc%2Fweb%2Fwiklou.git Fix action=feedcontributions date filtering parameters * Convert year/month date filter parameters to use start/end so that ApiFeedContributions still works as expected after b668887 * Move SpecialContributions::processDateFilter (used to convert year/month parameters to start/end parameters) to ContribsPager since ApiFeedContributions also uses it now Bug: T166859 Change-Id: I34fc8388a29e4cd36474934e6266127d0e3253cd --- diff --git a/includes/api/ApiFeedContributions.php b/includes/api/ApiFeedContributions.php index 97720c6e9f..cae1e150ee 100644 --- a/includes/api/ApiFeedContributions.php +++ b/includes/api/ApiFeedContributions.php @@ -70,11 +70,16 @@ class ApiFeedContributions extends ApiBase { $feedUrl ); + // Convert year/month parameters to end parameter + $params['start'] = ''; + $params['end'] = ''; + $params = ContribsPager::processDateFilter( $params ); + $pager = new ContribsPager( $this->getContext(), [ 'target' => $target, 'namespace' => $params['namespace'], - 'year' => $params['year'], - 'month' => $params['month'], + 'start' => $params['start'], + 'end' => $params['end'], 'tagFilter' => $params['tagfilter'], 'deletedOnly' => $params['deletedonly'], 'topOnly' => $params['toponly'], diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index cc399b6890..4da1c854ca 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -138,7 +138,7 @@ class SpecialContributions extends IncludableSpecialPage { $this->opts['start'] = $request->getVal( 'start' ); $this->opts['end'] = $request->getVal( 'end' ); - $this->opts = SpecialContributions::processDateFilter( $this->opts ); + $this->opts = ContribsPager::processDateFilter( $this->opts ); } $feedType = $request->getVal( 'feed' ); @@ -728,46 +728,6 @@ class SpecialContributions extends IncludableSpecialPage { return UserNamePrefixSearch::search( 'public', $search, $limit, $offset ); } - /** - * Set up date filter options, given request data. - * - * @param array $opts Options array - * @return array Options array with processed start and end date filter options - */ - public static function processDateFilter( $opts ) { - $start = $opts['start'] ?: ''; - $end = $opts['end'] ?: ''; - $year = $opts['year'] ?: ''; - $month = $opts['month'] ?: ''; - - if ( $start !== '' && $end !== '' && - $start > $end - ) { - $temp = $start; - $start = $end; - $end = $temp; - } - - // If year/month legacy filtering options are set, convert them to display the new stamp - if ( $year !== '' || $month !== '' ) { - // Reuse getDateCond logic, but subtract a day because - // the endpoints of our date range appear inclusive - // but the internal end offsets are always exclusive - $legacyTimestamp = ReverseChronologicalPager::getOffsetDate( $year, $month ); - $legacyDateTime = new DateTime( $legacyTimestamp->getTimestamp( TS_ISO_8601 ) ); - $legacyDateTime = $legacyDateTime->modify( '-1 day' ); - - // Clear the new timestamp range options if used and - // replace with the converted legacy timestamp - $start = ''; - $end = $legacyDateTime->format( 'Y-m-d' ); - } - - $opts['start'] = $start; - $opts['end'] = $end; - return $opts; - } - protected function getGroupName() { return 'users'; } diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index e690a3f45d..a3880eed50 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -573,4 +573,43 @@ class ContribsPager extends RangeChronologicalPager { public function getPreventClickjacking() { return $this->preventClickjacking; } + + /** + * Set up date filter options, given request data. + * + * @param array $opts Options array + * @return array Options array with processed start and end date filter options + */ + public static function processDateFilter( $opts ) { + $start = $opts['start'] ?: ''; + $end = $opts['end'] ?: ''; + $year = $opts['year'] ?: ''; + $month = $opts['month'] ?: ''; + + if ( $start !== '' && $end !== '' && $start > $end ) { + $temp = $start; + $start = $end; + $end = $temp; + } + + // If year/month legacy filtering options are set, convert them to display the new stamp + if ( $year !== '' || $month !== '' ) { + // Reuse getDateCond logic, but subtract a day because + // the endpoints of our date range appear inclusive + // but the internal end offsets are always exclusive + $legacyTimestamp = ReverseChronologicalPager::getOffsetDate( $year, $month ); + $legacyDateTime = new DateTime( $legacyTimestamp->getTimestamp( TS_ISO_8601 ) ); + $legacyDateTime = $legacyDateTime->modify( '-1 day' ); + + // Clear the new timestamp range options if used and + // replace with the converted legacy timestamp + $start = ''; + $end = $legacyDateTime->format( 'Y-m-d' ); + } + + $opts['start'] = $start; + $opts['end'] = $end; + + return $opts; + } } diff --git a/tests/phpunit/includes/specials/ContribsPagerTest.php b/tests/phpunit/includes/specials/ContribsPagerTest.php new file mode 100644 index 0000000000..d7fc13d116 --- /dev/null +++ b/tests/phpunit/includes/specials/ContribsPagerTest.php @@ -0,0 +1,50 @@ +assertArraySubset( $expectedOpts, ContribsPager::processDateFilter( $inputOpts ) ); + } + + public static function dateFilterOptionProcessingProvider() { + return [ + [ [ 'start' => '2016-05-01', + 'end' => '2016-06-01', + 'year' => null, + 'month' => null ], + [ 'start' => '2016-05-01', + 'end' => '2016-06-01' ] ], + [ [ 'start' => '2016-05-01', + 'end' => '2016-06-01', + 'year' => '', + 'month' => '' ], + [ 'start' => '2016-05-01', + 'end' => '2016-06-01' ] ], + [ [ 'start' => '2016-05-01', + 'end' => '2016-06-01', + 'year' => '2012', + 'month' => '5' ], + [ 'start' => '', + 'end' => '2012-05-31' ] ], + [ [ 'start' => '', + 'end' => '', + 'year' => '2012', + 'month' => '5' ], + [ 'start' => '', + 'end' => '2012-05-31' ] ], + [ [ 'start' => '', + 'end' => '', + 'year' => '2012', + 'month' => '' ], + [ 'start' => '', + 'end' => '2012-12-31' ] ], + ]; + } +} diff --git a/tests/phpunit/includes/specials/SpecialContributionsTest.php b/tests/phpunit/includes/specials/SpecialContributionsTest.php deleted file mode 100644 index 6e692a7060..0000000000 --- a/tests/phpunit/includes/specials/SpecialContributionsTest.php +++ /dev/null @@ -1,50 +0,0 @@ -assertArraySubset( $expectedOpts, SpecialContributions::processDateFilter( $inputOpts ) ); - } - - public static function dateFilterOptionProcessingProvider() { - return [ - [ [ 'start' => '2016-05-01', - 'end' => '2016-06-01', - 'year' => null, - 'month' => null ], - [ 'start' => '2016-05-01', - 'end' => '2016-06-01' ] ], - [ [ 'start' => '2016-05-01', - 'end' => '2016-06-01', - 'year' => '', - 'month' => '' ], - [ 'start' => '2016-05-01', - 'end' => '2016-06-01' ] ], - [ [ 'start' => '2016-05-01', - 'end' => '2016-06-01', - 'year' => '2012', - 'month' => '5' ], - [ 'start' => '', - 'end' => '2012-05-31' ] ], - [ [ 'start' => '', - 'end' => '', - 'year' => '2012', - 'month' => '5' ], - [ 'start' => '', - 'end' => '2012-05-31' ] ], - [ [ 'start' => '', - 'end' => '', - 'year' => '2012', - 'month' => '' ], - [ 'start' => '', - 'end' => '2012-12-31' ] ], - ]; - } -}