wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / pager / ReverseChronologicalPager.php
blobee6e26c02f4cfdc3aea7e31126e829054fed59b2
1 <?php
2 /**
3 * Efficient paging for SQL queries.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Pager
24 /**
25 * IndexPager with a formatted navigation bar
26 * @ingroup Pager
28 abstract class ReverseChronologicalPager extends IndexPager {
29 public $mDefaultDirection = IndexPager::DIR_DESCENDING;
30 public $mYear;
31 public $mMonth;
33 function getNavigationBar() {
34 if ( !$this->isNavigationBarShown() ) {
35 return '';
38 if ( isset( $this->mNavigationBar ) ) {
39 return $this->mNavigationBar;
42 $linkTexts = array(
43 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit )->escaped(),
44 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit )->escaped(),
45 'first' => $this->msg( 'histlast' )->escaped(),
46 'last' => $this->msg( 'histfirst' )->escaped()
49 $pagingLinks = $this->getPagingLinks( $linkTexts );
50 $limitLinks = $this->getLimitLinks();
51 $limits = $this->getLanguage()->pipeList( $limitLinks );
52 $firstLastLinks = $this->msg( 'parentheses' )->rawParams( "{$pagingLinks['first']}" .
53 $this->msg( 'pipe-separator' )->escaped() .
54 "{$pagingLinks['last']}" )->escaped();
56 $this->mNavigationBar = $firstLastLinks . ' ' .
57 $this->msg( 'viewprevnext' )->rawParams(
58 $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped();
60 return $this->mNavigationBar;
63 function getDateCond( $year, $month ) {
64 $year = intval( $year );
65 $month = intval( $month );
67 // Basic validity checks
68 $this->mYear = $year > 0 ? $year : false;
69 $this->mMonth = ( $month > 0 && $month < 13 ) ? $month : false;
71 // Given an optional year and month, we need to generate a timestamp
72 // to use as "WHERE rev_timestamp <= result"
73 // Examples: year = 2006 equals < 20070101 (+000000)
74 // year=2005, month=1 equals < 20050201
75 // year=2005, month=12 equals < 20060101
76 if ( !$this->mYear && !$this->mMonth ) {
77 return;
80 if ( $this->mYear ) {
81 $year = $this->mYear;
82 } else {
83 // If no year given, assume the current one
84 $timestamp = MWTimestamp::getInstance();
85 $year = $timestamp->format( 'Y' );
86 // If this month hasn't happened yet this year, go back to last year's month
87 if ( $this->mMonth > $timestamp->format( 'n' ) ) {
88 $year--;
92 if ( $this->mMonth ) {
93 $month = $this->mMonth + 1;
94 // For December, we want January 1 of the next year
95 if ( $month > 12 ) {
96 $month = 1;
97 $year++;
99 } else {
100 // No month implies we want up to the end of the year in question
101 $month = 1;
102 $year++;
105 // Y2K38 bug
106 if ( $year > 2032 ) {
107 $year = 2032;
110 $ymd = (int)sprintf( "%04d%02d01", $year, $month );
112 if ( $ymd > 20320101 ) {
113 $ymd = 20320101;
116 // Treat the given time in the wiki timezone and get a UTC timestamp for the database lookup
117 $timestamp = MWTimestamp::getInstance( "${ymd}000000" );
118 $timestamp->setTimeZone( $this->getConfig()->get( 'Localtimezone' ) );
120 $this->mOffset = $this->mDb->timestamp( $timestamp->getTimestamp() );