X-Git-Url: http://git.cyclocoop.org/%28?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryRevisions.php;h=3781ab0f3527ba4fc98d1405e28c83205b62cda0;hb=cb15755e92513eb61dcea6d7a0c0930374efdb86;hp=b8a180f2a1dc8efade6ae50a0bec53f558e30ce2;hpb=1658759d42a5d802e29a71c3fd70ae127afd3e46;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index b8a180f2a1..3781ab0f35 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -84,7 +84,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { } protected function run( ApiPageSet $resultPageSet = null ) { - global $wgChangeTagsSchemaMigrationStage; + global $wgActorTableSchemaMigrationStage; $params = $this->extractRequestParams( false ); $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); @@ -133,6 +133,19 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $db = $this->getDB(); + $idField = 'rev_id'; + $tsField = 'rev_timestamp'; + $pageField = 'rev_page'; + if ( $params['user'] !== null && + ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) + ) { + // We're going to want to use the page_actor_timestamp index (on revision_actor_temp) + // so use that table's denormalized fields. + $idField = 'revactor_rev'; + $tsField = 'revactor_timestamp'; + $pageField = 'revactor_page'; + } + if ( $resultPageSet === null ) { $this->parseParameters( $params ); $this->token = $params['token']; @@ -147,6 +160,15 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $opts[] = 'user'; } $revQuery = $revisionStore->getQueryInfo( $opts ); + + if ( $idField !== 'rev_id' ) { + $aliasFields = [ 'rev_id' => $idField, 'rev_timestamp' => $tsField, 'rev_page' => $pageField ]; + $revQuery['fields'] = array_merge( + $aliasFields, + array_diff( $revQuery['fields'], array_keys( $aliasFields ) ) + ); + } + $this->addTables( $revQuery['tables'] ); $this->addFields( $revQuery['fields'] ); $this->addJoinConds( $revQuery['joins'] ); @@ -155,34 +177,28 @@ 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', 'rev_timestamp', 'rev_page' ] ); + $this->addFields( [ + 'rev_id' => $idField, 'rev_timestamp' => $tsField, 'rev_page' => $pageField + ] ); } if ( $this->fld_tags ) { - $this->addTables( 'tag_summary' ); - $this->addJoinConds( - [ 'tag_summary' => [ 'LEFT JOIN', [ 'rev_id=ts_rev_id' ] ] ] - ); - $this->addFields( 'ts_tags' ); + $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] ); } 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' ] ] ] ); - 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'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } @@ -207,6 +223,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { if ( $enumRevMode ) { // Indexes targeted: // page_timestamp if we don't have rvuser + // page_actor_timestamp (on revision_actor_temp) if we have rvuser in READ_NEW mode // page_user_timestamp if we have a logged-in rvuser // page_timestamp or usertext_timestamp if we have an IP rvuser @@ -222,9 +239,9 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) ); $continueId = (int)$cont[1]; $this->dieContinueUsageIf( $continueId != $cont[1] ); - $this->addWhere( "rev_timestamp $op $continueTimestamp OR " . - "(rev_timestamp = $continueTimestamp AND " . - "rev_id $op= $continueId)" + $this->addWhere( "$tsField $op $continueTimestamp OR " . + "($tsField = $continueTimestamp AND " . + "$idField $op= $continueId)" ); } @@ -274,24 +291,24 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $op = ( $params['dir'] === 'newer' ? '>' : '<' ); $ts = $db->addQuotes( $db->timestampOrNull( $params['start'] ) ); if ( $params['startid'] !== null ) { - $this->addWhere( "rev_timestamp $op $ts OR " - . "rev_timestamp = $ts AND rev_id $op= " . intval( $params['startid'] ) ); + $this->addWhere( "$tsField $op $ts OR " + . "$tsField = $ts AND $idField $op= " . (int)$params['startid'] ); } else { - $this->addWhere( "rev_timestamp $op= $ts" ); + $this->addWhere( "$tsField $op= $ts" ); } } if ( $params['end'] !== null ) { $op = ( $params['dir'] === 'newer' ? '<' : '>' ); // Yes, opposite of the above $ts = $db->addQuotes( $db->timestampOrNull( $params['end'] ) ); if ( $params['endid'] !== null ) { - $this->addWhere( "rev_timestamp $op $ts OR " - . "rev_timestamp = $ts AND rev_id $op= " . intval( $params['endid'] ) ); + $this->addWhere( "$tsField $op $ts OR " + . "$tsField = $ts AND $idField $op= " . (int)$params['endid'] ); } else { - $this->addWhere( "rev_timestamp $op= $ts" ); + $this->addWhere( "$tsField $op= $ts" ); } } } else { - $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'], + $this->addTimestampWhereRange( $tsField, $params['dir'], $params['start'], $params['end'] ); } @@ -300,7 +317,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { // There is only one ID, use it $ids = array_keys( $pageSet->getGoodTitles() ); - $this->addWhereFld( 'rev_page', reset( $ids ) ); + $this->addWhereFld( $pageField, reset( $ids ) ); if ( $params['user'] !== null ) { $actorQuery = ActorMigration::newMigration() @@ -337,7 +354,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 ) { @@ -357,8 +374,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 " . @@ -386,12 +403,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; } @@ -421,12 +438,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; }