Merge "Revert "Use display name in category page subheadings if provided""
[lhc/web/wiklou.git] / includes / specials / pagers / ActiveUsersPager.php
index 0d3bc9a..ea906b7 100644 (file)
@@ -36,14 +36,9 @@ class ActiveUsersPager extends UsersPager {
        protected $opts;
 
        /**
-        * @var array
-        */
-       protected $hideGroups = [];
-
-       /**
-        * @var array
+        * @var string[]
         */
-       protected $hideRights = [];
+       protected $groups;
 
        /**
         * @var array
@@ -52,15 +47,15 @@ class ActiveUsersPager extends UsersPager {
 
        /**
         * @param IContextSource $context
-        * @param null $group Unused
-        * @param string $par Parameter passed to the page
+        * @param FormOptions $opts
         */
-       function __construct( IContextSource $context = null, $group = null, $par = null ) {
+       function __construct( IContextSource $context = null, FormOptions $opts ) {
                parent::__construct( $context );
 
                $this->RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' );
-               $un = $this->getRequest()->getText( 'username', $par );
                $this->requestedUser = '';
+
+               $un = $opts->getValue( 'username' );
                if ( $un != '' ) {
                        $username = Title::makeTitleSafe( NS_USER, $un );
                        if ( !is_null( $username ) ) {
@@ -68,23 +63,7 @@ class ActiveUsersPager extends UsersPager {
                        }
                }
 
-               $this->setupOptions();
-       }
-
-       public function setupOptions() {
-               $this->opts = new FormOptions();
-
-               $this->opts->add( 'hidebots', false, FormOptions::BOOL );
-               $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
-
-               $this->opts->fetchValuesFromRequest( $this->getRequest() );
-
-               if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
-                       $this->hideRights[] = 'bot';
-               }
-               if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
-                       $this->hideGroups[] = 'sysop';
-               }
+               $this->groups = $opts->getValue( 'groups' );
        }
 
        function getIndexField() {
@@ -96,6 +75,7 @@ class ActiveUsersPager extends UsersPager {
 
                $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
                $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX ) - $activeUserSeconds );
+               $tables = [ 'querycachetwo', 'user', 'recentchanges' ];
                $conds = [
                        'qcc_type' => 'activeusers',
                        'qcc_namespace' => NS_USER,
@@ -109,6 +89,11 @@ class ActiveUsersPager extends UsersPager {
                if ( $this->requestedUser != '' ) {
                        $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser );
                }
+               if ( $this->groups !== [] ) {
+                       $tables[] = 'user_groups';
+                       $conds[] = 'ug_user = user_id';
+                       $conds['ug_group'] = $this->groups;
+               }
                if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
                        $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
                                        'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
@@ -122,7 +107,7 @@ class ActiveUsersPager extends UsersPager {
                }
 
                return [
-                       'tables' => [ 'querycachetwo', 'user', 'recentchanges' ],
+                       'tables' => $tables,
                        'fields' => [ 'user_name', 'user_id', 'recentedits' => 'COUNT(*)', 'qcc_title' ],
                        'options' => $options,
                        'conds' => $conds
@@ -165,26 +150,8 @@ class ActiveUsersPager extends UsersPager {
                $list = [];
                $user = User::newFromId( $row->user_id );
 
-               // User right filter
-               foreach ( $this->hideRights as $right ) {
-                       // Calling User::getRights() within the loop so that
-                       // if the hideRights() filter is empty, we don't have to
-                       // trigger the lazy-init of the big userrights array in the
-                       // User object
-                       if ( in_array( $right, $user->getRights() ) ) {
-                               return '';
-                       }
-               }
-
-               // User group filter
-               // Note: This is a different loop than for user rights,
-               // because we're reusing it to build the group links
-               // at the same time
                $groups_list = self::getGroups( intval( $row->user_id ), $this->userGroupCache );
                foreach ( $groups_list as $group ) {
-                       if ( in_array( $group, $this->hideGroups ) ) {
-                               return '';
-                       }
                        $list[] = self::buildGroupLink( $group, $userName );
                }
 
@@ -203,52 +170,4 @@ class ActiveUsersPager extends UsersPager {
                return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );
        }
 
-       function getPageHeader() {
-               $self = $this->getTitle();
-               $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
-
-               # Form tag
-               $out = Xml::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] );
-               $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
-               $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
-
-               # Username field (with autocompletion support)
-               $this->getOutput()->addModules( 'mediawiki.userSuggest' );
-               $out .= Xml::inputLabel(
-                               $this->msg( 'activeusers-from' )->text(),
-                               'username',
-                               'offset',
-                               20,
-                               $this->requestedUser,
-                               [
-                                       'class' => 'mw-ui-input-inline mw-autocomplete-user',
-                                       'tabindex' => 1,
-                               ] + (
-                                       // Set autofocus on blank input
-                               $this->requestedUser === '' ? [ 'autofocus' => '' ] : []
-                               )
-                       ) . '<br />';
-
-               $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
-                       'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ), [ 'tabindex' => 2 ] );
-
-               $out .= Xml::checkLabel(
-                               $this->msg( 'activeusers-hidesysops' )->text(),
-                               'hidesysops',
-                               'hidesysops',
-                               $this->opts->getValue( 'hidesysops' ),
-                               [ 'tabindex' => 3 ]
-                       ) . '<br />';
-
-               # Submit button and form bottom
-               $out .= Xml::submitButton(
-                               $this->msg( 'activeusers-submit' )->text(),
-                               [ 'tabindex' => 4 ]
-                       ) . "\n";
-               $out .= Xml::closeElement( 'fieldset' );
-               $out .= Xml::closeElement( 'form' );
-
-               return $out;
-       }
-
 }