MediaWiki  REL1_24
ReverseChronologicalPager.php
Go to the documentation of this file.
00001 <?php
00028 abstract class ReverseChronologicalPager extends IndexPager {
00029     public $mDefaultDirection = IndexPager::DIR_DESCENDING;
00030     public $mYear;
00031     public $mMonth;
00032 
00033     function getNavigationBar() {
00034         if ( !$this->isNavigationBarShown() ) {
00035             return '';
00036         }
00037 
00038         if ( isset( $this->mNavigationBar ) ) {
00039             return $this->mNavigationBar;
00040         }
00041 
00042         $linkTexts = array(
00043             'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit )->escaped(),
00044             'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit )->escaped(),
00045             'first' => $this->msg( 'histlast' )->escaped(),
00046             'last' => $this->msg( 'histfirst' )->escaped()
00047         );
00048 
00049         $pagingLinks = $this->getPagingLinks( $linkTexts );
00050         $limitLinks = $this->getLimitLinks();
00051         $limits = $this->getLanguage()->pipeList( $limitLinks );
00052         $firstLastLinks = $this->msg( 'parentheses' )->rawParams( "{$pagingLinks['first']}" .
00053             $this->msg( 'pipe-separator' )->escaped() .
00054             "{$pagingLinks['last']}" )->escaped();
00055 
00056         $this->mNavigationBar = $firstLastLinks . ' ' .
00057             $this->msg( 'viewprevnext' )->rawParams(
00058                 $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped();
00059 
00060         return $this->mNavigationBar;
00061     }
00062 
00063     function getDateCond( $year, $month ) {
00064         $year = intval( $year );
00065         $month = intval( $month );
00066 
00067         // Basic validity checks
00068         $this->mYear = $year > 0 ? $year : false;
00069         $this->mMonth = ( $month > 0 && $month < 13 ) ? $month : false;
00070 
00071         // Given an optional year and month, we need to generate a timestamp
00072         // to use as "WHERE rev_timestamp <= result"
00073         // Examples: year = 2006 equals < 20070101 (+000000)
00074         // year=2005, month=1    equals < 20050201
00075         // year=2005, month=12   equals < 20060101
00076         if ( !$this->mYear && !$this->mMonth ) {
00077             return;
00078         }
00079 
00080         if ( $this->mYear ) {
00081             $year = $this->mYear;
00082         } else {
00083             // If no year given, assume the current one
00084             $timestamp = MWTimestamp::getInstance();
00085             $year = $timestamp->format( 'Y' );
00086             // If this month hasn't happened yet this year, go back to last year's month
00087             if ( $this->mMonth > $timestamp->format( 'n' ) ) {
00088                 $year--;
00089             }
00090         }
00091 
00092         if ( $this->mMonth ) {
00093             $month = $this->mMonth + 1;
00094             // For December, we want January 1 of the next year
00095             if ( $month > 12 ) {
00096                 $month = 1;
00097                 $year++;
00098             }
00099         } else {
00100             // No month implies we want up to the end of the year in question
00101             $month = 1;
00102             $year++;
00103         }
00104 
00105         // Y2K38 bug
00106         if ( $year > 2032 ) {
00107             $year = 2032;
00108         }
00109 
00110         $ymd = (int)sprintf( "%04d%02d01", $year, $month );
00111 
00112         if ( $ymd > 20320101 ) {
00113             $ymd = 20320101;
00114         }
00115 
00116         $this->mOffset = $this->mDb->timestamp( "${ymd}000000" );
00117     }
00118 }