MediaWiki master
RangeChronologicalPager.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Pager;
22
24use Wikimedia\Timestamp\TimestampException;
25
33
38 protected $rangeConds;
39
41 protected $startOffset;
42
56 public function getDateRangeCond( $startTime, $endTime ) {
57 // Construct the conds array for compatibility with callers and derived classes
58 $this->rangeConds = [];
59
60 try {
61 if ( $startTime !== '' ) {
62 $startTimestamp = MWTimestamp::getInstance( $startTime );
63 $this->startOffset = $this->mDb->timestamp( $startTimestamp->getTimestamp() );
64 $this->rangeConds[] = $this->mDb->buildComparison( '>=',
65 [ $this->getTimestampField() => $this->startOffset ] );
66 }
67
68 if ( $endTime !== '' ) {
69 $endTimestamp = MWTimestamp::getInstance( $endTime );
70 // Turned to use '<' for consistency with the parent class,
71 // add one second for compatibility with existing use cases
72 $endTimestamp->timestamp = $endTimestamp->timestamp->modify( '+1 second' );
73 $this->endOffset = $this->mDb->timestamp( $endTimestamp->getTimestamp() );
74 $this->rangeConds[] = $this->mDb->buildComparison( '<',
75 [ $this->getTimestampField() => $this->endOffset ] );
76
77 // populate existing variables for compatibility with parent
78 $this->mYear = (int)$endTimestamp->format( 'Y' );
79 $this->mMonth = (int)$endTimestamp->format( 'm' );
80 $this->mDay = (int)$endTimestamp->format( 'd' );
81 }
82 } catch ( TimestampException $ex ) {
83 return null;
84 }
85
86 return $this->rangeConds;
87 }
88
96 public function getRangeOffsets() {
98 }
99
103 protected function buildQueryInfo( $offset, $limit, $order ) {
104 [ $tables, $fields, $conds, $fname, $options, $join_conds ] = parent::buildQueryInfo(
105 $offset,
106 $limit,
107 $order
108 );
109 // End of the range has been added by ReverseChronologicalPager
110 if ( $this->startOffset ) {
111 $conds[] = $this->mDb->expr( $this->getTimestampField(), '>=', $this->startOffset );
112 } elseif ( $this->rangeConds ) {
113 // Keep compatibility with some derived classes, T325034
114 $conds = array_merge( $conds, $this->rangeConds );
115 }
116
117 return [ $tables, $fields, $conds, $fname, $options, $join_conds ];
118 }
119}
120
122class_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.