Change ResultWrapper to IResultWrapper in pagers and special pages
[lhc/web/wiklou.git] / includes / specials / pagers / ContribsPager.php
index c3fa2b1..e31498a 100644 (file)
@@ -24,7 +24,7 @@
  * @ingroup Pager
  */
 use MediaWiki\MediaWikiServices;
-use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\IResultWrapper;
 use Wikimedia\Rdbms\FakeResultWrapper;
 use Wikimedia\Rdbms\IDatabase;
 
@@ -113,7 +113,7 @@ class ContribsPager extends RangeChronologicalPager {
         * @param string $offset Index offset, inclusive
         * @param int $limit Exact query limit
         * @param bool $descending Query direction, false for ascending, true for descending
-        * @return ResultWrapper
+        * @return IResultWrapper
         */
        function reallyDoQuery( $offset, $limit, $descending ) {
                list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
@@ -185,8 +185,8 @@ class ContribsPager extends RangeChronologicalPager {
                ];
 
                if ( $this->contribs == 'newbie' ) {
-                       $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
-                       $queryInfo['conds'][] = 'rev_user >' . (int)( $max - $max / 100 );
+                       $max = $this->mDb->selectField( 'user', 'max(user_id)', '', __METHOD__ );
+                       $queryInfo['conds'][] = $revQuery['fields']['rev_user'] . ' >' . (int)( $max - $max / 100 );
                        # ignore local groups with the bot right
                        # @todo FIXME: Global groups may have 'bot' rights
                        $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
@@ -195,7 +195,7 @@ class ContribsPager extends RangeChronologicalPager {
                                $queryInfo['conds'][] = 'ug_group IS NULL';
                                $queryInfo['join_conds']['user_groups'] = [
                                        'LEFT JOIN', [
-                                               'ug_user = rev_user',
+                                               'ug_user = ' . $revQuery['fields']['rev_user'],
                                                'ug_group' => $groupsWithBotPermission,
                                                'ug_expiry IS NULL OR ug_expiry >= ' .
                                                        $this->mDb->addQuotes( $this->mDb->timestamp() )
@@ -208,22 +208,27 @@ class ContribsPager extends RangeChronologicalPager {
                        $queryInfo['conds'][] = 'rev_timestamp > ' .
                                $this->mDb->addQuotes( $this->mDb->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
                } else {
-                       $uid = User::idFromName( $this->target );
-                       if ( $uid ) {
-                               $queryInfo['conds']['rev_user'] = $uid;
-                               $queryInfo['options']['USE INDEX']['revision'] = 'user_timestamp';
+                       $user = User::newFromName( $this->target, false );
+                       $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
+                       if ( $ipRangeConds ) {
+                               $queryInfo['tables'][] = 'ip_changes';
+                               $queryInfo['join_conds']['ip_changes'] = [
+                                       'LEFT JOIN', [ 'ipc_rev_id = rev_id' ]
+                               ];
+                               $queryInfo['conds'][] = $ipRangeConds;
                        } else {
-                               $ipRangeConds = $this->getIpRangeConds( $this->mDb, $this->target );
-
-                               if ( $ipRangeConds ) {
-                                       $queryInfo['tables'][] = 'ip_changes';
-                                       $queryInfo['join_conds']['ip_changes'] = [
-                                               'LEFT JOIN', [ 'ipc_rev_id = rev_id' ]
-                                       ];
-                                       $queryInfo['conds'][] = $ipRangeConds;
-                               } else {
-                                       $queryInfo['conds']['rev_user_text'] = $this->target;
-                                       $queryInfo['options']['USE INDEX']['revision'] = 'usertext_timestamp';
+                               // tables and joins are already handled by Revision::getQueryInfo()
+                               $conds = ActorMigration::newMigration()->getWhere( $this->mDb, 'rev_user', $user );
+                               $queryInfo['conds'][] = $conds['conds'];
+                               // Force the appropriate index to avoid bad query plans (T189026)
+                               if ( count( $conds['orconds'] ) === 1 ) {
+                                       if ( isset( $conds['orconds']['actor'] ) ) {
+                                               // @todo: This will need changing when revision_comment_temp goes away
+                                               $queryInfo['options']['USE INDEX']['temp_rev_user'] = 'actor_timestamp';
+                                       } else {
+                                               $queryInfo['options']['USE INDEX']['revision'] =
+                                                       isset( $conds['orconds']['userid'] ) ? 'user_timestamp' : 'usertext_timestamp';
+                                       }
                                }
                        }
                }
@@ -427,14 +432,14 @@ class ContribsPager extends RangeChronologicalPager {
                 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
                 * to extensions to subscribe to the hook to parse the row.
                 */
-               MediaWiki\suppressWarnings();
+               Wikimedia\suppressWarnings();
                try {
                        $rev = new Revision( $row );
                        $validRevision = (bool)$rev->getId();
                } catch ( Exception $e ) {
                        $validRevision = false;
                }
-               MediaWiki\restoreWarnings();
+               Wikimedia\restoreWarnings();
 
                if ( $validRevision ) {
                        $attribs['data-mw-revid'] = $rev->getId();