Sn1per has uploaded a new change for review.

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

Change subject: Add day to date filter for ReverseChronologicalPager
......................................................................

Add day to date filter for ReverseChronologicalPager

Filter by days of months.

Bug: T120733
Change-Id: I8e684f067d792b07137341d63cd2e54a18c51a7d
---
M includes/pager/ReverseChronologicalPager.php
1 file changed, 33 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/36/260636/1

diff --git a/includes/pager/ReverseChronologicalPager.php 
b/includes/pager/ReverseChronologicalPager.php
index ee6e26c..50d6ace 100644
--- a/includes/pager/ReverseChronologicalPager.php
+++ b/includes/pager/ReverseChronologicalPager.php
@@ -29,6 +29,7 @@
        public $mDefaultDirection = IndexPager::DIR_DESCENDING;
        public $mYear;
        public $mMonth;
+       public $mDay;
 
        function getNavigationBar() {
                if ( !$this->isNavigationBarShown() ) {
@@ -60,19 +61,21 @@
                return $this->mNavigationBar;
        }
 
-       function getDateCond( $year, $month ) {
+       function getDateCond( $year, $month, $day = 0 ) {
                $year = intval( $year );
                $month = intval( $month );
+               $day = intval( $day );
 
-               // Basic validity checks
+               // Basic validity checks for year and month
                $this->mYear = $year > 0 ? $year : false;
                $this->mMonth = ( $month > 0 && $month < 13 ) ? $month : false;
 
-               // Given an optional year and month, we need to generate a 
timestamp
+               // 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)
-               // year=2005, month=1    equals < 20050201
-               // year=2005, month=12   equals < 20060101
+               // Examples: year = 2006      equals < 20070101 (+000000)
+               // year=2005, month=1         equals < 20050201
+               // year=2005, month=12        equals < 20060101
+               // year=2005, month=12, day=5 equals < 20051206
                if ( !$this->mYear && !$this->mMonth ) {
                        return;
                }
@@ -90,15 +93,36 @@
                }
 
                if ( $this->mMonth ) {
-                       $month = $this->mMonth + 1;
-                       // For December, we want January 1 of the next year
+                       $month = $this->mMonth;
+
+                       // Day validity check after we have month and year 
checked
+                       $this->mDay = checkdate( $month, $day, $year) ? $day : 
false;
+
+                       if ( $this->mDay ) {
+                               // If we have a day we want the day immediately 
afterward
+                               $day = $this->mDay + 1;
+
+                               // Did we overflow the current month?
+                               if ( !checkdate( $month, $day, $year ) ) {
+                                       $day = 1;
+                                       $month++;
+                               }
+                       } else {
+                               // If no day, assume beginning of next month
+                               $day = 1;
+                               $month++;
+                       }
+
+                       // For December, we want January of the next year
                        if ( $month > 12 ) {
                                $month = 1;
                                $year++;
                        }
+
                } else {
                        // No month implies we want up to the end of the year 
in question
                        $month = 1;
+                       $day = 1;
                        $year++;
                }
 
@@ -107,7 +131,7 @@
                        $year = 2032;
                }
 
-               $ymd = (int)sprintf( "%04d%02d01", $year, $month );
+               $ymd = (int)sprintf( "%04d%02d%02d", $year, $month, $day );
 
                if ( $ymd > 20320101 ) {
                        $ymd = 20320101;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e684f067d792b07137341d63cd2e54a18c51a7d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Sn1per <geof...@gmail.com>

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

Reply via email to