00001 <?php
00002
00003 # Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
00004 # Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
00005 #
00006 # © 2006 Rob Church <robchur@gmail.com>
00007 #
00008 # http://www.mediawiki.org/
00009 #
00010 # This program is free software; you can redistribute it and/or modify
00011 # it under the terms of the GNU General Public License as published by
00012 # the Free Software Foundation; either version 2 of the License, or
00013 # (at your option) any later version.
00014 #
00015 # This program is distributed in the hope that it will be useful,
00016 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 # GNU General Public License for more details.
00019 #
00020 # You should have received a copy of the GNU General Public License along
00021 # with this program; if not, write to the Free Software Foundation, Inc.,
00022 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00023 # http://www.gnu.org/copyleft/gpl.html
00024
00036 class UsersPager extends AlphabeticPager {
00037
00038 function __construct( $par=null ) {
00039 global $wgRequest;
00040 $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
00041 $symsForAll = array( '*', 'user' );
00042 if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) {
00043 $this->requestedGroup = $par;
00044 $un = $wgRequest->getText( 'username' );
00045 } else if ( count( $parms ) == 2 ) {
00046 $this->requestedGroup = $parms[0];
00047 $un = $parms[1];
00048 } else {
00049 $this->requestedGroup = $wgRequest->getVal( 'group' );
00050 $un = ( $par != '' ) ? $par : $wgRequest->getText( 'username' );
00051 }
00052 if ( in_array( $this->requestedGroup, $symsForAll ) ) {
00053 $this->requestedGroup = '';
00054 }
00055 $this->editsOnly = $wgRequest->getBool( 'editsOnly' );
00056 $this->creationSort = $wgRequest->getBool( 'creationSort' );
00057
00058 $this->requestedUser = '';
00059 if ( $un != '' ) {
00060 $username = Title::makeTitleSafe( NS_USER, $un );
00061 if( ! is_null( $username ) ) {
00062 $this->requestedUser = $username->getText();
00063 }
00064 }
00065 parent::__construct();
00066 }
00067
00068
00069 function getIndexField() {
00070 return $this->creationSort ? 'user_id' : 'user_name';
00071 }
00072
00073 function getQueryInfo() {
00074 $dbr = wfGetDB( DB_SLAVE );
00075 $conds = array();
00076
00077 $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0';
00078 if( $this->requestedGroup != '' ) {
00079 $conds['ug_group'] = $this->requestedGroup;
00080 $useIndex = '';
00081 } else {
00082 $useIndex = $dbr->useIndexClause( $this->creationSort ? 'PRIMARY' : 'user_name');
00083 }
00084 if( $this->requestedUser != '' ) {
00085 # Sorted either by account creation or name
00086 if( $this->creationSort ) {
00087 $conds[] = 'user_id >= ' . User::idFromName( $this->requestedUser );
00088 } else {
00089 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
00090 }
00091 }
00092 if( $this->editsOnly ) {
00093 $conds[] = 'user_editcount > 0';
00094 }
00095
00096 list ($user,$user_groups,$ipblocks) = $dbr->tableNamesN('user','user_groups','ipblocks');
00097
00098 $query = array(
00099 'tables' => " $user $useIndex LEFT JOIN $user_groups ON user_id=ug_user
00100 LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ",
00101 'fields' => array(
00102 $this->creationSort ? 'MAX(user_name) AS user_name' : 'user_name',
00103 $this->creationSort ? 'user_id' : 'MAX(user_id) AS user_id',
00104 'MAX(user_editcount) AS edits',
00105 'COUNT(ug_group) AS numgroups',
00106 'MAX(ug_group) AS singlegroup',
00107 'MIN(user_registration) AS creation'),
00108 'options' => array('GROUP BY' => $this->creationSort ? 'user_id' : 'user_name'),
00109 'conds' => $conds
00110 );
00111
00112 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
00113 return $query;
00114 }
00115
00116 function formatRow( $row ) {
00117 global $wgLang;
00118
00119 $userPage = Title::makeTitle( NS_USER, $row->user_name );
00120 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
00121
00122 if( $row->numgroups > 1 || ( $this->requestedGroup && $row->numgroups == 1 ) ) {
00123 $list = array();
00124 foreach( self::getGroups( $row->user_id ) as $group )
00125 $list[] = self::buildGroupLink( $group );
00126 $groups = $wgLang->commaList( $list );
00127 } elseif( $row->numgroups == 1 ) {
00128 $groups = self::buildGroupLink( $row->singlegroup );
00129 } else {
00130 $groups = '';
00131 }
00132
00133 $item = wfSpecialList( $name, $groups );
00134
00135 global $wgEdititis;
00136 if ( $wgEdititis ) {
00137 $editCount = $wgLang->formatNum( $row->edits );
00138 $edits = ' [' . wfMsgExt( 'usereditcount', 'parsemag', $editCount ) . ']';
00139 } else {
00140 $edits = '';
00141 }
00142
00143 $created = '';
00144 # Some rows may be NULL
00145 if( $row->creation ) {
00146 $d = $wgLang->date( wfTimestamp( TS_MW, $row->creation ), true );
00147 $t = $wgLang->time( wfTimestamp( TS_MW, $row->creation ), true );
00148 $created = ' (' . wfMsgHtml( 'usercreated', $d, $t ) . ')';
00149 }
00150
00151 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
00152 return "<li>{$item}{$edits}{$created}</li>";
00153 }
00154
00155 function getBody() {
00156 if( !$this->mQueryDone ) {
00157 $this->doQuery();
00158 }
00159 $this->mResult->rewind();
00160 $batch = new LinkBatch;
00161 while ( $row = $this->mResult->fetchObject() ) {
00162 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
00163 }
00164 $batch->execute();
00165 $this->mResult->rewind();
00166 return parent::getBody();
00167 }
00168
00169 function getPageHeader( ) {
00170 global $wgScript, $wgRequest;
00171 $self = $this->getTitle();
00172
00173 # Form tag
00174 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
00175 Xml::fieldset( wfMsg( 'listusers' ) ) .
00176 Xml::hidden( 'title', $self->getPrefixedDbKey() );
00177
00178 # Username field
00179 $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
00180 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
00181
00182 # Group drop-down list
00183 $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
00184 Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
00185 Xml::option( wfMsg( 'group-all' ), '' );
00186 foreach( $this->getAllGroups() as $group => $groupText )
00187 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
00188 $out .= Xml::closeElement( 'select' ) . '<br/>';
00189 $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly );
00190 $out .= ' ';
00191 $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort );
00192 $out .= '<br/>';
00193
00194 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
00195
00196 # Submit button and form bottom
00197 $out .= Xml::hidden( 'limit', $this->mLimit );
00198 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
00199 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
00200 $out .= Xml::closeElement( 'fieldset' ) .
00201 Xml::closeElement( 'form' );
00202
00203 return $out;
00204 }
00205
00210 function getAllGroups() {
00211 $result = array();
00212 foreach( User::getAllGroups() as $group ) {
00213 $result[$group] = User::getGroupName( $group );
00214 }
00215 asort( $result );
00216 return $result;
00217 }
00218
00223 function getDefaultQuery() {
00224 $query = parent::getDefaultQuery();
00225 if( $this->requestedGroup != '' )
00226 $query['group'] = $this->requestedGroup;
00227 if( $this->requestedUser != '' )
00228 $query['username'] = $this->requestedUser;
00229 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
00230 return $query;
00231 }
00232
00239 protected static function getGroups( $uid ) {
00240 $user = User::newFromId( $uid );
00241 $groups = array_diff( $user->getEffectiveGroups(), $user->getImplicitGroups() );
00242 return $groups;
00243 }
00244
00251 protected static function buildGroupLink( $group ) {
00252 static $cache = array();
00253 if( !isset( $cache[$group] ) )
00254 $cache[$group] = User::makeGroupLinkHtml( $group, User::getGroupMember( $group ) );
00255 return $cache[$group];
00256 }
00257 }
00258
00263 function wfSpecialListusers( $par = null ) {
00264 global $wgRequest, $wgOut;
00265
00266 $up = new UsersPager($par);
00267
00268 # getBody() first to check, if empty
00269 $usersbody = $up->getBody();
00270 $s = XML::openElement( 'div', array('class' => 'mw-spcontent') );
00271 $s .= $up->getPageHeader();
00272 if( $usersbody ) {
00273 $s .= $up->getNavigationBar();
00274 $s .= '<ul>' . $usersbody . '</ul>';
00275 $s .= $up->getNavigationBar() ;
00276 } else {
00277 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
00278 };
00279 $s .= XML::closeElement( 'div' );
00280 $wgOut->addHTML( $s );
00281 }