X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/pager/RangeChronologicalPager.php diff --git a/includes/pager/RangeChronologicalPager.php b/includes/pager/RangeChronologicalPager.php new file mode 100644 index 00000000..d3cb5668 --- /dev/null +++ b/includes/pager/RangeChronologicalPager.php @@ -0,0 +1,114 @@ +rangeConds = []; + + try { + if ( $startStamp !== '' ) { + $startTimestamp = MWTimestamp::getInstance( $startStamp ); + $startTimestamp->setTimezone( $this->getConfig()->get( 'Localtimezone' ) ); + $startOffset = $this->mDb->timestamp( $startTimestamp->getTimestamp() ); + $this->rangeConds[] = $this->mIndexField . '>=' . $this->mDb->addQuotes( $startOffset ); + } + + if ( $endStamp !== '' ) { + $endTimestamp = MWTimestamp::getInstance( $endStamp ); + $endTimestamp->setTimezone( $this->getConfig()->get( 'Localtimezone' ) ); + $endOffset = $this->mDb->timestamp( $endTimestamp->getTimestamp() ); + $this->rangeConds[] = $this->mIndexField . '<=' . $this->mDb->addQuotes( $endOffset ); + + // populate existing variables for compatibility with parent + $this->mYear = (int)$endTimestamp->format( 'Y' ); + $this->mMonth = (int)$endTimestamp->format( 'm' ); + $this->mDay = (int)$endTimestamp->format( 'd' ); + $this->mOffset = $endOffset; + } + } catch ( TimestampException $ex ) { + return null; + } + + return $this->rangeConds; + } + + /** + * Takes ReverseChronologicalPager::getDateCond parameters and repurposes + * them to work with timestamp-based getDateRangeCond. + * + * @param int $year Year up to which we want revisions + * @param int $month Month up to which we want revisions + * @param int $day [optional] Day up to which we want revisions. Default is end of month. + * @return string|null Timestamp or null if year and month are false/invalid + */ + public function getDateCond( $year, $month, $day = -1 ) { + // run through getDateRangeCond so rangeConds, mOffset, ... are set + $legacyTimestamp = self::getOffsetDate( $year, $month, $day ); + // ReverseChronologicalPager uses strict inequality for the end date ('<'), + // but this class uses '<=' and expects extending classes to handle modifying the end date. + // Therefore, we need to subtract one second from the output of getOffsetDate to make it + // work with the '<=' inequality used in this class. + $legacyTimestamp->timestamp = $legacyTimestamp->timestamp->modify( '-1 second' ); + $this->getDateRangeCond( '', $legacyTimestamp->getTimestamp( TS_MW ) ); + return $this->mOffset; + } + + /** + * Build variables to use by the database wrapper. + * + * @param string $offset Index offset, inclusive + * @param int $limit Exact query limit + * @param bool $descending Query direction, false for ascending, true for descending + * @return array + */ + protected function buildQueryInfo( $offset, $limit, $descending ) { + list( $tables, $fields, $conds, $fname, $options, $join_conds ) = parent::buildQueryInfo( + $offset, + $limit, + $descending + ); + + if ( $this->rangeConds ) { + $conds = array_merge( $conds, $this->rangeConds ); + } + + return [ $tables, $fields, $conds, $fname, $options, $join_conds ]; + } +}