Merge "Add getters for properties accessed by Flow"
[lhc/web/wiklou.git] / includes / specials / pagers / ContribsPager.php
index 510bf92..5112ccd 100644 (file)
@@ -30,27 +30,89 @@ use Wikimedia\Rdbms\IDatabase;
 
 class ContribsPager extends RangeChronologicalPager {
 
-       public $mDefaultDirection = IndexPager::DIR_DESCENDING;
-       public $messages;
+       /**
+        * @var string[] Local cache for escaped messages
+        */
+       private $messages;
+
+       /**
+        * @var string User name, or a string describing an IP address range
+        * @private
+        * @fixme Make private again after Flow got fixed.
+        */
        public $target;
+
+       /**
+        * @var string Set to "newbie" to list contributions from the most recent 1% registered users.
+        *  $this->target is ignored then. Defaults to "users".
+        * @private
+        * @fixme Make private again after Flow got fixed.
+        */
+       public $contribs;
+
+       /**
+        * @var string|int A single namespace number, or an empty string for all namespaces
+        * @private
+        * @fixme Make private again after Flow got fixed.
+        */
        public $namespace = '';
-       public $mDb;
-       public $preventClickjacking = false;
+
+       /**
+        * @var string|false Name of tag to filter, or false to ignore tags
+        * @private
+        * @fixme Make private again after Flow got fixed.
+        */
+       public $tagFilter;
+
+       /**
+        * @var bool Set to true to invert the namespace selection
+        */
+       private $nsInvert;
+
+       /**
+        * @var bool Set to true to show both the subject and talk namespace, no matter which got
+        *  selected
+        */
+       private $associated;
+
+       /**
+        * @var bool Set to true to show only deleted revisions
+        */
+       private $deletedOnly;
+
+       /**
+        * @var bool Set to true to show only latest (a.k.a. current) revisions
+        */
+       private $topOnly;
+
+       /**
+        * @var bool Set to true to show only new pages
+        * @private
+        * @fixme Make private again after Flow got fixed.
+        */
+       public $newOnly;
+
+       /**
+        * @var bool Set to true to hide edits marked as minor by the user
+        */
+       private $hideMinor;
+
+       private $preventClickjacking = false;
 
        /** @var IDatabase */
-       public $mDbSecondary;
+       private $mDbSecondary;
 
        /**
         * @var array
         */
-       protected $mParentLens;
+       private $mParentLens;
 
        /**
         * @var TemplateParser
         */
-       protected $templateParser;
+       private $templateParser;
 
-       function __construct( IContextSource $context, array $options ) {
+       public function __construct( IContextSource $context, array $options ) {
                parent::__construct( $context );
 
                $msgs = [
@@ -87,10 +149,6 @@ class ContribsPager extends RangeChronologicalPager {
                }
                $this->getDateRangeCond( $startTimestamp, $endTimestamp );
 
-               // This property on IndexPager is set by $this->getIndexField() in parent::__construct().
-               // We need to reassign it here so that it is used when the actual query is ran.
-               $this->mIndexField = $this->getIndexField();
-
                // Most of this code will use the 'contributions' group DB, which can map to replica DBs
                // with extra user based indexes or partioning by user. The additional metadata
                // queries should use a regular replica DB since the lookup pattern is not all by user.
@@ -212,6 +270,22 @@ class ContribsPager extends RangeChronologicalPager {
                        $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
                        if ( $ipRangeConds ) {
                                $queryInfo['tables'][] = 'ip_changes';
+                               /**
+                                * These aliases make `ORDER BY rev_timestamp, rev_id` from {@see getIndexField} and
+                                * {@see getExtraSortFields} use the replicated `ipc_rev_timestamp` and `ipc_rev_id`
+                                * columns from the `ip_changes` table, for more efficient queries.
+                                * @see https://phabricator.wikimedia.org/T200259#4832318
+                                */
+                               $queryInfo['fields'] = array_merge(
+                                       [
+                                               'rev_timestamp' => 'ipc_rev_timestamp',
+                                               'rev_id' => 'ipc_rev_id',
+                                       ],
+                                       array_diff( $queryInfo['fields'], [
+                                               'rev_timestamp',
+                                               'rev_id',
+                                       ] )
+                               );
                                $queryInfo['join_conds']['ip_changes'] = [
                                        'LEFT JOIN', [ 'ipc_rev_id = rev_id' ]
                                ];
@@ -350,20 +424,57 @@ class ContribsPager extends RangeChronologicalPager {
        }
 
        /**
-        * Override of getIndexField() in IndexPager.
-        * For IP ranges, it's faster to use the replicated ipc_rev_timestamp
-        * on the `ip_changes` table than the rev_timestamp on the `revision` table.
-        * @return string Name of field
+        * @return string
         */
        public function getIndexField() {
-               if ( $this->isQueryableRange( $this->target ) ) {
-                       return 'ipc_rev_timestamp';
-               } else {
-                       return 'rev_timestamp';
-               }
+               // Note this is run via parent::__construct() *before* $this->target is set!
+               return 'rev_timestamp';
+       }
+
+       /**
+        * @return false|string
+        */
+       public function getTagFilter() {
+               return $this->tagFilter;
+       }
+
+       /**
+        * @return string
+        */
+       public function getContribs() {
+               return $this->contribs;
+       }
+
+       /**
+        * @return string
+        */
+       public function getTarget() {
+               return $this->target;
+       }
+
+       /**
+        * @return bool
+        */
+       public function isNewOnly() {
+               return $this->newOnly;
+       }
+
+       /**
+        * @return int|string
+        */
+       public function getNamespace() {
+               return $this->namespace;
+       }
+
+       /**
+        * @return string[]
+        */
+       protected function getExtraSortFields() {
+               // Note this is run via parent::__construct() *before* $this->target is set!
+               return [ 'rev_id' ];
        }
 
-       function doBatchLookups() {
+       protected function doBatchLookups() {
                # Do a link batch query
                $this->mResult->seek( 0 );
                $parentRevIds = [];
@@ -399,14 +510,14 @@ class ContribsPager extends RangeChronologicalPager {
        /**
         * @return string
         */
-       function getStartBody() {
+       protected function getStartBody() {
                return "<ul class=\"mw-contributions-list\">\n";
        }
 
        /**
         * @return string
         */
-       function getEndBody() {
+       protected function getEndBody() {
                return "</ul>\n";
        }