function __construct($group=null) {
global $wgRequest;
$this->requestedGroup = $group != "" ? $group : $wgRequest->getVal( 'group' );
- $this->requestedUser = $wgRequest->getText( 'username', $this->mOffset );
-
+ $un = $wgRequest->getText( 'username' );
+ $this->requestedUser = '';
+ if ( $un != '' ) {
+ $username = Title::makeTitleSafe( NS_USER, $un );
+ if( ! is_null( $username ) ) {
+ $this->requestedUser = $username->getText();
+ }
+ }
parent::__construct();
}
function getQueryInfo() {
$conds=array();
+ // don't show hidden names
+ $conds[]='ipb_deleted IS NULL OR ipb_deleted = 0';
if ($this->requestedGroup != "") {
$conds['ug_group'] = $this->requestedGroup;
}
if ($this->requestedUser != "") {
$conds[] = 'user_name >= ' . wfGetDB()->addQuotes( $this->requestedUser );
}
-
- list ($user,$user_groups) = wfGetDB()->tableNamesN('user','user_groups');
-
+
+ list ($user,$user_groups,$ipblocks) = wfGetDB()->tableNamesN('user','user_groups','ipblocks');
+
return array(
- 'tables' => " $user LEFT JOIN $user_groups ON user_id=ug_user ",
+ 'tables' => " $user LEFT JOIN $user_groups ON user_id=ug_user LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ",
'fields' => array('user_name',
'MAX(user_id) AS user_id',
'COUNT(ug_group) AS numgroups',
'options' => array('GROUP BY' => 'user_name'),
'conds' => $conds
);
+
}
-
- function formatRow($row) {
- $userPage = Title::makeTitle(NS_USER, $row->user_name);
+
+ 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->requestedGroup 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);
+
+ if( $row->numgroups > 1 || ( $this->requestedGroup && $row->numgroups == 1 ) ) {
+ $list = array();
+ foreach( self::getGroups( $row->user_id ) as $group )
+ $list[] = self::buildGroupLink( $group );
+ $groups = implode( ', ', $list );
+ } elseif( $row->numgroups == 1 ) {
+ $groups = self::buildGroupLink( $row->singlegroup );
} else {
- $groups ='';
+ $groups = '';
}
- return '<li>' . wfSpecialList ($name, $groups) .'</li>';
+
+ return '<li>' . wfSpecialList( $name, $groups ) . '</li>';
}
-
+
function getBody() {
if (!$this->mQueryDone) {
$this->doQuery();
}
$batch = new LinkBatch;
- $db = $this->mDb;
-
+
$this->mResult->rewind();
-
+
while ( $row = $this->mResult->fetchObject() ) {
$batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
}
$this->mResult->rewind();
return parent::getBody();
}
-
+
function getPageHeader( ) {
+ global $wgRequest;
$self = $this->getTitle();
# Form tag
- $out = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
-
+ $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $self->getLocalUrl() ) ) .
+ '<fieldset>' .
+ Xml::element( 'legend', array(), wfMsg( 'listusers' ) );
+
+ # Username field
+ $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
+ Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
+
+ if( $this->mLimit )
+ $out .= Xml::hidden( 'limit', $this->mLimit );
+
# Group drop-down list
- $out .= wfElement( 'label', array( 'for' => 'group' ), wfMsg( 'group' ) ) . ' ';
- $out .= wfOpenElement( 'select', array( 'name' => 'group', 'id' => 'group' ) );
- $out .= wfElement( 'option', array( 'value' => '' ), wfMsg( 'group-all' ) ); # Item for "all groups"
+ $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
+ Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
+ Xml::option( wfMsg( 'group-all' ), '' ); # Item for "all groups"
+
$groups = User::getAllGroups();
foreach( $groups as $group ) {
$attribs = array( 'value' => $group );
- if( $group == $this->requestedGroup )
- $attribs['selected'] = 'selected';
- $out .= wfElement( 'option', $attribs, User::getGroupName( $group ) );
+ $attribs['selected'] = ( $group == $this->requestedGroup ) ? 'selected' : '';
+ $out .= Xml::option( User::getGroupName( $group ), $attribs['value'], $attribs['selected'] );
}
- $out .= wfCloseElement( 'select' ) . ' ';;# . wfElement( 'br' );
-
- # Username field
- $out .= wfElement( 'label', array( 'for' => 'offset' ), wfMsg( 'listusersfrom' ) ) . ' ';
- $out .= wfElement( 'input', array( 'type' => 'text', 'id' => 'username', 'name' => 'username',
- 'value' => $this->requestedUser ) ) . ' ';
-
- if( $this->mLimit )
- $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'limit', 'value' => $this->mLimit ) );
+ $out .= Xml::closeElement( 'select' ) . ' ';
# Submit button and form bottom
- $out .= wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'allpagessubmit' ) ) );
- $out .= wfCloseElement( 'form' );
+ $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
+ '</fieldset>' .
+ Xml::closeElement( 'form' );
return $out;
}
-
+
/**
* Preserve group and username offset parameters when paging
* @return array
$query['username'] = $this->requestedUser;
return $query;
}
+
+ /**
+ * Get a list of groups the specified user belongs to
+ *
+ * @param int $uid
+ * @return array
+ */
+ private static function getGroups( $uid ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $groups = array();
+ $res = $dbr->select( 'user_groups', 'ug_group', array( 'ug_user' => $uid ), __METHOD__ );
+ if( $res && $dbr->numRows( $res ) > 0 ) {
+ while( $row = $dbr->fetchObject( $res ) )
+ $groups[] = $row->ug_group;
+ $dbr->freeResult( $res );
+ }
+ return $groups;
+ }
+
+ /**
+ * Format a link to a group description page
+ *
+ * @param string $group
+ * @return string
+ */
+ private static function buildGroupLink( $group ) {
+ static $cache = array();
+ if( !isset( $cache[$group] ) )
+ $cache[$group] = User::makeGroupLinkHtml( $group, User::getGroupMember( $group ) );
+ return $cache[$group];
+ }
}
/**
} else {
$s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
};
- $wgOut->addHTML( $s );
+
+ $wgOut->addHTML( $s );
}
?>