MediaWiki REL1_39
RangeChronologicalPager.php
Go to the documentation of this file.
1<?php
21use Wikimedia\Timestamp\TimestampException;
22
29
31 protected $rangeConds = [];
32
46 public function getDateRangeCond( $startStamp, $endStamp ) {
47 $this->rangeConds = [];
48
49 try {
50 if ( $startStamp !== '' ) {
51 $startTimestamp = MWTimestamp::getInstance( $startStamp );
52 $startOffset = $this->mDb->timestamp( $startTimestamp->getTimestamp() );
53 $this->rangeConds[] = $this->mIndexField . '>=' . $this->mDb->addQuotes( $startOffset );
54 }
55
56 if ( $endStamp !== '' ) {
57 $endTimestamp = MWTimestamp::getInstance( $endStamp );
58 $endOffset = $this->mDb->timestamp( $endTimestamp->getTimestamp() );
59 $this->rangeConds[] = $this->mIndexField . '<=' . $this->mDb->addQuotes( $endOffset );
60
61 // populate existing variables for compatibility with parent
62 $this->mYear = (int)$endTimestamp->format( 'Y' );
63 $this->mMonth = (int)$endTimestamp->format( 'm' );
64 $this->mDay = (int)$endTimestamp->format( 'd' );
65 $this->mOffset = $endOffset;
66 }
67 } catch ( TimestampException $ex ) {
68 return null;
69 }
70
71 return $this->rangeConds;
72 }
73
85 public function getDateCond( $year, $month, $day = -1 ) {
86 // run through getDateRangeCond so rangeConds, mOffset, ... are set
87 $legacyTimestamp = self::getOffsetDate( $year, $month, $day );
88 // ReverseChronologicalPager uses strict inequality for the end date ('<'),
89 // but this class uses '<=' and expects extending classes to handle modifying the end date.
90 // Therefore, we need to subtract one second from the output of getOffsetDate to make it
91 // work with the '<=' inequality used in this class.
92 $legacyTimestamp->timestamp = $legacyTimestamp->timestamp->modify( '-1 second' );
93 $this->getDateRangeCond( '', $legacyTimestamp->getTimestamp( TS_MW ) );
94 return $this->mOffset;
95 }
96
107 protected function buildQueryInfo( $offset, $limit, $order ) {
108 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = parent::buildQueryInfo(
109 $offset,
110 $limit,
111 $order
112 );
113
114 if ( $this->rangeConds ) {
115 $conds = array_merge( $conds, $this->rangeConds );
116 }
117
118 return [ $tables, $fields, $conds, $fname, $options, $join_conds ];
119 }
120}
mixed $mOffset
The starting point to enumerate entries.
Pager for filtering by a range of dates.
buildQueryInfo( $offset, $limit, $order)
Build variables to use by the database wrapper.
getDateRangeCond( $startStamp, $endStamp)
Set and return a date range condition using timestamps provided by the user.
getDateCond( $year, $month, $day=-1)
Takes ReverseChronologicalPager::getDateCond parameters and repurposes them to work with timestamp-ba...
Efficient paging for SQL queries.
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...