* Better yet, move getDateCond() to reverseChronologicalPager to avoid duplication.
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 1 Aug 2008 22:38:45 +0000 (22:38 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 1 Aug 2008 22:38:45 +0000 (22:38 +0000)
* Make LogPager use getDateCond(). This also means that greg's fixes to contribs apply to logs as well.

includes/LogEventsList.php
includes/Pager.php
includes/specials/SpecialContributions.php

index d49f636..f4b7848 100644 (file)
@@ -429,14 +429,14 @@ class LogPager extends ReverseChronologicalPager {
                $this->limitType( $type );
                $this->limitUser( $user );
                $this->limitTitle( $title, $pattern );
-               $this->limitDate( $y, $m );
+               $this->getDateCond( $y, $m );
        }
 
        function getDefaultQuery() {
                $query = parent::getDefaultQuery();
                $query['type'] = $this->type;
-               $query['month'] = $this->month;
-               $query['year'] = $this->year;
+               $query['month'] = $this->mMonth;
+               $query['year'] = $this->mYear;
                return $query;
        }
 
@@ -527,45 +527,6 @@ class LogPager extends ReverseChronologicalPager {
                }
        }
 
-       /**
-        * Set the log reader to return only entries from given date.
-        * @param int $year
-        * @param int $month
-        * @private
-        */
-       function limitDate( $year, $month ) {
-               $year = intval($year);
-               $month = intval($month);
-
-               $this->year = ($year > 0 && $year < 10000) ? $year : '';
-               $this->month = ($month > 0 && $month < 13) ? $month : '';
-
-               if( $this->year || $this->month ) {
-                       // Assume this year if only a month is given
-                       if( $this->year ) {
-                               $year_start = $this->year;
-                       } else {
-                               $year_start = substr( wfTimestampNow(), 0, 4 );
-                               $thisMonth = gmdate( 'n' );
-                               if( $this->month > $thisMonth ) {
-                                       // Future contributions aren't supposed to happen. :)
-                                       $year_start--;
-                               }
-                       }
-
-                       if( $this->month ) {
-                               $month_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT);
-                               $year_end = $year_start;
-                       } else {
-                               $month_end = 0;
-                               $year_end = $year_start + 1;
-                       }
-                       $ts_end = str_pad($year_end . $month_end, 14, '0' );
-
-                       $this->mOffset = $ts_end;
-               }
-       }
-
        function getQueryInfo() {
                $this->mConds[] = 'user_id = log_user';
                # Don't use the wrong logging index
index 62c4e55..c4d55b6 100644 (file)
@@ -564,6 +564,8 @@ abstract class AlphabeticPager extends IndexPager {
  */
 abstract class ReverseChronologicalPager extends IndexPager {
        public $mDefaultDirection = true;
+       public $mYear;
+       public $mMonth;
 
        function __construct() {
                parent::__construct();
@@ -591,6 +593,53 @@ abstract class ReverseChronologicalPager extends IndexPager {
                        wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
                return $this->mNavigationBar;
        }
+       
+       function getDateCond( $year, $month ) {
+               $year = intval($year);
+               $month = intval($month);
+               // Basic validity checks
+               $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
+               // 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
+               if ( !$this->mYear && !$this->mMonth ) {
+                       return;
+               }
+               if ( $this->mYear ) {
+                       $year = $this->mYear;
+               } else {
+                       // If no year given, assume the current one
+                       $year = gmdate( 'Y' );
+                       // If this month hasn't happened yet this year, go back to last year's month
+                       if( $this->mMonth > gmdate( 'n' ) ) {
+                               $year--;
+                       }
+               }
+               if ( $this->mMonth ) {
+                       $month = $this->mMonth + 1;
+                       // For December, we want January 1 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;
+                       $year++;
+               }
+               // Y2K38 bug
+               if ( $year > 2032 ) {
+                       $year = 2032;
+               }
+               $ymd = (int)sprintf( "%04d%02d01", $year, $month );
+               if ( $ymd > 20320101 ) {
+                       $ymd = 20320101;
+               }
+               $this->mOffset = $this->mDb->timestamp( "${ymd}000000" );
+       }
 }
 
 /**
index d9f708a..34c93d2 100644 (file)
@@ -12,7 +12,7 @@
 class ContribsPager extends ReverseChronologicalPager {
        public $mDefaultDirection = true;
        var $messages, $target;
-       var $namespace = '', $year = '', $month = '', $mDb;
+       var $namespace = '', $mDb;
 
        function __construct( $target, $namespace = false, $year = false, $month = false ) {
                parent::__construct();
@@ -30,8 +30,8 @@ class ContribsPager extends ReverseChronologicalPager {
        function getDefaultQuery() {
                $query = parent::getDefaultQuery();
                $query['target'] = $this->target;
-               $query['month'] = $this->month;
-               $query['year'] = $this->year;
+               $query['month'] = $this->mMonth;
+               $query['year'] = $this->mYear;
                return $query;
        }
 
@@ -74,53 +74,6 @@ class ContribsPager extends ReverseChronologicalPager {
                }
        }
 
-       function getDateCond( $year, $month ) {
-               $year = intval($year);
-               $month = intval($month);
-               // Basic validity checks
-               $this->year = $year > 0 ? $year : false;
-               $this->month = ($month > 0 && $month < 13) ? $month : false;
-               // Given an optional year and month, 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
-               if ( !$this->year && !$this->month ) {
-                       return;
-               }
-               if ( $this->year ) {
-                       $year = $this->year;
-               } else {
-                       // If no year given, assume the current one
-                       $year = gmdate( 'Y' );
-                       // If this month hasn't happened yet this year, go back to last year's month
-                       if( $this->month > gmdate( 'n' ) ) {
-                               $year--;
-                       }
-               }
-               if ( $this->month ) {
-                       $month = $this->month + 1;
-                       // For December, we want January 1 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;
-                       $year++;
-               }
-               // Y2K38 bug
-               if ( $year > 2032 ) {
-                       $year = 2032;
-               }
-               $ymd = (int)sprintf( "%04d%02d01", $year, $month );
-               if ( $ymd > 20320101 ) {
-                       $ymd = 20320101;
-               }
-               $this->mOffset = $this->mDb->timestamp( "${ymd}000000" );
-       }
-
        function getIndexField() {
                return 'rev_timestamp';
        }