resources: Strip '$' and 'mw' from file closures
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index 5858bc7..9109a5e 100644 (file)
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\NameTableAccessException;
+use MediaWiki\Storage\RevisionRecord;
+
 /**
  * A query action to enumerate revisions of a given page, or show top revisions
  * of multiple pages. Various pieces of information may be shown - flags,
@@ -80,7 +84,10 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
        }
 
        protected function run( ApiPageSet $resultPageSet = null ) {
+               global $wgChangeTagsSchemaMigrationStage;
+
                $params = $this->extractRequestParams( false );
+               $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
 
                // If any of those parameters are used, work in 'enumeration' mode.
                // Enum mode can only be used when exactly one page is provided.
@@ -139,7 +146,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        if ( $this->fld_user ) {
                                $opts[] = 'user';
                        }
-                       $revQuery = Revision::getQueryInfo( $opts );
+                       $revQuery = $revisionStore->getQueryInfo( $opts );
                        $this->addTables( $revQuery['tables'] );
                        $this->addFields( $revQuery['fields'] );
                        $this->addJoinConds( $revQuery['joins'] );
@@ -166,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 ) {
@@ -301,9 +318,9 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        if ( $params['user'] !== null || $params['excludeuser'] !== null ) {
                                // Paranoia: avoid brute force searches (T19342)
                                if ( !$this->getUser()->isAllowed( 'deletedhistory' ) ) {
-                                       $bitmask = Revision::DELETED_USER;
+                                       $bitmask = RevisionRecord::DELETED_USER;
                                } elseif ( !$this->getUser()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
-                                       $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
+                                       $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                                } else {
                                        $bitmask = 0;
                                }
@@ -382,14 +399,15 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        if ( $resultPageSet !== null ) {
                                $generated[] = $row->rev_id;
                        } else {
-                               $revision = new Revision( $row );
+                               $revision = $revisionStore->newRevisionFromRow( $row );
                                $rev = $this->extractRevisionInfo( $revision, $row );
 
                                if ( $this->token !== null ) {
-                                       $title = $revision->getTitle();
+                                       $title = Title::newFromLinkTarget( $revision->getPageAsLinkTarget() );
+                                       $revisionCompat = new Revision( $revision );
                                        $tokenFunctions = $this->getTokenFunctions();
                                        foreach ( $this->token as $t ) {
-                                               $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
+                                               $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revisionCompat );
                                                if ( $val === false ) {
                                                        $this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
                                                } else {
@@ -481,7 +499,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
        protected function getExamplesMessages() {
                return [
                        'action=query&prop=revisions&titles=API|Main%20Page&' .
-                               'rvprop=timestamp|user|comment|content'
+                               'rvslots=*&rvprop=timestamp|user|comment|content'
                                => 'apihelp-query+revisions-example-content',
                        'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
                                'rvprop=timestamp|user|comment'