Merge "RevisionStoreDbTestBase, remove redundant needsDB override"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserContribs.php
index fdcaa76..75670dd 100644 (file)
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\NameTableAccessException;
+use MediaWiki\Storage\RevisionRecord;
+
 /**
  * This query action adds a list of a specified user's contributions to the output.
  *
@@ -399,7 +403,8 @@ class ApiQueryUserContribs extends ApiQueryBase {
                                                $revIds[] = $data[0]->rev_parent_id;
                                        }
                                }
-                               $this->parentLens = Revision::getParentLengths( $dbSecondary, $revIds );
+                               $this->parentLens = MediaWikiServices::getInstance()->getRevisionStore()
+                                       ->listRevisionSizes( $dbSecondary, $revIds );
                        }
 
                        foreach ( $merged as $data ) {
@@ -433,12 +438,12 @@ class ApiQueryUserContribs extends ApiQueryBase {
         * @return bool
         */
        private function prepareQuery( array $users, $limit, $which ) {
-               global $wgActorTableSchemaMigrationStage;
+               global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage;
 
                $this->resetQueryParams();
                $db = $this->getDB();
 
-               $revQuery = Revision::getQueryInfo( [ 'page' ] );
+               $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo( [ 'page' ] );
                $this->addTables( $revQuery['tables'] );
                $this->addJoinConds( $revQuery['joins'] );
                $this->addFields( $revQuery['fields'] );
@@ -500,9 +505,9 @@ class ApiQueryUserContribs extends ApiQueryBase {
                // see the username.
                $user = $this->getUser();
                if ( !$user->isAllowed( 'deletedhistory' ) ) {
-                       $bitmask = Revision::DELETED_USER;
+                       $bitmask = RevisionRecord::DELETED_USER;
                } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
-                       $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
+                       $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                } else {
                        $bitmask = 0;
                }
@@ -603,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;
@@ -619,7 +634,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
                $vals = [];
                $anyHidden = false;
 
-               if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
+               if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
                        $vals['texthidden'] = true;
                        $anyHidden = true;
                }
@@ -627,7 +642,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
                // Any rows where we can't view the user were filtered out in the query.
                $vals['userid'] = (int)$row->rev_user;
                $vals['user'] = $row->rev_user_text;
-               if ( $row->rev_deleted & Revision::DELETED_USER ) {
+               if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
                        $vals['userhidden'] = true;
                        $anyHidden = true;
                }
@@ -658,14 +673,14 @@ class ApiQueryUserContribs extends ApiQueryBase {
                }
 
                if ( $this->fld_comment || $this->fld_parsedcomment ) {
-                       if ( $row->rev_deleted & Revision::DELETED_COMMENT ) {
+                       if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
                                $vals['commenthidden'] = true;
                                $anyHidden = true;
                        }
 
-                       $userCanView = Revision::userCanBitfield(
+                       $userCanView = RevisionRecord::userCanBitfield(
                                $row->rev_deleted,
-                               Revision::DELETED_COMMENT, $this->getUser()
+                               RevisionRecord::DELETED_COMMENT, $this->getUser()
                        );
 
                        if ( $userCanView ) {
@@ -707,7 +722,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
                        }
                }
 
-               if ( $anyHidden && $row->rev_deleted & Revision::DELETED_RESTRICTED ) {
+               if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
                        $vals['suppressed'] = true;
                }