From c18151c38c5355e23206dc0a51445326b9e51aa4 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Thu, 6 Oct 2011 20:46:24 +0000 Subject: [PATCH] (bug 29392) Setting the start or end parameter now works with lists blocks, categorymembers, deletedrevs, logevents, protectedtitles, usercontributions and watchlist in Postgres. Since all those used ApiQueryBase::addWhereRange, added ApiQueryBase::addTimestampWhereRange, which does automagic timestamp conversion. Not tested whether this actually fixes problems in Postgres, but at least the API modules are still functional in SQLite --- RELEASE-NOTES-1.19 | 3 +++ includes/api/ApiQueryBase.php | 10 ++++++++++ includes/api/ApiQueryBlocks.php | 2 +- includes/api/ApiQueryDeletedrevs.php | 2 +- includes/api/ApiQueryLogEvents.php | 2 +- includes/api/ApiQueryProtectedTitles.php | 2 +- includes/api/ApiQueryRecentChanges.php | 2 +- includes/api/ApiQueryRevisions.php | 4 ++-- includes/api/ApiQueryUserContributions.php | 2 +- includes/api/ApiQueryWatchlist.php | 5 ++--- 10 files changed, 23 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 9321195f00..bcd37c7139 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -120,6 +120,9 @@ production. * (bug 26885) Allow show/hide of account blocks, temporary blocks and single IP address blocks for list=blocks. * (bug 30591) Add support to only return keys in ApiAllMessages. +* (bug 29392) Setting the start or end parameter now works with lists blocks, + categorymembers, deletedrevs, logevents, protectedtitles, usercontributions + and watchlist in Postgres === Languages updated in 1.19 === diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 18a1a1813d..b7bb1a136a 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -220,6 +220,16 @@ abstract class ApiQueryBase extends ApiBase { } } } + /** + * Add a WHERE clause corresponding to a range, similar to addWhereRange, + * but converts $start and $end to database timestamps. + * @see addWhereRange + */ + protected function addTimestampWhereRange( $field, $dir, $start, $end, $sort = true ) { + $db = $this->getDb(); + return $this->addWhereRange( $field, $dir, + $db->timestamp( $start ), $db->timestamp( $end ), $sort ); + } /** * Add an option such as LIMIT or USE INDEX. If an option was set diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php index 83f8eb8de4..36f089648b 100644 --- a/includes/api/ApiQueryBlocks.php +++ b/includes/api/ApiQueryBlocks.php @@ -81,7 +81,7 @@ class ApiQueryBlocks extends ApiQueryBase { $fld_flags ); $this->addOption( 'LIMIT', $params['limit'] + 1 ); - $this->addWhereRange( 'ipb_timestamp', $params['dir'], $params['start'], $params['end'] ); + $this->addTimestampWhereRange( 'ipb_timestamp', $params['dir'], $params['start'], $params['end'] ); if ( isset( $params['ids'] ) ) { $this->addWhereFld( 'ipb_id', $params['ids'] ); } diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 813d98c8a6..3ce962e4da 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -191,7 +191,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $this->addWhereRange( 'ar_namespace', $dir, null, null ); $this->addWhereRange( 'ar_title', $dir, null, null ); } - $this->addWhereRange( 'ar_timestamp', $dir, $params['start'], $params['end'] ); + $this->addTimestampWhereRange( 'ar_timestamp', $dir, $params['start'], $params['end'] ); } $res = $this->select( __METHOD__ ); $pageMap = array(); // Maps ns&title to (fake) pageid diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index db75c8e726..309c742ebb 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -116,7 +116,7 @@ class ApiQueryLogEvents extends ApiQueryBase { $index['logging'] = 'type_time'; } - $this->addWhereRange( 'log_timestamp', $params['dir'], $params['start'], $params['end'] ); + $this->addTimestampWhereRange( 'log_timestamp', $params['dir'], $params['start'], $params['end'] ); $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php index 9330d18158..f3b1436bb4 100644 --- a/includes/api/ApiQueryProtectedTitles.php +++ b/includes/api/ApiQueryProtectedTitles.php @@ -64,7 +64,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) ); $this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) ); - $this->addWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] ); + $this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] ); $this->addWhereFld( 'pt_namespace', $params['namespace'] ); $this->addWhereFld( 'pt_create_perm', $params['level'] ); diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 79012cc6d0..d955aaa5c8 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -140,7 +140,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { */ $this->addTables( 'recentchanges' ); $index = array( 'recentchanges' => 'rc_timestamp' ); // May change - $this->addWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] ); + $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] ); $this->addWhereFld( 'rc_namespace', $params['namespace'] ); $this->addWhereFld( 'rc_deleted', 0 ); diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 5298d39060..431cc27f41 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -252,14 +252,14 @@ class ApiQueryRevisions extends ApiQueryBase { // one row with the same timestamp for the same page. // The order needs to be the same as start parameter to avoid SQL filesort. if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) ) { - $this->addWhereRange( 'rev_timestamp', $params['dir'], + $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'], $params['start'], $params['end'] ); } else { $this->addWhereRange( 'rev_id', $params['dir'], $params['startid'], $params['endid'] ); // One of start and end can be set // If neither is set, this does nothing - $this->addWhereRange( 'rev_timestamp', $params['dir'], + $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'], $params['start'], $params['end'], false ); } diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index ba9786448f..62194a4b3b 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -182,7 +182,7 @@ class ApiQueryContributions extends ApiQueryBase { if ( $this->multiUserMode ) { $this->addWhereRange( 'rev_user_text', $this->params['dir'], null, null ); } - $this->addWhereRange( 'rev_timestamp', + $this->addTimestampWhereRange( 'rev_timestamp', $this->params['dir'], $this->params['start'], $this->params['end'] ); $this->addWhereFld( 'page_namespace', $this->params['namespace'] ); diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 2e45fdfc7b..76965cea02 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -134,9 +134,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $db = $this->getDB(); - $this->addWhereRange( 'rc_timestamp', $params['dir'], - $db->timestamp( $params['start'] ), - $db->timestamp( $params['end'] ) ); + $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], + $params['start'], $params['end'] ); $this->addWhereFld( 'wl_namespace', $params['namespace'] ); if ( !$params['allrev'] ) { -- 2.20.1