MediaWiki REL1_33
ReverseChronologicalPager.php
Go to the documentation of this file.
1<?php
22
28abstract class ReverseChronologicalPager extends IndexPager {
32 public $mYear;
34 public $mMonth;
36 public $mDay;
37
38 public function getNavigationBar() {
39 if ( !$this->isNavigationBarShown() ) {
40 return '';
41 }
42
43 if ( isset( $this->mNavigationBar ) ) {
45 }
46
47 $linkTexts = [
48 'prev' => $this->msg( 'pager-newer-n' )->numParams( $this->mLimit )->escaped(),
49 'next' => $this->msg( 'pager-older-n' )->numParams( $this->mLimit )->escaped(),
50 'first' => $this->msg( 'histlast' )->escaped(),
51 'last' => $this->msg( 'histfirst' )->escaped()
52 ];
53
54 $pagingLinks = $this->getPagingLinks( $linkTexts );
55 $limitLinks = $this->getLimitLinks();
56 $limits = $this->getLanguage()->pipeList( $limitLinks );
57 $firstLastLinks = $this->msg( 'parentheses' )->rawParams( "{$pagingLinks['first']}" .
58 $this->msg( 'pipe-separator' )->escaped() .
59 "{$pagingLinks['last']}" )->escaped();
60
61 $this->mNavigationBar = $firstLastLinks . ' ' .
62 $this->msg( 'viewprevnext' )->rawParams(
63 $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped();
64
66 }
67
77 public function getDateCond( $year, $month, $day = -1 ) {
78 $year = (int)$year;
79 $month = (int)$month;
80 $day = (int)$day;
81
82 // Basic validity checks for year and month
83 // If year and month are invalid, don't update the mOffset
84 if ( $year <= 0 && ( $month <= 0 || $month >= 13 ) ) {
85 return null;
86 }
87
88 $timestamp = self::getOffsetDate( $year, $month, $day );
89
90 try {
91 // The timestamp used for DB queries is at midnight of the *next* day after the selected date.
92 $selectedDate = new DateTime( $timestamp->getTimestamp( TS_ISO_8601 ) );
93 $selectedDate = $selectedDate->modify( '-1 day' );
94
95 $this->mYear = (int)$selectedDate->format( 'Y' );
96 $this->mMonth = (int)$selectedDate->format( 'm' );
97 $this->mDay = (int)$selectedDate->format( 'd' );
98 $this->mOffset = $this->mDb->timestamp( $timestamp->getTimestamp() );
99 } catch ( TimestampException $e ) {
100 // Invalid user provided timestamp (T149257)
101 return null;
102 }
103
104 return $this->mOffset;
105 }
106
122 public static function getOffsetDate( $year, $month, $day = -1 ) {
123 // Given an optional year, month, and day, we need to generate a timestamp
124 // to use as "WHERE rev_timestamp <= result"
125 // Examples: year = 2006 equals < 20070101 (+000000)
126 // year=2005, month=1 equals < 20050201
127 // year=2005, month=12 equals < 20060101
128 // year=2005, month=12, day=5 equals < 20051206
129 if ( $year <= 0 ) {
130 // If no year given, assume the current one
131 $timestamp = MWTimestamp::getInstance();
132 $year = $timestamp->format( 'Y' );
133 // If this month hasn't happened yet this year, go back to last year's month
134 if ( $month > $timestamp->format( 'n' ) ) {
135 $year--;
136 }
137 }
138
139 if ( $month && $month > 0 && $month < 13 ) {
140 // Day validity check after we have month and year checked
141 $day = checkdate( $month, $day, $year ) ? $day : false;
142
143 if ( $day && $day > 0 ) {
144 // If we have a day, we want up to the day immediately afterward
145 $day++;
146
147 // Did we overflow the current month?
148 if ( !checkdate( $month, $day, $year ) ) {
149 $day = 1;
150 $month++;
151 }
152 } else {
153 // If no day, assume beginning of next month
154 $day = 1;
155 $month++;
156 }
157
158 // Did we overflow the current year?
159 if ( $month > 12 ) {
160 $month = 1;
161 $year++;
162 }
163
164 } else {
165 // No month implies we want up to the end of the year in question
166 $month = 1;
167 $day = 1;
168 $year++;
169 }
170
171 // Y2K38 bug
172 if ( $year > 2032 ) {
173 $year = 2032;
174 }
175
176 $ymd = (int)sprintf( "%04d%02d%02d", $year, $month, $day );
177
178 if ( $ymd > 20320101 ) {
179 $ymd = 20320101;
180 }
181
182 return MWTimestamp::getInstance( "${ymd}000000" );
183 }
184}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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...
string $mNavigationBar
getPagingLinks( $linkTexts, $disabledTexts=[])
Get paging links.
mixed $mOffset
The starting point to enumerate entries.
isNavigationBarShown()
Returns whether to show the "navigation bar".
const DIR_DESCENDING
Backwards-compatible constant for $mDefaultDirection field (do not change)
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:2175