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 global $wgUser;
00075 $dbr = wfGetDB( DB_SLAVE );
00076 $conds = array();
00077
00078 if( !$wgUser->isAllowed('hideuser') )
00079 $conds[] = 'ipb_deleted IS NULL';
00080 if( $this->requestedGroup != '' ) {
00081 $conds['ug_group'] = $this->requestedGroup;
00082 $useIndex = '';
00083 } else {
00084 $useIndex = $dbr->useIndexClause( $this->creationSort ? 'PRIMARY' : 'user_name');
00085 }
00086 if( $this->requestedUser != '' ) {
00087 # Sorted either by account creation or name
00088 if( $this->creationSort ) {
00089 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) );
00090 } else {
00091 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
00092 }
00093 }
00094 if( $this->editsOnly ) {
00095 $conds[] = 'user_editcount > 0';
00096 }
00097
00098 list ($user,$user_groups,$ipblocks) = $dbr->tableNamesN('user','user_groups','ipblocks');
00099
00100 $query = array(
00101 'tables' => " $user $useIndex LEFT JOIN $user_groups ON user_id=ug_user
00102 LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_deleted=1 AND ipb_auto=0 ",
00103 'fields' => array(
00104 $this->creationSort ? 'MAX(user_name) AS user_name' : 'user_name',
00105 $this->creationSort ? 'user_id' : 'MAX(user_id) AS user_id',
00106 'MAX(user_editcount) AS edits',
00107 'COUNT(ug_group) AS numgroups',
00108 'MAX(ug_group) AS singlegroup',
00109 'MIN(user_registration) AS creation',
00110 'MAX(ipb_deleted) AS ipb_deleted'
00111 ),
00112 'options' => array('GROUP BY' => $this->creationSort ? 'user_id' : 'user_name'),
00113 'conds' => $conds
00114 );
00115
00116 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
00117 return $query;
00118 }
00119
00120 function formatRow( $row ) {
00121 global $wgLang;
00122
00123 $userPage = Title::makeTitle( NS_USER, $row->user_name );
00124 $name = $this->getSkin()->link( $userPage, htmlspecialchars( $userPage->getText() ) );
00125
00126 if( $row->numgroups > 1 || ( $this->requestedGroup && $row->numgroups == 1 ) ) {
00127 $list = array();
00128 foreach( self::getGroups( $row->user_id ) as $group )
00129 $list[] = self::buildGroupLink( $group );
00130 $groups = $wgLang->commaList( $list );
00131 } elseif( $row->numgroups == 1 ) {
00132 $groups = self::buildGroupLink( $row->singlegroup );
00133 } else {
00134 $groups = '';
00135 }
00136
00137 $item = wfSpecialList( $name, $groups );
00138 if( $row->ipb_deleted ) {
00139 $item = "<span class=\"deleted\">$item</span>";
00140 }
00141
00142 global $wgEdititis;
00143 if ( $wgEdititis ) {
00144 $editCount = $wgLang->formatNum( $row->edits );
00145 $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']';
00146 } else {
00147 $edits = '';
00148 }
00149
00150 $created = '';
00151 # Some rows may be NULL
00152 if( $row->creation ) {
00153 $d = $wgLang->date( wfTimestamp( TS_MW, $row->creation ), true );
00154 $t = $wgLang->time( wfTimestamp( TS_MW, $row->creation ), true );
00155 $created = ' (' . wfMsg( 'usercreated', $d, $t ) . ')';
00156 $created = htmlspecialchars( $created );
00157 }
00158
00159 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
00160 return "<li>{$item}{$edits}{$created}</li>";
00161 }
00162
00163 function getBody() {
00164 if( !$this->mQueryDone ) {
00165 $this->doQuery();
00166 }
00167 $this->mResult->rewind();
00168 $batch = new LinkBatch;
00169 while ( $row = $this->mResult->fetchObject() ) {
00170 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
00171 }
00172 $batch->execute();
00173 $this->mResult->rewind();
00174 return parent::getBody();
00175 }
00176
00177 function getPageHeader( ) {
00178 global $wgScript, $wgRequest;
00179 $self = $this->getTitle();
00180
00181 # Form tag
00182 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
00183 Xml::fieldset( wfMsg( 'listusers' ) ) .
00184 Xml::hidden( 'title', $self->getPrefixedDbKey() );
00185
00186 # Username field
00187 $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
00188 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
00189
00190 # Group drop-down list
00191 $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
00192 Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
00193 Xml::option( wfMsg( 'group-all' ), '' );
00194 foreach( $this->getAllGroups() as $group => $groupText )
00195 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
00196 $out .= Xml::closeElement( 'select' ) . '<br />';
00197 $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly );
00198 $out .= ' ';
00199 $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort );
00200 $out .= '<br />';
00201
00202 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
00203
00204 # Submit button and form bottom
00205 $out .= Xml::hidden( 'limit', $this->mLimit );
00206 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
00207 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
00208 $out .= Xml::closeElement( 'fieldset' ) .
00209 Xml::closeElement( 'form' );
00210
00211 return $out;
00212 }
00213
00218 function getAllGroups() {
00219 $result = array();
00220 foreach( User::getAllGroups() as $group ) {
00221 $result[$group] = User::getGroupName( $group );
00222 }
00223 asort( $result );
00224 return $result;
00225 }
00226
00231 function getDefaultQuery() {
00232 $query = parent::getDefaultQuery();
00233 if( $this->requestedGroup != '' )
00234 $query['group'] = $this->requestedGroup;
00235 if( $this->requestedUser != '' )
00236 $query['username'] = $this->requestedUser;
00237 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
00238 return $query;
00239 }
00240
00247 protected static function getGroups( $uid ) {
00248 $user = User::newFromId( $uid );
00249 $groups = array_diff( $user->getEffectiveGroups(), $user->getImplicitGroups() );
00250 return $groups;
00251 }
00252
00259 protected static function buildGroupLink( $group ) {
00260 static $cache = array();
00261 if( !isset( $cache[$group] ) )
00262 $cache[$group] = User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group ) ) );
00263 return $cache[$group];
00264 }
00265 }
00266
00271 function wfSpecialListusers( $par = null ) {
00272 global $wgRequest, $wgOut;
00273
00274 $up = new UsersPager($par);
00275
00276 # getBody() first to check, if empty
00277 $usersbody = $up->getBody();
00278 $s = XML::openElement( 'div', array('class' => 'mw-spcontent') );
00279 $s .= $up->getPageHeader();
00280 if( $usersbody ) {
00281 $s .= $up->getNavigationBar();
00282 $s .= '<ul>' . $usersbody . '</ul>';
00283 $s .= $up->getNavigationBar() ;
00284 } else {
00285 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
00286 };
00287 $s .= XML::closeElement( 'div' );
00288 $wgOut->addHTML( $s );
00289 }