Replace User::isAllowed with PermissionManager.
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index cb2f616..3a06e36 100644 (file)
@@ -76,7 +76,8 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
         */
        public static function getRollbackToken( $pageid, $title, $rev ) {
                global $wgUser;
-               if ( !$wgUser->isAllowed( 'rollback' ) ) {
+               if ( !MediaWikiServices::getInstance()->getPermissionManager()
+                               ->userHasRight( $wgUser, 'rollback' ) ) {
                        return false;
                }
 
@@ -114,7 +115,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
 
                if ( $revCount > 0 && $enumRevMode ) {
                        $this->dieWithError(
-                               [ 'apierror-revisions-nolist', $this->getModulePrefix() ], 'invalidparammix'
+                               [ 'apierror-revisions-norevids', $this->getModulePrefix() ], 'invalidparammix'
                        );
                }
 
@@ -153,9 +154,6 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        if ( $this->token !== null || $pageCount > 0 ) {
                                $opts[] = 'page';
                        }
-                       if ( $this->fetchContent ) {
-                               $opts[] = 'text';
-                       }
                        if ( $this->fld_user ) {
                                $opts[] = 'user';
                        }
@@ -177,7 +175,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        // Always join 'page' so orphaned revisions are filtered out
                        $this->addTables( [ 'revision', 'page' ] );
                        $this->addJoinConds(
-                               [ 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ] ]
+                               [ 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ] ]
                        );
                        $this->addFields( [
                                'rev_id' => $idField, 'rev_timestamp' => $tsField, 'rev_page' => $pageField
@@ -191,7 +189,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                if ( $params['tag'] !== null ) {
                        $this->addTables( 'change_tag' );
                        $this->addJoinConds(
-                               [ 'change_tag' => [ 'INNER JOIN', [ 'rev_id=ct_rev_id' ] ] ]
+                               [ 'change_tag' => [ 'JOIN', [ 'rev_id=ct_rev_id' ] ] ]
                        );
                        $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
                        try {
@@ -204,11 +202,12 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
 
                if ( $resultPageSet === null && $this->fetchContent ) {
                        // For each page we will request, the user must have read rights for that page
-                       $user = $this->getUser();
                        $status = Status::newGood();
+                       $user = $this->getUser();
+
                        /** @var Title $title */
                        foreach ( $pageSet->getGoodTitles() as $title ) {
-                               if ( !$title->userCan( 'read', $user ) ) {
+                               if ( !$this->getPermissionManager()->userCan( 'read', $user, $title ) ) {
                                        $status->fatal( ApiMessage::create(
                                                [ 'apierror-cannotviewtitle', wfEscapeWikiText( $title->getPrefixedText() ) ],
                                                'accessdenied'
@@ -268,7 +267,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                                                [ 'ar_rev_id' => $revids ],
                                                __METHOD__
                                        ),
-                               ], false );
+                               ], $db::UNION_DISTINCT );
                                $res = $db->query( $sql, __METHOD__ );
                                foreach ( $res as $row ) {
                                        if ( (int)$row->id === (int)$params['startid'] ) {
@@ -292,7 +291,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                                        $ts = $db->addQuotes( $db->timestampOrNull( $params['start'] ) );
                                        if ( $params['startid'] !== null ) {
                                                $this->addWhere( "$tsField $op $ts OR "
-                                                       . "$tsField = $ts AND $idField $op= " . intval( $params['startid'] ) );
+                                                       . "$tsField = $ts AND $idField $op= " . (int)$params['startid'] );
                                        } else {
                                                $this->addWhere( "$tsField $op= $ts" );
                                        }
@@ -302,7 +301,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                                        $ts = $db->addQuotes( $db->timestampOrNull( $params['end'] ) );
                                        if ( $params['endid'] !== null ) {
                                                $this->addWhere( "$tsField $op $ts OR "
-                                                       . "$tsField = $ts AND $idField $op= " . intval( $params['endid'] ) );
+                                                       . "$tsField = $ts AND $idField $op= " . (int)$params['endid'] );
                                        } else {
                                                $this->addWhere( "$tsField $op= $ts" );
                                        }
@@ -334,7 +333,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        }
                        if ( $params['user'] !== null || $params['excludeuser'] !== null ) {
                                // Paranoia: avoid brute force searches (T19342)
-                               if ( !$this->getUser()->isAllowed( 'deletedhistory' ) ) {
+                               if ( !$this->getPermissionManager()->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
                                        $bitmask = RevisionRecord::DELETED_USER;
                                } elseif ( !$this->getUser()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
                                        $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
@@ -354,7 +353,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        $this->addWhereFld( 'rev_id', array_keys( $revs ) );
 
                        if ( $params['continue'] !== null ) {
-                               $this->addWhere( 'rev_id >= ' . intval( $params['continue'] ) );
+                               $this->addWhere( 'rev_id >= ' . (int)$params['continue'] );
                        }
                        $this->addOption( 'ORDER BY', 'rev_id' );
                } elseif ( $pageCount > 0 ) {
@@ -374,8 +373,8 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                        if ( $params['continue'] !== null ) {
                                $cont = explode( '|', $params['continue'] );
                                $this->dieContinueUsageIf( count( $cont ) != 2 );
-                               $pageid = intval( $cont[0] );
-                               $revid = intval( $cont[1] );
+                               $pageid = (int)$cont[0];
+                               $revid = (int)$cont[1];
                                $this->addWhere(
                                        "rev_page > $pageid OR " .
                                        "(rev_page = $pageid AND " .
@@ -392,6 +391,10 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
 
                $this->addOption( 'LIMIT', $this->limit + 1 );
 
+               // T224017: `rev_timestamp` is never the correct index to use for this module, but
+               // MariaDB (10.1.37-39) sometimes insists on trying to use it anyway. Tell it not to.
+               $this->addOption( 'IGNORE INDEX', [ 'revision' => 'rev_timestamp' ] );
+
                $count = 0;
                $generated = [];
                $hookData = [];
@@ -403,12 +406,12 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                                // additional pages to be had. Stop here...
                                if ( $enumRevMode ) {
                                        $this->setContinueEnumParameter( 'continue',
-                                               $row->rev_timestamp . '|' . intval( $row->rev_id ) );
+                                               $row->rev_timestamp . '|' . (int)$row->rev_id );
                                } elseif ( $revCount > 0 ) {
-                                       $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
+                                       $this->setContinueEnumParameter( 'continue', (int)$row->rev_id );
                                } else {
-                                       $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
-                                               '|' . intval( $row->rev_id ) );
+                                       $this->setContinueEnumParameter( 'continue', (int)$row->rev_page .
+                                               '|' . (int)$row->rev_id );
                                }
                                break;
                        }
@@ -438,12 +441,12 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                                if ( !$fit ) {
                                        if ( $enumRevMode ) {
                                                $this->setContinueEnumParameter( 'continue',
-                                                       $row->rev_timestamp . '|' . intval( $row->rev_id ) );
+                                                       $row->rev_timestamp . '|' . (int)$row->rev_id );
                                        } elseif ( $revCount > 0 ) {
-                                               $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
+                                               $this->setContinueEnumParameter( 'continue', (int)$row->rev_id );
                                        } else {
-                                               $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
-                                                       '|' . intval( $row->rev_id ) );
+                                               $this->setContinueEnumParameter( 'continue', (int)$row->rev_page .
+                                                       '|' . (int)$row->rev_id );
                                        }
                                        break;
                                }