Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki-CVS

SVN: [34625] trunk/phase3/includes/SpecialContributions.php

 

 

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded


greg at svn

May 11, 2008, 1:22 PM

Post #1 of 1 (12 views)
Permalink
SVN: [34625] trunk/phase3/includes/SpecialContributions.php

Revision: 34625
Author: greg
Date: 2008-05-11 20:22:25 +0000 (Sun, 11 May 2008)

Log Message:
-----------
Clean up date formatting per bug 14067, remove assumptions that things like
20051300000000 will work. It's fine for dates-as-integers, but goes horribly
wrong when fed to $dbr->timestamp(), which calls gmmktime(). The latter function
has a bug/feature causing any 0s in the month or day field to cause a month
or day's *subtraction*. We might want to modify timestamp() to handle that, as
I can imagine any MW code would want to rely on such a feature, but that's not
this patch.

Also set a limit for Y2K38 problems, as gmmktime() doesn't like that very much either.

Modified Paths:
--------------
trunk/phase3/includes/SpecialContributions.php

Modified: trunk/phase3/includes/SpecialContributions.php
===================================================================
--- trunk/phase3/includes/SpecialContributions.php 2008-05-11 19:49:08 UTC (rev 34624)
+++ trunk/phase3/includes/SpecialContributions.php 2008-05-11 20:22:25 UTC (rev 34625)
@@ -20,7 +20,7 @@
$year = intval($year);
$month = intval($month);

- $this->year = ($year > 0 && $year < 10000) ? $year : false;
+ $this->year = $year > 0 ? $year : false;
$this->month = ($month > 0 && $month < 13) ? $month : false;
$this->getDateCond();

@@ -38,7 +38,6 @@
function getQueryInfo() {
list( $index, $userCond ) = $this->getUserCond();
$conds = array_merge( array('page_id=rev_page'), $userCond, $this->getNamespaceCond() );
-
return array(
'tables' => array( 'page', 'revision' ),
'fields' => array(
@@ -74,30 +73,50 @@
}

function getDateCond() {
- 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--;
- }
+ // 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_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT);
- $year_end = $year_start;
- } else {
- $month_end = 0;
- $year_end = $year_start + 1;
+ if ( $this->month ) {
+ $month = $this->month + 1;
+ // For December, we want January 1 of the next year
+ if ($month > 12) {
+ $month = 1;
+ $year++;
}
- $ts_end = str_pad($year_end . $month_end, 14, '0' );
+ }
+ else {
+ // No month implies we want up to the end of the year in question
+ $month = 1;
+ $year++;
+ }

- $this->mOffset = $ts_end;
- }
+ if ($year > 2032)
+ $year = 2032;
+ $ymd = (int)sprintf( "%04d%02d01", $year, $month );
+
+ // Y2K38 bug
+ if ($ymd > 20320101)
+ $ymd = 20320101;
+
+ $this->mOffset = $this->mDb->timestamp( "${ymd}000000" );
}

function getIndexField() {
@@ -147,7 +166,7 @@
}

}
- # Is there a visable previous revision?
+ # Is there a visible previous revision?
if( $rev->userCan(Revision::DELETED_TEXT) ) {
$difftext = '(' . $sk->makeKnownLinkObj( $page, $this->messages['diff'], 'diff=prev&oldid='.$row->rev_id ) . ')';
} else {



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS[at]lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.