From 250e1244ca785bd8a4eef3f9e1b24f424bc5be02 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 1 Aug 2008 22:38:45 +0000 Subject: [PATCH] * Better yet, move getDateCond() to reverseChronologicalPager to avoid duplication. * Make LogPager use getDateCond(). This also means that greg's fixes to contribs apply to logs as well. --- includes/LogEventsList.php | 45 ++---------------- includes/Pager.php | 49 ++++++++++++++++++++ includes/specials/SpecialContributions.php | 53 ++-------------------- 3 files changed, 55 insertions(+), 92 deletions(-) diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index d49f636b4c..f4b7848aa3 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -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 diff --git a/includes/Pager.php b/includes/Pager.php index 62c4e551a2..c4d55b6ea6 100644 --- a/includes/Pager.php +++ b/includes/Pager.php @@ -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" ); + } } /** diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index d9f708a304..34c93d220d 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -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'; } -- 2.20.1