From: Domas Mituzas Date: Thu, 15 Feb 2007 18:48:12 +0000 (+0000) Subject: Use AlphabeticPager for Special:Listusers X-Git-Tag: 1.31.0-rc.0~54037 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=e37d9b43d4c0dc143329663deb0365c0abd07905;p=lhc%2Fweb%2Fwiklou.git Use AlphabeticPager for Special:Listusers --- diff --git a/includes/SpecialListusers.php b/includes/SpecialListusers.php index c0292c0dd3..ae75fa3241 100644 --- a/includes/SpecialListusers.php +++ b/includes/SpecialListusers.php @@ -33,44 +33,85 @@ * * @addtogroup SpecialPage */ -class ListUsersPage extends QueryPage { - var $requestedGroup = ''; - var $requestedUser = ''; - function getName() { - return 'Listusers'; +class UsersPager extends AlphabeticPager { + + function __construct($group=null) { + global $wgRequest; + $this->groupRequested = $group != "" ? $group : $wgRequest->getVal( 'group' ); + + parent::__construct(); } - function isSyndicated() { return false; } - /** - * Not expensive, this class won't work properly with the caching system anyway - */ - function isExpensive() { - return false; + + function getIndexField() { + return 'user_name'; } - /** - * Fetch user page links and cache their existence - */ - function preprocessResults( &$db, &$res ) { + function getQueryInfo() { + $conds=array(); + if ($this->groupRequested != "") { + $conds['ug_group'] = $this->groupRequested; + } + + list ($user,$user_groups) = wfGetDB()->tableNamesN('user','user_groups'); + + return array( + 'tables' => " $user LEFT JOIN $user_groups ON user_id=ug_user ", + 'fields' => array('user_name', + 'MAX(user_id) AS user_id', + 'COUNT(ug_group) AS numgroups', + 'MAX(ug_group) AS singlegroup'), + 'options' => array('GROUP BY' => 'user_name'), + 'conds' => $conds + ); + } + + function formatRow($row) { + $userPage = Title::makeTitle(NS_USER, $row->user_name); + $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) ); + $groups = array(); + if ($row->numgroups > 1 || ( $this->groupRequested and $row->numgroups == 1) ) { + $dbr = wfGetDB(DB_SLAVE); + $result = $dbr->select( 'user_groups', 'ug_group', + array( 'ug_user' => $row->user_id ), + 'UsersPager::formatRow' ); + while ( $group = $dbr->fetchObject($result)) { + $groups[$group->ug_group] = User::getGroupMember ( $group->ug_group ); + } + $dbr->freeResult($result); + } elseif ($row->numgroups == 1 ) { // MAX hack inside query :) + $groups[$row->singlegroup] = User::getGroupMember( $row->singlegroup ); + } + + if ( count($groups) > 0 ) { + foreach( $groups as $group => $desc ) { + $list[] = User::makeGroupLinkHTML( $group, $desc); + } + $groups = implode( ', ', $list); + } else { + $groups =''; + } + return '
  • ' . wfSpecialList ($name, $groups) .'
  • '; + } + + function getBody() { + if (!$this->mQueryDone) { + $this->doQuery(); + } $batch = new LinkBatch; - while ( $row = $db->fetchObject( $res ) ) { - $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) ); + $db = $this->mDb; + + $this->mResult->rewind(); + + while ( $row = $this->mResult->fetchObject() ) { + $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) ); } $batch->execute(); - - // Back to start for display - if( $db->numRows( $res ) > 0 ) { - // If there are no rows we get an error seeking. - $db->dataSeek( $res, 0 ); - } + $this->mResult->rewind(); + return parent::getBody(); } - - /** - * Show a drop down list to select a group as well as a user name - * search box. - * @todo localize - */ + function getPageHeader( ) { $self = $this->getTitle(); @@ -91,15 +132,12 @@ class ListUsersPage extends QueryPage { $out .= wfCloseElement( 'select' ) . ' ';;# . wfElement( 'br' ); # Username field - $out .= wfElement( 'label', array( 'for' => 'username' ), wfMsg( 'listusersfrom' ) ) . ' '; - $out .= wfElement( 'input', array( 'type' => 'text', 'id' => 'username', 'name' => 'username', + $out .= wfElement( 'label', array( 'for' => 'offset' ), wfMsg( 'listusersfrom' ) ) . ' '; + $out .= wfElement( 'input', array( 'type' => 'text', 'id' => 'offset', 'name' => 'offset', 'value' => $this->requestedUser ) ) . ' '; - # Preserve offset and limit - if( $this->offset ) - $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'offset', 'value' => $this->offset ) ); - if( $this->limit ) - $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'limit', 'value' => $this->limit ) ); + if( $this->mLimit ) + $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'limit', 'value' => $this->mLimit ) ); # Submit button and form bottom $out .= wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'allpagessubmit' ) ) ); @@ -107,100 +145,6 @@ class ListUsersPage extends QueryPage { return $out; } - - function getSQL() { - global $wgDBtype; - $dbr = wfGetDB( DB_SLAVE ); - $user = $dbr->tableName( 'user' ); - $user_groups = $dbr->tableName( 'user_groups' ); - - // We need to get an 'atomic' list of users, so that we - // don't break the list half-way through a user's group set - // and so that lists by group will show all group memberships. - // - // On MySQL 4.1 we could use GROUP_CONCAT to grab group - // assignments together with users pretty easily. On other - // versions, it's not so easy to do it consistently. - // For now we'll just grab the number of memberships, so - // we can then do targetted checks on those who are in - // non-default groups as we go down the list. - - $userspace = NS_USER; - $sql = "SELECT 'Listusers' as type, $userspace AS namespace, user_name AS title, " . - "user_name as value, user_id, COUNT(ug_group) as numgroups " . - "FROM $user ". - "LEFT JOIN $user_groups ON user_id=ug_user " . - $this->userQueryWhere( $dbr ) . - " GROUP BY user_name"; - if ( $wgDBtype != 'mysql' ) { - $sql .= ",user_id"; - } - return $sql; - } - - function userQueryWhere( &$dbr ) { - $conds = $this->userQueryConditions( $dbr ); - return empty( $conds ) - ? "" - : "WHERE " . $dbr->makeList( $conds, LIST_AND ); - } - - function userQueryConditions( $dbr ) { - $conds = array(); - if( $this->requestedGroup != '' ) { - $conds['ug_group'] = $this->requestedGroup; - } - if( $this->requestedUser != '' ) { - $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser ); - } - return $conds; - } - - function linkParameters() { - $conds = array(); - if( $this->requestedGroup != '' ) { - $conds['group'] = $this->requestedGroup; - } - if( $this->requestedUser != '' ) { - $conds['username'] = $this->requestedUser; - } - return $conds; - } - - function sortDescending() { - return false; - } - - function formatResult( $skin, $result ) { - $userPage = Title::makeTitle( $result->namespace, $result->title ); - $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) ); - $groups = null; - - if( !isset( $result->numgroups ) || $result->numgroups > 0 ) { - $dbr = wfGetDB( DB_SLAVE ); - $result = $dbr->select( 'user_groups', - array( 'ug_group' ), - array( 'ug_user' => $result->user_id ), - 'ListUsersPage::formatResult' ); - $groups = array(); - while( $row = $dbr->fetchObject( $result ) ) { - $groups[$row->ug_group] = User::getGroupMember( $row->ug_group ); - } - $dbr->freeResult( $result ); - - if( count( $groups ) > 0 ) { - foreach( $groups as $group => $desc ) { - $list[] = User::makeGroupLinkHTML( $group, $desc ); - } - $groups = implode( ', ', $list ); - } else { - $groups = ''; - } - - } - - return wfSpecialList( $name, $groups ); - } } /** @@ -208,25 +152,23 @@ class ListUsersPage extends QueryPage { * $par string (optional) A group to list users from */ function wfSpecialListusers( $par = null ) { - global $wgRequest; + global $wgRequest, $wgOut; list( $limit, $offset ) = wfCheckLimits(); - - $slu = new ListUsersPage(); - - /** - * Get some parameters - */ $groupTarget = isset($par) ? $par : $wgRequest->getVal( 'group' ); - $slu->requestedGroup = $groupTarget; - - # 'Validate' the username first - $username = $wgRequest->getText( 'username', '' ); - $user = User::newFromName( $username ); - $slu->requestedUser = is_object( $user ) ? $user->getName() : ''; - - return $slu->doQuery( $offset, $limit ); + + $up = new UsersPager($par); + $wgOut->addHTML( + $up->getPageHeader(). + $up->getNavigationBar(). + '' . + $up->getNavigationBar() + ); + + } ?>