Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
[lhc/web/wiklou.git] / includes / specials / pagers / ContribsPager.php
index cd04995..205364f 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;
 
@@ -64,12 +64,12 @@ class ContribsPager extends RangeChronologicalPager {
                        $this->messages[$msg] = $this->msg( $msg )->escaped();
                }
 
-               $this->target = isset( $options['target'] ) ? $options['target'] : '';
-               $this->contribs = isset( $options['contribs'] ) ? $options['contribs'] : 'users';
-               $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
-               $this->tagFilter = isset( $options['tagfilter'] ) ? $options['tagfilter'] : false;
-               $this->nsInvert = isset( $options['nsInvert'] ) ? $options['nsInvert'] : false;
-               $this->associated = isset( $options['associated'] ) ? $options['associated'] : false;
+               $this->target = $options['target'] ?? '';
+               $this->contribs = $options['contribs'] ?? 'users';
+               $this->namespace = $options['namespace'] ?? '';
+               $this->tagFilter = $options['tagfilter'] ?? false;
+               $this->nsInvert = $options['nsInvert'] ?? false;
+               $this->associated = $options['associated'] ?? false;
 
                $this->deletedOnly = !empty( $options['deletedOnly'] );
                $this->topOnly = !empty( $options['topOnly'] );
@@ -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(
@@ -218,8 +218,18 @@ class ContribsPager extends RangeChronologicalPager {
                                $queryInfo['conds'][] = $ipRangeConds;
                        } else {
                                // tables and joins are already handled by Revision::getQueryInfo()
-                               $queryInfo['conds'][] = ActorMigration::newMigration()
-                                       ->getWhere( $this->mDb, 'rev_user', $user )['conds'];
+                               $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';
+                                       }
+                               }
                        }
                }
 
@@ -630,10 +640,10 @@ class ContribsPager extends RangeChronologicalPager {
         * @return array Options array with processed start and end date filter options
         */
        public static function processDateFilter( array $opts ) {
-               $start = isset( $opts['start'] ) ? $opts['start'] : '';
-               $end = isset( $opts['end'] ) ? $opts['end'] : '';
-               $year = isset( $opts['year'] ) ? $opts['year'] : '';
-               $month = isset( $opts['month'] ) ? $opts['month'] : '';
+               $start = $opts['start'] ?? '';
+               $end = $opts['end'] ?? '';
+               $year = $opts['year'] ?? '';
+               $month = $opts['month'] ?? '';
 
                if ( $start !== '' && $end !== '' && $start > $end ) {
                        $temp = $start;