X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryContributors.php;h=d07df5a370aab579e52a04e1ecf94c515c54584a;hb=59636d1d0c95b2fb86ad93cfc3e25176e730e133;hp=25b7c84028f33afb963a2248c272d24da920f6ae;hpb=16ef3e79c4c52aa6b74563b7eadcfc9792e7a4c4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryContributors.php b/includes/api/ApiQueryContributors.php index 25b7c84028..d07df5a370 100644 --- a/includes/api/ApiQueryContributors.php +++ b/includes/api/ApiQueryContributors.php @@ -43,6 +43,8 @@ class ApiQueryContributors extends ApiQueryBase { } public function execute() { + global $wgActorTableSchemaMigrationStage; + $db = $this->getDB(); $params = $this->extractRequestParams(); $this->requireMaxOneParameter( $params, 'group', 'excludegroup', 'rights', 'excluderights' ); @@ -73,17 +75,27 @@ class ApiQueryContributors extends ApiQueryBase { } $result = $this->getResult(); + $revQuery = Revision::getQueryInfo(); + + // For MIGRATION_NEW, target indexes on the revision_actor_temp table. + // Otherwise, revision is fine because it'll have to check all revision rows anyway. + $pageField = $wgActorTableSchemaMigrationStage === MIGRATION_NEW ? 'revactor_page' : 'rev_page'; + $idField = $wgActorTableSchemaMigrationStage === MIGRATION_NEW + ? 'revactor_actor' : $revQuery['fields']['rev_user']; + $countField = $wgActorTableSchemaMigrationStage === MIGRATION_NEW + ? 'revactor_actor' : $revQuery['fields']['rev_user_text']; // First, count anons - $this->addTables( 'revision' ); + $this->addTables( $revQuery['tables'] ); + $this->addJoinConds( $revQuery['joins'] ); $this->addFields( [ - 'page' => 'rev_page', - 'anons' => 'COUNT(DISTINCT rev_user_text)', + 'page' => $pageField, + 'anons' => "COUNT(DISTINCT $countField)", ] ); - $this->addWhereFld( 'rev_page', $pages ); - $this->addWhere( 'rev_user = 0' ); + $this->addWhereFld( $pageField, $pages ); + $this->addWhere( ActorMigration::newMigration()->isAnon( $revQuery['fields']['rev_user'] ) ); $this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ); - $this->addOption( 'GROUP BY', 'rev_page' ); + $this->addOption( 'GROUP BY', $pageField ); $res = $this->select( __METHOD__ ); foreach ( $res as $row ) { $fit = $result->addValue( [ 'query', 'pages', $row->page ], @@ -103,24 +115,27 @@ class ApiQueryContributors extends ApiQueryBase { // Next, add logged-in users $this->resetQueryParams(); - $this->addTables( 'revision' ); + $this->addTables( $revQuery['tables'] ); + $this->addJoinConds( $revQuery['joins'] ); $this->addFields( [ - 'page' => 'rev_page', - 'user' => 'rev_user', - 'username' => 'MAX(rev_user_text)', // Non-MySQL databases don't like partial group-by + 'page' => $pageField, + 'id' => $idField, + // Non-MySQL databases don't like partial group-by + 'userid' => 'MAX(' . $revQuery['fields']['rev_user'] . ')', + 'username' => 'MAX(' . $revQuery['fields']['rev_user_text'] . ')', ] ); - $this->addWhereFld( 'rev_page', $pages ); - $this->addWhere( 'rev_user != 0' ); + $this->addWhereFld( $pageField, $pages ); + $this->addWhere( ActorMigration::newMigration()->isNotAnon( $revQuery['fields']['rev_user'] ) ); $this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ); - $this->addOption( 'GROUP BY', 'rev_page, rev_user' ); + $this->addOption( 'GROUP BY', [ $pageField, $idField ] ); $this->addOption( 'LIMIT', $params['limit'] + 1 ); // Force a sort order to ensure that properties are grouped by page - // But only if pp_page is not constant in the WHERE clause. + // But only if rev_page is not constant in the WHERE clause. if ( count( $pages ) > 1 ) { - $this->addOption( 'ORDER BY', 'rev_page, rev_user' ); + $this->addOption( 'ORDER BY', [ 'page', 'id' ] ); } else { - $this->addOption( 'ORDER BY', 'rev_user' ); + $this->addOption( 'ORDER BY', 'id' ); } $limitGroups = []; @@ -159,7 +174,7 @@ class ApiQueryContributors extends ApiQueryBase { $this->addJoinConds( [ 'user_groups' => [ $excludeGroups ? 'LEFT OUTER JOIN' : 'INNER JOIN', [ - 'ug_user=rev_user', + 'ug_user=' . $revQuery['fields']['rev_user'], 'ug_group' => $limitGroups, 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() ) ] @@ -171,11 +186,11 @@ class ApiQueryContributors extends ApiQueryBase { $cont = explode( '|', $params['continue'] ); $this->dieContinueUsageIf( count( $cont ) != 2 ); $cont_page = (int)$cont[0]; - $cont_user = (int)$cont[1]; + $cont_id = (int)$cont[1]; $this->addWhere( - "rev_page > $cont_page OR " . - "(rev_page = $cont_page AND " . - "rev_user >= $cont_user)" + "$pageField > $cont_page OR " . + "($pageField = $cont_page AND " . + "$idField >= $cont_id)" ); } @@ -185,18 +200,16 @@ class ApiQueryContributors extends ApiQueryBase { if ( ++$count > $params['limit'] ) { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... - $this->setContinueEnumParameter( 'continue', $row->page . '|' . $row->user ); - + $this->setContinueEnumParameter( 'continue', $row->page . '|' . $row->id ); return; } $fit = $this->addPageSubItem( $row->page, - [ 'userid' => (int)$row->user, 'name' => $row->username ], + [ 'userid' => (int)$row->userid, 'name' => $row->username ], 'user' ); if ( !$fit ) { - $this->setContinueEnumParameter( 'continue', $row->page . '|' . $row->user ); - + $this->setContinueEnumParameter( 'continue', $row->page . '|' . $row->id ); return; } }