MediaWiki
REL1_34
ReverseChronologicalPager.php
Go to the documentation of this file.
1
<?php
21
use Wikimedia\Timestamp\TimestampException;
22
28
abstract
class
ReverseChronologicalPager
extends
IndexPager
{
30
public
$mDefaultDirection
=
IndexPager::DIR_DESCENDING
;
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 ) ) {
44
return
$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
65
return
$this->mNavigationBar
;
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
}
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition
ContextSource.php:168
ContextSource\getLanguage
getLanguage()
Definition
ContextSource.php:128
IndexPager
IndexPager is an efficient pager which uses a (roughly unique) index in the data set to implement pag...
Definition
IndexPager.php:72
IndexPager\$mNavigationBar
string $mNavigationBar
Definition
IndexPager.php:146
IndexPager\getPagingLinks
getPagingLinks( $linkTexts, $disabledTexts=[])
Get paging links.
Definition
IndexPager.php:676
IndexPager\$mOffset
mixed $mOffset
The starting point to enumerate entries.
Definition
IndexPager.php:90
IndexPager\isNavigationBarShown
isNavigationBarShown()
Returns whether to show the "navigation bar".
Definition
IndexPager.php:658
IndexPager\DIR_DESCENDING
const DIR_DESCENDING
Backwards-compatible constant for $mDefaultDirection field (do not change)
Definition
IndexPager.php:76
IndexPager\getLimitLinks
getLimitLinks()
Definition
IndexPager.php:697
ReverseChronologicalPager
Efficient paging for SQL queries.
Definition
ReverseChronologicalPager.php:28
ReverseChronologicalPager\getDateCond
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...
Definition
ReverseChronologicalPager.php:77
ReverseChronologicalPager\getOffsetDate
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...
Definition
ReverseChronologicalPager.php:122
ReverseChronologicalPager\$mMonth
int $mMonth
Definition
ReverseChronologicalPager.php:34
ReverseChronologicalPager\$mDay
int $mDay
Definition
ReverseChronologicalPager.php:36
ReverseChronologicalPager\$mDefaultDirection
bool $mDefaultDirection
Definition
ReverseChronologicalPager.php:30
ReverseChronologicalPager\$mYear
int $mYear
Definition
ReverseChronologicalPager.php:32
ReverseChronologicalPager\getNavigationBar
getNavigationBar()
Definition
ReverseChronologicalPager.php:38
includes
pager
ReverseChronologicalPager.php
Generated on Mon Nov 25 2024 16:05:32 for MediaWiki by
1.10.0