MediaWiki master
RangeChronologicalPager.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Pager;
8
10use Wikimedia\Timestamp\TimestampException;
11
19
24 protected $rangeConds;
25
27 protected $startOffset;
28
42 public function getDateRangeCond( $startTime, $endTime ) {
43 // Construct the conds array for compatibility with callers and derived classes
44 $this->rangeConds = [];
45
46 try {
47 if ( $startTime !== '' ) {
48 $startTimestamp = MWTimestamp::getInstance( $startTime );
49 $this->startOffset = $this->mDb->timestamp( $startTimestamp->getTimestamp() );
50 $this->rangeConds[] = $this->mDb->buildComparison( '>=',
51 [ $this->getTimestampField() => $this->startOffset ] );
52 }
53
54 if ( $endTime !== '' ) {
55 $endTimestamp = MWTimestamp::getInstance( $endTime );
56 // Turned to use '<' for consistency with the parent class,
57 // add one second for compatibility with existing use cases
58 $endTimestamp->timestamp = $endTimestamp->timestamp->modify( '+1 second' );
59 $this->endOffset = $this->mDb->timestamp( $endTimestamp->getTimestamp() );
60 $this->rangeConds[] = $this->mDb->buildComparison( '<',
61 [ $this->getTimestampField() => $this->endOffset ] );
62
63 // populate existing variables for compatibility with parent
64 $this->mYear = (int)$endTimestamp->format( 'Y' );
65 $this->mMonth = (int)$endTimestamp->format( 'm' );
66 $this->mDay = (int)$endTimestamp->format( 'd' );
67 }
68 } catch ( TimestampException ) {
69 return null;
70 }
71
72 return $this->rangeConds;
73 }
74
82 public function getRangeOffsets() {
84 }
85
89 protected function buildQueryInfo( $offset, $limit, $order ) {
90 [ $tables, $fields, $conds, $fname, $options, $join_conds ] = parent::buildQueryInfo(
91 $offset,
92 $limit,
93 $order
94 );
95 // End of the range has been added by ReverseChronologicalPager
96 if ( $this->startOffset ) {
97 $conds[] = $this->mDb->expr( $this->getTimestampField(), '>=', $this->startOffset );
98 } elseif ( $this->rangeConds ) {
99 // Keep compatibility with some derived classes, T325034
100 $conds = array_merge( $conds, $this->rangeConds );
101 }
102
103 return [ $tables, $fields, $conds, $fname, $options, $join_conds ];
104 }
105}
106
108class_alias( RangeChronologicalPager::class, 'RangeChronologicalPager' );
Pager for filtering by a range of dates.
getRangeOffsets()
Return the range of date offsets, in the format of [ endOffset, startOffset ].
getDateRangeCond( $startTime, $endTime)
Set and return a date range condition using timestamps provided by the user.
buildQueryInfo( $offset, $limit, $order)
Build variables to use by the database wrapper.For b/c, query direction is true for ascending and fal...
IndexPager with a formatted navigation bar.
getTimestampField()
Returns the name of the timestamp field.
Library for creating and parsing MW-style timestamps.