Merge "Improve test coverage for ApiBase.php"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserContributions.php
index e587ef4..f6bc8cb 100644 (file)
@@ -82,19 +82,20 @@ class ApiQueryContributions extends ApiQueryBase {
                        $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
                                global $wgActorTableSchemaMigrationStage;
 
-                               $from = $fromName = false;
+                               $fromName = false;
                                if ( !is_null( $this->params['continue'] ) ) {
                                        $continue = explode( '|', $this->params['continue'] );
                                        $this->dieContinueUsageIf( count( $continue ) != 4 );
                                        $this->dieContinueUsageIf( $continue[0] !== 'name' );
                                        $fromName = $continue[1];
-                                       $from = "$op= " . $dbSecondary->addQuotes( $fromName );
                                }
                                $like = $dbSecondary->buildLike( $this->params['userprefix'], $dbSecondary->anyString() );
 
                                $limit = 501;
 
                                do {
+                                       $from = $fromName ? "$op= " . $dbSecondary->addQuotes( $fromName ) : false;
+
                                        // For the new schema, pull from the actor table. For the
                                        // old, pull from rev_user. For migration a FULL [OUTER]
                                        // JOIN would be what we want, except MySQL doesn't support
@@ -158,15 +159,15 @@ class ApiQueryContributions extends ApiQueryBase {
                                        }
 
                                        $count = 0;
-                                       $from = null;
+                                       $fromName = false;
                                        foreach ( $res as $row ) {
                                                if ( ++$count >= $limit ) {
-                                                       $from = $row->user_name;
+                                                       $fromName = $row->user_name;
                                                        break;
                                                }
                                                yield User::newFromRow( $row );
                                        }
-                               } while ( $from !== null );
+                               } while ( $fromName !== false );
                        } );
                        // Do the actual sorting client-side, because otherwise
                        // prepareQuery might try to sort by actor and confuse everything.
@@ -245,7 +246,7 @@ class ApiQueryContributions extends ApiQueryBase {
                                        );
                                }
 
-                               if ( User::isIP( $u ) ) {
+                               if ( User::isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
                                        $names[$u] = null;
                                } else {
                                        $name = User::getCanonicalName( $u, 'valid' );
@@ -529,6 +530,8 @@ class ApiQueryContributions extends ApiQueryBase {
 
                        if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
                                || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
+                               || ( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
+                               || ( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
                                || ( isset( $show['top'] ) && isset( $show['!top'] ) )
                                || ( isset( $show['new'] ) && isset( $show['!new'] ) )
                        ) {
@@ -539,6 +542,8 @@ class ApiQueryContributions extends ApiQueryBase {
                        $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
                        $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
                        $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
+                       $this->addWhereIf( 'rc_patrolled != 2', isset( $show['!autopatrolled'] ) );
+                       $this->addWhereIf( 'rc_patrolled = 2', isset( $show['autopatrolled'] ) );
                        $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
                        $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
                        $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
@@ -547,15 +552,17 @@ class ApiQueryContributions extends ApiQueryBase {
                $this->addOption( 'LIMIT', $limit + 1 );
 
                if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
-                       $this->fld_patrolled
+                       isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] ) || $this->fld_patrolled
                ) {
                        if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
                                $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
                        }
 
+                       $isFilterset = isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
+                               isset( $show['autopatrolled'] ) || isset( $show['!autopatrolled'] );
                        $this->addTables( 'recentchanges' );
                        $this->addJoinConds( [ 'recentchanges' => [
-                               isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ? 'JOIN' : 'LEFT JOIN',
+                               $isFilterset ? 'JOIN' : 'LEFT JOIN',
                                [
                                        // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
                                        // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
@@ -659,7 +666,8 @@ class ApiQueryContributions extends ApiQueryBase {
                }
 
                if ( $this->fld_patrolled ) {
-                       $vals['patrolled'] = (bool)$row->rc_patrolled;
+                       $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
+                       $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
                }
 
                if ( $this->fld_size && !is_null( $row->rev_len ) ) {
@@ -777,6 +785,8 @@ class ApiQueryContributions extends ApiQueryBase {
                                        '!minor',
                                        'patrolled',
                                        '!patrolled',
+                                       'autopatrolled',
+                                       '!autopatrolled',
                                        'top',
                                        '!top',
                                        'new',