X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryRevisions.php;h=a4f0315e9f20ace561e97f625c2ee348dfe4cee2;hb=7babd362babcbf7f20adb8e12edb4f4bc1d4249f;hp=b0a8468428c5fac269a518c708f8a160c6d05355;hpb=58e1e472ba48c3271902ccbcadb7c142220c4d58;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index b0a8468428..ef0223aae5 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -1,9 +1,5 @@ @gmail.com" * * This program is free software; you can redistribute it and/or modify @@ -60,7 +56,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { } $this->tokenFunctions = [ - 'rollback' => [ 'ApiQueryRevisions', 'getRollbackToken' ] + 'rollback' => [ self::class, 'getRollbackToken' ] ]; Hooks::run( 'APIQueryRevisionsTokens', [ &$this->tokenFunctions ] ); @@ -129,20 +125,31 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { } $db = $this->getDB(); - $this->addTables( [ 'revision', 'page' ] ); - $this->addJoinConds( - [ 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ] ] - ); if ( $resultPageSet === null ) { $this->parseParameters( $params ); $this->token = $params['token']; - $this->addFields( Revision::selectFields() ); + $opts = []; if ( $this->token !== null || $pageCount > 0 ) { - $this->addFields( Revision::selectPageFields() ); + $opts[] = 'page'; + } + if ( $this->fetchContent ) { + $opts[] = 'text'; } + if ( $this->fld_user ) { + $opts[] = 'user'; + } + $revQuery = Revision::getQueryInfo( $opts ); + $this->addTables( $revQuery['tables'] ); + $this->addFields( $revQuery['fields'] ); + $this->addJoinConds( $revQuery['joins'] ); } else { $this->limit = $this->getParameter( 'limit' ) ?: 10; + // Always join 'page' so orphaned revisions are filtered out + $this->addTables( [ 'revision', 'page' ] ); + $this->addJoinConds( + [ 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ] ] + ); $this->addFields( [ 'rev_id', 'rev_timestamp', 'rev_page' ] ); } @@ -162,11 +169,11 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $this->addWhereFld( 'ct_tag', $params['tag'] ); } - if ( $this->fetchContent ) { + 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(); - /** @var $title Title */ + /** @var Title $title */ foreach ( $pageSet->getGoodTitles() as $title ) { if ( !$title->userCan( 'read', $user ) ) { $status->fatal( ApiMessage::create( @@ -178,20 +185,6 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { if ( !$status->isGood() ) { $this->dieStatus( $status ); } - - $this->addTables( 'text' ); - $this->addJoinConds( - [ 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ] ] - ); - $this->addFields( 'old_id' ); - $this->addFields( Revision::selectTextFields() ); - } - - // add user name, if needed - if ( $this->fld_user ) { - $this->addTables( 'user' ); - $this->addJoinConds( [ 'user' => Revision::userJoinCond() ] ); - $this->addFields( Revision::selectUserFields() ); } if ( $enumRevMode ) { @@ -219,26 +212,26 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { } // Convert startid/endid to timestamps (T163532) - if ( $params['startid'] !== null || $params['endid'] !== null ) { - $ids = [ - (int)$params['startid'] => true, - (int)$params['endid'] => true, - ]; - unset( $ids[0] ); // null - $ids = array_keys( $ids ); - + $revids = []; + if ( $params['startid'] !== null ) { + $revids[] = (int)$params['startid']; + } + if ( $params['endid'] !== null ) { + $revids[] = (int)$params['endid']; + } + if ( $revids ) { $db = $this->getDB(); $sql = $db->unionQueries( [ $db->selectSQLText( 'revision', [ 'id' => 'rev_id', 'ts' => 'rev_timestamp' ], - [ 'rev_id' => $ids ], + [ 'rev_id' => $revids ], __METHOD__ ), $db->selectSQLText( 'archive', [ 'id' => 'ar_rev_id', 'ts' => 'ar_timestamp' ], - [ 'ar_rev_id' => $ids ], + [ 'ar_rev_id' => $revids ], __METHOD__ ), ], false );