<?php
+
# Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
# Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
#
+# © 2006 Rob Church <robchur@gmail.com>
+#
# http://www.mediawiki.org/
-#
+#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# http://www.gnu.org/copyleft/gpl.html
/**
*
- * @package MediaWiki
- * @subpackage SpecialPage
- */
-
-/**
- *
+ * @addtogroup SpecialPage
*/
-require_once('QueryPage.php');
/**
* This class is used to get a list of user. The ones with specials
* rights (sysop, bureaucrat, developer) will have them displayed
* next to their names.
*
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
*/
-class ListUsersPage extends QueryPage {
- var $requestedGroup = '';
- var $requestedUser = '';
- var $previousResult = false;
- var $concatGroups = '';
-
- function getName() {
- return 'Listusers';
+
+class UsersPager extends AlphabeticPager {
+
+ function __construct($group=null) {
+ global $wgRequest;
+ $this->requestedGroup = $group != "" ? $group : $wgRequest->getVal( 'group' );
+ $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 isSyndicated() { return false; }
- /**
- * Show a drop down list to select a group as well as a user name
- * search box.
- * @todo localize
- */
- function getPageHeader( ) {
- global $wgScript;
-
- // Various variables used for the form
- $action = htmlspecialchars( $wgScript );
- $title = Title::makeTitle( NS_SPECIAL, 'Listusers' );
- $special = htmlspecialchars( $title->getPrefixedDBkey() );
-
- // form header
- $out = '<form method="get" action="'.$action.'">' .
- '<input type="hidden" name="title" value="'.$special.'" />' .
- wfMsg( 'grouplevels-editgroup-name' ) . '<select name="group">';
-
- // get all group names and id
- $dbr = & wfGetDB( DB_SLAVE );
- $group = $dbr->tableName( 'group' );
- $sql = "SELECT group_id, group_name FROM $group;";
- $result = $dbr->query($sql);
-
- // we want a default empty group
- $out.= '<option value=""></option>';
-
- // build the dropdown list menu using datas from the database
- while($agroup = $dbr->fetchObject( $result )) {
- $selected = ($agroup->group_id == $this->requestedGroup) ? ' selected ' : '' ;
- $out.= '<option value="'.$agroup->group_id.'" '.$selected.'>'.$agroup->group_name.'</option>';
+
+ function getIndexField() {
+ return 'user_name';
+ }
+
+ 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;
}
- $out .= '</select> ';
+ if ($this->requestedUser != "") {
+ $conds[] = 'user_name >= ' . wfGetDB()->addQuotes( $this->requestedUser );
+ }
+
+ list ($user,$user_groups,$ipblocks) = wfGetDB()->tableNamesN('user','user_groups','ipblocks');
- $out .= wfMsg( 'specialloguserlabel' ) . '<input type="text" name="username" /> ';
+ return array(
+ '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',
+ 'MAX(ug_group) AS singlegroup'),
+ 'options' => array('GROUP BY' => 'user_name'),
+ 'conds' => $conds
+ );
- // OK button, end of form.
- $out .= '<input type="submit" /></form>';
- // congratulations the form is now build
- return $out;
}
-
- function getSQL() {
- $dbr =& wfGetDB( DB_SLAVE );
- /* system showing possible actions for users
- $user = $dbr->tableName( 'user' );
- $user_rights = $dbr->tableName( 'user_rights' );
- $userspace = Namespace::getUser();
- return "SELECT ur_rights as type, $userspace as namespace, user_name as title, " .
- "user_name as value FROM $user LEFT JOIN $user_rights ON user_id = ur_user";
- */
- /** Show groups instead */
- $user = $dbr->tableName( 'user' );
- $group = $dbr->tableName( 'group' );
- $user_groups = $dbr->tableName( 'user_groups' );
-
- $userspace = NS_USER;
- $sql = "SELECT group_name as type, $userspace AS namespace, user_name AS title, user_name as value " .
- "FROM $user ".
- "LEFT JOIN $user_groups ON user_id =ug_user " .
- "LEFT JOIN $group ON ug_group = group_id ";
-
- if($this->requestedGroup != '') {
- $sql .= "WHERE group_id= '" . IntVal( $this->requestedGroup ) . "' ";
- if($this->requestedUser != '') {
- $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' ';
- }
+
+ function formatRow( $row ) {
+ $userPage = Title::makeTitle( NS_USER, $row->user_name );
+ $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
+
+ 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 {
- if($this->requestedUser !='') {
- $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' ';
- }
- }
-
- return $sql;
- }
-
- /**
- * When calling formatResult we output the previous result instead of the
- * current one. We need an additional step to flush out the last result.
- */
- function tryLastResult( ) {
- return true;
+ $groups = '';
+ }
+
+ return '<li>' . wfSpecialList( $name, $groups ) . '</li>';
}
-
- function sortDescending() {
- return false;
+
+ function getBody() {
+ if (!$this->mQueryDone) {
+ $this->doQuery();
+ }
+ $batch = new LinkBatch;
+
+ $this->mResult->rewind();
+
+ while ( $row = $this->mResult->fetchObject() ) {
+ $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
+ }
+ $batch->execute();
+ $this->mResult->rewind();
+ return parent::getBody();
}
- function appendGroups($group) {
- $this->concatGroups .= $group.' ';
+ function getPageHeader( ) {
+ global $wgScript, $wgRequest;
+ $self = $this->getTitle();
+
+ # Form tag
+ $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
+ '<fieldset>' .
+ Xml::element( 'legend', array(), wfMsg( 'listusers' ) );
+ $out .= Xml::hidden( 'title', $self->getPrefixedDbKey() );
+
+ # Username field
+ $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
+ Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
+
+ # Group drop-down list
+ $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
+ Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
+ Xml::option( wfMsg( 'group-all' ), '' );
+ foreach( User::getAllGroups() as $group )
+ $out .= Xml::option( User::getGroupName( $group ), $group, $group == $this->requestedGroup );
+ $out .= Xml::closeElement( 'select' ) . ' ';
+
+ # Submit button and form bottom
+ if( $this->mLimit )
+ $out .= Xml::hidden( 'limit', $this->mLimit );
+ $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
+ '</fieldset>' .
+ Xml::closeElement( 'form' );
+
+ return $out;
}
- function clearGroups() {
- $this->concatGroups = '';
+ /**
+ * Preserve group and username offset parameters when paging
+ * @return array
+ */
+ function getDefaultQuery() {
+ $query = parent::getDefaultQuery();
+ if( $this->requestedGroup != '' )
+ $query['group'] = $this->requestedGroup;
+ if( $this->requestedUser != '' )
+ $query['username'] = $this->requestedUser;
+ return $query;
}
-/*
- var $previousResult = false;
- var $concatGroups = '';
-*/
- function formatResult( $skin, $result ) {
- global $wgContLang;
- $name = false;
-
- if($this->previousResult->title != $result->title && $this->previousResult != false) {
- // Different username, give back name(group1,group2)
- $name = $skin->makeLink( $wgContLang->getNsText($this->previousResult->namespace) . ':' . $this->previousResult->title, $this->previousResult->title );
- $name .= $this->concatGroups ? '('.substr($this->concatGroups,0,-1).')' : '';
- $this->clearGroups();
- }
- if($result->type != '') {
- $this->appendGroups( $skin->makeLink( wfMsgForContent( 'administrators' ), $result->type ) );
- }
+ /**
+ * 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;
+ }
- $this->previousResult = $result;
- return $name;
+ /**
+ * 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];
}
}
/**
* constructor
+ * $par string (optional) A group to list users from
*/
-function wfSpecialListusers() {
- global $wgRequest;
-
- list( $limit, $offset ) = wfCheckLimits();
-
- $slu = new ListUsersPage();
-
- /**
- * Get some parameters
- */
- $slu->requestedGroup = $wgRequest->getVal('group');
- $slu->requestedUser = $wgRequest->getVal('username');
-
- return $slu->doQuery( $offset, $limit );
+function wfSpecialListusers( $par = null ) {
+ global $wgRequest, $wgOut;
+
+ $up = new UsersPager($par);
+
+ # getBody() first to check, if empty
+ $usersbody = $up->getBody();
+ $s = $up->getPageHeader();
+ if( $usersbody ) {
+ $s .= $up->getNavigationBar();
+ $s .= '<ul>' . $usersbody . '</ul>';
+ $s .= $up->getNavigationBar() ;
+ } else {
+ $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
+ };
+
+ $wgOut->addHTML( $s );
}
-?>
+