From 0841a0f79eb9755a8218785a137b89e1e6e86343 Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Tue, 4 Sep 2018 21:17:29 +0200 Subject: [PATCH] API: Use ct_tag_id in queries when applicable Bug: T194162 Change-Id: I2146cd1f72b546277723102ab64c79567549ff5b --- includes/api/ApiQueryAllDeletedRevisions.php | 15 ++++++++++++++- includes/api/ApiQueryDeletedRevisions.php | 15 ++++++++++++++- includes/api/ApiQueryDeletedrevs.php | 17 ++++++++++++++++- includes/api/ApiQueryLogEvents.php | 17 ++++++++++++++++- includes/api/ApiQueryRecentChanges.php | 16 +++++++++++++++- includes/api/ApiQueryRevisions.php | 15 ++++++++++++++- includes/api/ApiQueryUserContribs.php | 15 +++++++++++++-- 7 files changed, 102 insertions(+), 8 deletions(-) diff --git a/includes/api/ApiQueryAllDeletedRevisions.php b/includes/api/ApiQueryAllDeletedRevisions.php index 50afc7de3d..830df59351 100644 --- a/includes/api/ApiQueryAllDeletedRevisions.php +++ b/includes/api/ApiQueryAllDeletedRevisions.php @@ -24,6 +24,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; use MediaWiki\Storage\RevisionRecord; /** @@ -42,6 +43,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase { * @return void */ protected function run( ApiPageSet $resultPageSet = null ) { + global $wgChangeTagsSchemaMigrationStage; + // Before doing anything at all, let's check permissions $this->checkUserRightsAny( 'deletedhistory' ); @@ -136,7 +139,17 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ] ); - $this->addWhereFld( 'ct_tag', $params['tag'] ); + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); + } + } else { + $this->addWhereFld( 'ct_tag', $params['tag'] ); + } } if ( $this->fetchContent ) { diff --git a/includes/api/ApiQueryDeletedRevisions.php b/includes/api/ApiQueryDeletedRevisions.php index 48d6f300c7..47b746a737 100644 --- a/includes/api/ApiQueryDeletedRevisions.php +++ b/includes/api/ApiQueryDeletedRevisions.php @@ -24,6 +24,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; use MediaWiki\Storage\RevisionRecord; /** @@ -38,6 +39,8 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase { } protected function run( ApiPageSet $resultPageSet = null ) { + global $wgChangeTagsSchemaMigrationStage; + $user = $this->getUser(); // Before doing anything at all, let's check permissions $this->checkUserRightsAny( 'deletedhistory' ); @@ -88,7 +91,17 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ] ); - $this->addWhereFld( 'ct_tag', $params['tag'] ); + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); + } + } else { + $this->addWhereFld( 'ct_tag', $params['tag'] ); + } } if ( $this->fetchContent ) { diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 83d00a9330..e84b9b2247 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -20,6 +20,9 @@ * @file */ +use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; + /** * Query module to enumerate all deleted revisions. * @@ -33,6 +36,8 @@ class ApiQueryDeletedrevs extends ApiQueryBase { } public function execute() { + global $wgChangeTagsSchemaMigrationStage; + // Before doing anything at all, let's check permissions $this->checkUserRightsAny( 'deletedhistory' ); @@ -140,7 +145,17 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ] ); - $this->addWhereFld( 'ct_tag', $params['tag'] ); + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); + } + } else { + $this->addWhereFld( 'ct_tag', $params['tag'] ); + } } if ( $fld_content ) { diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index a6b97dd895..39be2c17fd 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -20,6 +20,9 @@ * @file */ +use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; + /** * Query action to List the log events, with optional filtering by various parameters. * @@ -39,6 +42,8 @@ class ApiQueryLogEvents extends ApiQueryBase { $fld_details = false, $fld_tags = false; public function execute() { + global $wgChangeTagsSchemaMigrationStage; + $params = $this->extractRequestParams(); $db = $this->getDB(); $this->commentStore = CommentStore::getStore(); @@ -113,7 +118,17 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addTables( 'change_tag' ); $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'log_id=ct_log_id' ] ] ] ); - $this->addWhereFld( 'ct_tag', $params['tag'] ); + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); + } + } else { + $this->addWhereFld( 'ct_tag', $params['tag'] ); + } } if ( !is_null( $params['action'] ) ) { diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index a5be58b7ef..01b9c9affb 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; use MediaWiki\Storage\RevisionRecord; /** @@ -141,6 +143,8 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { * @param ApiPageSet|null $resultPageSet */ public function run( $resultPageSet = null ) { + global $wgChangeTagsSchemaMigrationStage; + $user = $this->getUser(); /* Get the parameters of the request. */ $params = $this->extractRequestParams(); @@ -361,7 +365,17 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { if ( !is_null( $params['tag'] ) ) { $this->addTables( 'change_tag' ); $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] ); - $this->addWhereFld( 'ct_tag', $params['tag'] ); + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); + } + } else { + $this->addWhereFld( 'ct_tag', $params['tag'] ); + } } // Paranoia: avoid brute force searches (T19342) diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 8c26024812..9109a5ea7d 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -21,6 +21,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; use MediaWiki\Storage\RevisionRecord; /** @@ -83,6 +84,8 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { } protected function run( ApiPageSet $resultPageSet = null ) { + global $wgChangeTagsSchemaMigrationStage; + $params = $this->extractRequestParams( false ); $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); @@ -170,7 +173,17 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rev_id=ct_rev_id' ] ] ] ); - $this->addWhereFld( 'ct_tag', $params['tag'] ); + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); + } + } else { + $this->addWhereFld( 'ct_tag', $params['tag'] ); + } } if ( $resultPageSet === null && $this->fetchContent ) { diff --git a/includes/api/ApiQueryUserContribs.php b/includes/api/ApiQueryUserContribs.php index 3aa61832fe..75670dd445 100644 --- a/includes/api/ApiQueryUserContribs.php +++ b/includes/api/ApiQueryUserContribs.php @@ -21,6 +21,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; use MediaWiki\Storage\RevisionRecord; /** @@ -437,7 +438,7 @@ class ApiQueryUserContribs extends ApiQueryBase { * @return bool */ private function prepareQuery( array $users, $limit, $which ) { - global $wgActorTableSchemaMigrationStage; + global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage; $this->resetQueryParams(); $db = $this->getDB(); @@ -607,7 +608,17 @@ class ApiQueryUserContribs extends ApiQueryBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ] ); - $this->addWhereFld( 'ct_tag', $this->params['tag'] ); + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); + } + } else { + $this->addWhereFld( 'ct_tag', $this->params['tag'] ); + } } return true; -- 2.20.1