MediaWiki  master
RangeChronologicalPager.php
Go to the documentation of this file.
1 <?php
20 use Wikimedia\Timestamp\TimestampException;
21 
29 
34  protected $rangeConds;
35 
37  protected $startOffset;
38 
52  public function getDateRangeCond( $startTime, $endTime ) {
53  // Construct the conds array for compatibility with callers and derived classes
54  $this->rangeConds = [];
55 
56  try {
57  if ( $startTime !== '' ) {
58  $startTimestamp = MWTimestamp::getInstance( $startTime );
59  $this->startOffset = $this->mDb->timestamp( $startTimestamp->getTimestamp() );
60  $this->rangeConds[] = $this->mDb->buildComparison( '>=',
61  [ $this->getTimestampField() => $this->startOffset ] );
62  }
63 
64  if ( $endTime !== '' ) {
65  $endTimestamp = MWTimestamp::getInstance( $endTime );
66  // Turned to use '<' for consistency with the parent class,
67  // add one second for compatibility with existing use cases
68  $endTimestamp->timestamp = $endTimestamp->timestamp->modify( '+1 second' );
69  $this->endOffset = $this->mDb->timestamp( $endTimestamp->getTimestamp() );
70  $this->rangeConds[] = $this->mDb->buildComparison( '<',
71  [ $this->getTimestampField() => $this->endOffset ] );
72 
73  // populate existing variables for compatibility with parent
74  $this->mYear = (int)$endTimestamp->format( 'Y' );
75  $this->mMonth = (int)$endTimestamp->format( 'm' );
76  $this->mDay = (int)$endTimestamp->format( 'd' );
77  }
78  } catch ( TimestampException $ex ) {
79  return null;
80  }
81 
82  return $this->rangeConds;
83  }
84 
92  public function getRangeOffsets() {
94  }
95 
99  protected function buildQueryInfo( $offset, $limit, $order ) {
100  [ $tables, $fields, $conds, $fname, $options, $join_conds ] = parent::buildQueryInfo(
101  $offset,
102  $limit,
103  $order
104  );
105  // End of the range has been added by ReverseChronologicalPager
106  if ( $this->startOffset ) {
107  $conds[] = $this->mDb->buildComparison( '>=', [ $this->getTimestampField() => $this->startOffset ] );
108  } elseif ( $this->rangeConds ) {
109  // Keep compatibility with some derived classes, T325034
110  $conds = array_merge( $conds, $this->rangeConds );
111  }
112 
113  return [ $tables, $fields, $conds, $fname, $options, $join_conds ];
114  }
115 }
static getInstance( $ts=false)
Get a timestamp instance in GMT.
Definition: MWTimestamp.php:47
Pager for filtering by a range of dates.
buildQueryInfo( $offset, $limit, $order)
Build variables to use by the database wrapper.For b/c, query direction is true for ascending and fal...
getDateRangeCond( $startTime, $endTime)
Set and return a date range condition using timestamps provided by the user.
getRangeOffsets()
Return the range of date offsets, in the format of [ endOffset, startOffset ].
IndexPager with a formatted navigation bar.
getTimestampField()
Returns the name of the timestamp field.