MediaWiki REL1_31
ReverseChronologicalPager.php
Go to the documentation of this file.
1<?php
21use Wikimedia\Timestamp\TimestampException;
22
28abstract class ReverseChronologicalPager extends IndexPager {
30 public $mYear;
31 public $mMonth;
32 public $mDay;
33
34 public function getNavigationBar() {
35 if ( !$this->isNavigationBarShown() ) {
36 return '';
37 }
38
39 if ( isset( $this->mNavigationBar ) ) {
41 }
42
43 $linkTexts = [
44 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit )->escaped(),
45 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit )->escaped(),
46 'first' => $this->msg( 'histlast' )->escaped(),
47 'last' => $this->msg( 'histfirst' )->escaped()
48 ];
49
50 $pagingLinks = $this->getPagingLinks( $linkTexts );
51 $limitLinks = $this->getLimitLinks();
52 $limits = $this->getLanguage()->pipeList( $limitLinks );
53 $firstLastLinks = $this->msg( 'parentheses' )->rawParams( "{$pagingLinks['first']}" .
54 $this->msg( 'pipe-separator' )->escaped() .
55 "{$pagingLinks['last']}" )->escaped();
56
57 $this->mNavigationBar = $firstLastLinks . ' ' .
58 $this->msg( 'viewprevnext' )->rawParams(
59 $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped();
60
62 }
63
73 public function getDateCond( $year, $month, $day = -1 ) {
74 $year = (int)$year;
75 $month = (int)$month;
76 $day = (int)$day;
77
78 // Basic validity checks for year and month
79 // If year and month are invalid, don't update the mOffset
80 if ( $year <= 0 && ( $month <= 0 || $month >= 13 ) ) {
81 return null;
82 }
83
84 // Treat the given time in the wiki timezone and get a UTC timestamp for the database lookup
85 $timestamp = self::getOffsetDate( $year, $month, $day );
86 $timestamp->setTimezone( $this->getConfig()->get( 'Localtimezone' ) );
87
88 try {
89 $this->mYear = (int)$timestamp->format( 'Y' );
90 $this->mMonth = (int)$timestamp->format( 'm' );
91 $this->mDay = (int)$timestamp->format( 'd' );
92 $this->mOffset = $this->mDb->timestamp( $timestamp->getTimestamp() );
93 } catch ( TimestampException $e ) {
94 // Invalid user provided timestamp (T149257)
95 return null;
96 }
97
98 return $this->mOffset;
99 }
100
116 public static function getOffsetDate( $year, $month, $day = -1 ) {
117 // Given an optional year, month, and day, we need to generate a timestamp
118 // to use as "WHERE rev_timestamp <= result"
119 // Examples: year = 2006 equals < 20070101 (+000000)
120 // year=2005, month=1 equals < 20050201
121 // year=2005, month=12 equals < 20060101
122 // year=2005, month=12, day=5 equals < 20051206
123 if ( $year <= 0 ) {
124 // If no year given, assume the current one
125 $timestamp = MWTimestamp::getInstance();
126 $year = $timestamp->format( 'Y' );
127 // If this month hasn't happened yet this year, go back to last year's month
128 if ( $month > $timestamp->format( 'n' ) ) {
129 $year--;
130 }
131 }
132
133 if ( $month && $month > 0 && $month < 13 ) {
134 // Day validity check after we have month and year checked
135 $day = checkdate( $month, $day, $year ) ? $day : false;
136
137 if ( $day && $day > 0 ) {
138 // If we have a day, we want up to the day immediately afterward
139 $day++;
140
141 // Did we overflow the current month?
142 if ( !checkdate( $month, $day, $year ) ) {
143 $day = 1;
144 $month++;
145 }
146 } else {
147 // If no day, assume beginning of next month
148 $day = 1;
149 $month++;
150 }
151
152 // Did we overflow the current year?
153 if ( $month > 12 ) {
154 $month = 1;
155 $year++;
156 }
157
158 } else {
159 // No month implies we want up to the end of the year in question
160 $month = 1;
161 $day = 1;
162 $year++;
163 }
164
165 // Y2K38 bug
166 if ( $year > 2032 ) {
167 $year = 2032;
168 }
169
170 $ymd = (int)sprintf( "%04d%02d%02d", $year, $month, $day );
171
172 if ( $ymd > 20320101 ) {
173 $ymd = 20320101;
174 }
175
176 return MWTimestamp::getInstance( "${ymd}000000" );
177 }
178}
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
IndexPager is an efficient pager which uses a (roughly unique) index in the data set to implement pag...
getPagingLinks( $linkTexts, $disabledTexts=[])
Get paging links.
isNavigationBarShown()
Returns whether to show the "navigation bar".
const DIR_DESCENDING
Efficient paging for SQL queries.
getDateCond( $year, $month, $day=-1)
Set and return the mOffset timestamp such that we can get all revisions with a timestamp up to the sp...
static getOffsetDate( $year, $month, $day=-1)
Core logic of determining the mOffset timestamp such that we can get all items with a timestamp up to...
returning false will NOT prevent logging $e
Definition hooks.txt:2176