aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>2023-02-14 00:49:43 +0000
committerGerrit Code Review <gerrit@wikimedia.org>2023-02-14 00:49:43 +0000
commit640cec0a08675220baa4e78755971eb1d9d25431 (patch)
treef0783ff5b516286d1762bbfbe19c95158e08416e
parent855004747a995408c5499b39b62b7535232f1ddc (diff)
parentf52e5993f4abfc7e4a79f68e7dafc629da76b663 (diff)
downloadmediawikicore-640cec0a08675220baa4e78755971eb1d9d25431.tar.gz
mediawikicore-640cec0a08675220baa4e78755971eb1d9d25431.zip
Merge "pager: Provide a method to override the timestamp field"
-rw-r--r--includes/pager/RangeChronologicalPager.php11
-rw-r--r--includes/pager/ReverseChronologicalPager.php17
2 files changed, 19 insertions, 9 deletions
diff --git a/includes/pager/RangeChronologicalPager.php b/includes/pager/RangeChronologicalPager.php
index 3d7c4134d7d6..3d08e59493d6 100644
--- a/includes/pager/RangeChronologicalPager.php
+++ b/includes/pager/RangeChronologicalPager.php
@@ -53,13 +53,12 @@ abstract class RangeChronologicalPager extends ReverseChronologicalPager {
// Construct the conds array for compatibility with callers and derived classes
$this->rangeConds = [];
- // This is a chronological pager, so the first column should be some kind of timestamp
- $timestampField = is_array( $this->mIndexField ) ? $this->mIndexField[0] : $this->mIndexField;
try {
if ( $startTime !== '' ) {
$startTimestamp = MWTimestamp::getInstance( $startTime );
$this->startOffset = $this->mDb->timestamp( $startTimestamp->getTimestamp() );
- $this->rangeConds[] = $this->mDb->buildComparison( '>=', [ $timestampField => $this->startOffset ] );
+ $this->rangeConds[] = $this->mDb->buildComparison( '>=',
+ [ $this->getTimestampField() => $this->startOffset ] );
}
if ( $endTime !== '' ) {
@@ -68,7 +67,8 @@ abstract class RangeChronologicalPager extends ReverseChronologicalPager {
// add one second for compatibility with existing use cases
$endTimestamp->timestamp = $endTimestamp->timestamp->modify( '+1 second' );
$this->endOffset = $this->mDb->timestamp( $endTimestamp->getTimestamp() );
- $this->rangeConds[] = $this->mDb->buildComparison( '<', [ $timestampField => $this->endOffset ] );
+ $this->rangeConds[] = $this->mDb->buildComparison( '<',
+ [ $this->getTimestampField() => $this->endOffset ] );
// populate existing variables for compatibility with parent
$this->mYear = (int)$endTimestamp->format( 'Y' );
@@ -104,8 +104,7 @@ abstract class RangeChronologicalPager extends ReverseChronologicalPager {
);
// End of the range has been added by ReverseChronologicalPager
if ( $this->startOffset ) {
- $timestampField = is_array( $this->mIndexField ) ? $this->mIndexField[0] : $this->mIndexField;
- $conds[] = $this->mDb->buildComparison( '>=', [ $timestampField => $this->startOffset ] );
+ $conds[] = $this->mDb->buildComparison( '>=', [ $this->getTimestampField() => $this->startOffset ] );
} elseif ( $this->rangeConds ) {
// Keep compatibility with some derived classes, T325034
$conds = array_merge( $conds, $this->rangeConds );
diff --git a/includes/pager/ReverseChronologicalPager.php b/includes/pager/ReverseChronologicalPager.php
index d9966ec5770a..cdd0bbf3777d 100644
--- a/includes/pager/ReverseChronologicalPager.php
+++ b/includes/pager/ReverseChronologicalPager.php
@@ -89,6 +89,18 @@ abstract class ReverseChronologicalPager extends IndexPager {
}
/**
+ * Returns the name of the timestamp field. Subclass can override this to provide the
+ * timestamp field if they are using a aliased field for getIndexField()
+ *
+ * @since 1.40
+ * @return string
+ */
+ public function getTimestampField() {
+ // This is a chronological pager, so the first column should be some kind of timestamp
+ return is_array( $this->mIndexField ) ? $this->mIndexField[0] : $this->mIndexField;
+ }
+
+ /**
* Get date from the timestamp
*
* @since 1.38
@@ -105,7 +117,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
protected function getRow( $row ): string {
$s = '';
- $timestampField = is_array( $this->mIndexField ) ? $this->mIndexField[0] : $this->mIndexField;
+ $timestampField = $this->getTimestampField();
$timestamp = $row->$timestampField ?? null;
$date = $timestamp ? $this->getDateFromTimestamp( $timestamp ) : null;
if ( $date && $this->isHeaderRowNeeded( $date ) ) {
@@ -310,8 +322,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
$order
);
if ( $this->endOffset ) {
- $timestampField = is_array( $this->mIndexField ) ? $this->mIndexField[0] : $this->mIndexField;
- $conds[] = $this->mDb->buildComparison( '<', [ $timestampField => $this->endOffset ] );
+ $conds[] = $this->mDb->buildComparison( '<', [ $this->getTimestampField() => $this->endOffset ] );
}
return [ $tables, $fields, $conds, $fname, $options, $join_conds ];