jenkins-bot has submitted this change and it was merged.

Change subject: Partially reverting I8e684f06 to restore some legacy behavior
......................................................................


Partially reverting I8e684f06 to restore some legacy behavior

Apparently some calls to getDateCond() expect it to not set an offset.
Also, removing some of the new tests that no longer work since they
don't pass all the required parameters. (Before I8e684f06, the year
and month were both required parameters.)

Bug: T145597
Change-Id: I3a90b3da48e49ec9723b7100a7d92146154f74e3
---
M includes/pager/ReverseChronologicalPager.php
M tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php
2 files changed, 12 insertions(+), 20 deletions(-)

Approvals:
  Thcipriani: Looks good to me, approved
  Bartosz Dziewoński: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/includes/pager/ReverseChronologicalPager.php 
b/includes/pager/ReverseChronologicalPager.php
index af6d039..4895b4f 100644
--- a/includes/pager/ReverseChronologicalPager.php
+++ b/includes/pager/ReverseChronologicalPager.php
@@ -64,12 +64,12 @@
        /**
         * Set and return the mOffset timestamp such that we can get all 
revisions with
         * a timestamp up to the specified parameters.
-        * @param int $year [optional] Year up to which we want revisions. 
Default is current year.
-        * @param int $month [optional] Month up to which we want revisions. 
Default is end of year.
+        * @param int $year Year up to which we want revisions
+        * @param int $month Month up to which we want revisions
         * @param int $day [optional] Day up to which we want revisions. 
Default is end of month.
-        * @return string Timestamp
+        * @return string|null Timestamp or null if year and month are 
false/invalid
         */
-       function getDateCond( $year = -1, $month = -1, $day = -1 ) {
+       function getDateCond( $year, $month, $day = -1 ) {
                $year = intval( $year );
                $month = intval( $month );
                $day = intval( $day );
@@ -78,6 +78,11 @@
                $this->mYear = $year > 0 ? $year : false;
                $this->mMonth = ( $month > 0 && $month < 13 ) ? $month : false;
 
+               // If year and month are false, don't update the mOffset
+               if ( !$this->mYear && !$this->mMonth ) {
+                       return;
+               }
+
                // Given an optional year, month, and day, we need to generate 
a timestamp
                // to use as "WHERE rev_timestamp <= result"
                // Examples: year = 2006      equals < 20070101 (+000000)
diff --git a/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php 
b/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php
index 824b5c4..fc5d660 100644
--- a/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php
+++ b/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php
@@ -19,14 +19,9 @@
 
                $currYear = $timestamp->format( 'Y' );
                $currMonth = $timestamp->format( 'n' );
-               $currYearTimestamp = $db->timestamp( $currYear + 1 . 
'0101000000' );
 
                // Test that getDateCond sets and returns mOffset
-               $this->assertEquals( $pager->getDateCond( 2006 ), 
$pager->mOffset );
-
-               // Test year
-               $pager->getDateCond( 2006 );
-               $this->assertEquals( $pager->mOffset, $db->timestamp( 
'20070101000000' ) );
+               $this->assertEquals( $pager->getDateCond( 2006, 6 ), 
$pager->mOffset );
 
                // Test year and month
                $pager->getDateCond( 2006, 6 );
@@ -44,21 +39,13 @@
                $pager->getDateCond( 2006, 6, 30 );
                $this->assertEquals( $pager->mOffset, $db->timestamp( 
'20060701000000' ) );
 
-               // Test invalid year (should use current year)
-               $pager->getDateCond( -1337 );
-               $this->assertEquals( $pager->mOffset, $currYearTimestamp );
-
-               // Test invalid month
+               // Test invalid month (should use end of year)
                $pager->getDateCond( 2006, -1 );
                $this->assertEquals( $pager->mOffset, $db->timestamp( 
'20070101000000' ) );
 
-               // Test invalid day
+               // Test invalid day (should use end of month)
                $pager->getDateCond( 2006, 6, 1337 );
                $this->assertEquals( $pager->mOffset, $db->timestamp( 
'20060701000000' ) );
-
-               // Test no year or month (should use end of current year)
-               $pager->getDateCond();
-               $this->assertEquals( $pager->mOffset, $currYearTimestamp );
 
                // Test last day of year
                $pager->getDateCond( 2006, 12, 31 );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3a90b3da48e49ec9723b7100a7d92146154f74e3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.28.0-wmf.19
Gerrit-Owner: Kaldari <rkald...@wikimedia.org>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Thcipriani <tcipri...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to