API: Use ct_tag_id in queries when applicable
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index 8c26024..9109a5e 100644 (file)
@@ -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 ) {