X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialListusers.php;h=d43a263f7e71ad60cc2b7112ca64ee72b17384f7;hb=23299ca8790bcf1aebcf54e0932b94338e630474;hp=cc3226dd38776673a95f8fd4aebd02d385d041f3;hpb=160c028526b4fd77b0423870b2837a799d558140;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialListusers.php b/includes/specials/SpecialListusers.php index cc3226dd38..d43a263f7e 100644 --- a/includes/specials/SpecialListusers.php +++ b/includes/specials/SpecialListusers.php @@ -34,6 +34,11 @@ */ class UsersPager extends AlphabeticPager { + /** + * @var array A array with user ids as key and a array of groups as value + */ + protected $userGroupCache; + /** * @param IContextSource $context * @param array $par (Default null) @@ -132,8 +137,6 @@ class UsersPager extends AlphabeticPager { 'user_name' => $this->creationSort ? 'MAX(user_name)' : 'user_name', 'user_id' => $this->creationSort ? 'user_id' : 'MAX(user_id)', 'edits' => 'MAX(user_editcount)', - 'numgroups' => 'COUNT(ug_group)', - 'singlegroup' => 'MAX(ug_group)', // the usergroup if there is only one 'creation' => 'MIN(user_registration)', 'ipb_deleted' => 'MAX(ipb_deleted)' // block/hide status ), @@ -150,7 +153,7 @@ class UsersPager extends AlphabeticPager { 'conds' => $conds ); - wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) ); + Hooks::run( 'SpecialListusersQueryInfo', array( $this, &$query ) ); return $query; } @@ -160,7 +163,7 @@ class UsersPager extends AlphabeticPager { * @return string */ function formatRow( $row ) { - if ( $row->user_id == 0 ) { #Bug 16487 + if ( $row->user_id == 0 ) { # Bug 16487 return ''; } @@ -176,7 +179,7 @@ class UsersPager extends AlphabeticPager { $lang = $this->getLanguage(); $groups = ''; - $groups_list = self::getGroups( $row->user_id ); + $groups_list = self::getGroups( intval( $row->user_id ), $this->userGroupCache ); if ( !$this->including && count( $groups_list ) > 0 ) { $list = array(); @@ -194,10 +197,8 @@ class UsersPager extends AlphabeticPager { $edits = ''; if ( !$this->including && $this->getConfig()->get( 'Edititis' ) ) { - // @todo fixme i18n issue: Hardcoded square brackets. - $edits = ' [' . - $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped() . - ']'; + $count = $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped(); + $edits = $this->msg( 'word-separator' )->escaped() . $this->msg( 'brackets', $count )->escaped(); } $created = ''; @@ -213,18 +214,45 @@ class UsersPager extends AlphabeticPager { ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : ''; - wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) ); + Hooks::run( 'SpecialListusersFormatRow', array( &$item, $row ) ); return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}{$blocked}" ); } function doBatchLookups() { $batch = new LinkBatch(); + $userIds = array(); # Give some pointers to make user links foreach ( $this->mResult as $row ) { $batch->add( NS_USER, $row->user_name ); $batch->add( NS_USER_TALK, $row->user_name ); + $userIds[] = $row->user_id; + } + + // Lookup groups for all the users + $dbr = wfGetDB( DB_SLAVE ); + $groupRes = $dbr->select( + 'user_groups', + array( 'ug_user', 'ug_group' ), + array( 'ug_user' => $userIds ), + __METHOD__ + ); + $cache = array(); + $groups = array(); + foreach ( $groupRes as $row ) { + $cache[intval( $row->ug_user )][] = $row->ug_group; + $groups[$row->ug_group] = true; } + $this->userGroupCache = $cache; + + // Add page of groups to link batch + foreach ( $groups as $group => $unused ) { + $groupPage = User::getGroupPage( $group ); + if ( $groupPage ) { + $batch->addObj( $groupPage ); + } + } + $batch->execute(); $this->mResult->rewind(); } @@ -235,6 +263,8 @@ class UsersPager extends AlphabeticPager { function getPageHeader() { list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() ); + $this->getOutput()->addModules( 'mediawiki.userSuggest' ); + # Form tag $out = Xml::openElement( 'form', @@ -243,13 +273,14 @@ class UsersPager extends AlphabeticPager { Xml::fieldset( $this->msg( 'listusers' )->text() ) . Html::hidden( 'title', $self ); - # Username field + # Username field (with autocompletion support) $out .= Xml::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' . Html::input( 'username', $this->requestedUser, 'text', array( + 'class' => 'mw-autocomplete-user', 'id' => 'offset', 'size' => 20, 'autofocus' => $this->requestedUser === '' @@ -257,13 +288,14 @@ class UsersPager extends AlphabeticPager { ) . ' '; # Group drop-down list - $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' ' . - Xml::openElement( 'select', array( 'name' => 'group', 'id' => 'group' ) ) . - Xml::option( $this->msg( 'group-all' )->text(), '' ); + $sel = new XmlSelect( 'group', 'group', $this->requestedGroup ); + $sel->addOption( $this->msg( 'group-all' )->text(), '' ); foreach ( $this->getAllGroups() as $group => $groupText ) { - $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup ); + $sel->addOption( $groupText, $group ); } - $out .= Xml::closeElement( 'select' ) . '
'; + + $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' '; + $out .= $sel->getHTML() . '
'; $out .= Xml::checkLabel( $this->msg( 'listusers-editsonly' )->text(), 'editsOnly', @@ -286,12 +318,12 @@ class UsersPager extends AlphabeticPager { ); $out .= '
'; - wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) ); + Hooks::run( 'SpecialListusersHeaderForm', array( $this, &$out ) ); # Submit button and form bottom $out .= Html::hidden( 'limit', $this->mLimit ); - $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ); - wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) ); + $out .= Xml::submitButton( $this->msg( 'listusers-submit' )->text() ); + Hooks::run( 'SpecialListusersHeader', array( $this, &$out ) ); $out .= Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ); @@ -324,7 +356,7 @@ class UsersPager extends AlphabeticPager { if ( $this->requestedUser != '' ) { $query['username'] = $this->requestedUser; } - wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) ); + Hooks::run( 'SpecialListusersDefaultQuery', array( $this, &$query ) ); return $query; } @@ -333,11 +365,17 @@ class UsersPager extends AlphabeticPager { * Get a list of groups the specified user belongs to * * @param int $uid User id + * @param array|null $cache * @return array */ - protected static function getGroups( $uid ) { - $user = User::newFromId( $uid ); - $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() ); + protected static function getGroups( $uid, $cache = null ) { + if ( $cache === null ) { + $user = User::newFromId( $uid ); + $effectiveGroups = $user->getEffectiveGroups(); + } else { + $effectiveGroups = isset( $cache[$uid] ) ? $cache[$uid] : array(); + } + $groups = array_diff( $effectiveGroups, User::getImplicitGroups() ); return $groups; } @@ -352,7 +390,7 @@ class UsersPager extends AlphabeticPager { protected static function buildGroupLink( $group, $username ) { return User::makeGroupLinkHtml( $group, - htmlspecialchars( User::getGroupMember( $group, $username ) ) + User::getGroupMember( $group, $username ) ); } } @@ -399,15 +437,12 @@ class SpecialListUsers extends IncludableSpecialPage { } /** - * Return an array of subpages beginning with $search that this special page will accept. + * Return an array of subpages that this special page will accept. * - * @param string $search Prefix to search for - * @param int $limit Maximum number of results to return - * @return string[] Matching subpages + * @return string[] subpages */ - public function prefixSearchSubpages( $search, $limit = 10 ) { - $subpages = User::getAllGroups(); - return self::prefixSearchArray( $search, $limit, $subpages ); + public function getSubpagesForPrefixSearch() { + return User::getAllGroups(); } protected function getGroupName() {