MediaWiki
REL1_21
|
00001 <?php 00035 class UsersPager extends AlphabeticPager { 00036 00043 function __construct( IContextSource $context = null, $par = null, $including = null ) { 00044 if ( $context ) { 00045 $this->setContext( $context ); 00046 } 00047 00048 $request = $this->getRequest(); 00049 $par = ( $par !== null ) ? $par : ''; 00050 $parms = explode( '/', $par ); 00051 $symsForAll = array( '*', 'user' ); 00052 if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) { 00053 $this->requestedGroup = $par; 00054 $un = $request->getText( 'username' ); 00055 } elseif ( count( $parms ) == 2 ) { 00056 $this->requestedGroup = $parms[0]; 00057 $un = $parms[1]; 00058 } else { 00059 $this->requestedGroup = $request->getVal( 'group' ); 00060 $un = ( $par != '' ) ? $par : $request->getText( 'username' ); 00061 } 00062 if ( in_array( $this->requestedGroup, $symsForAll ) ) { 00063 $this->requestedGroup = ''; 00064 } 00065 $this->editsOnly = $request->getBool( 'editsOnly' ); 00066 $this->creationSort = $request->getBool( 'creationSort' ); 00067 $this->including = $including; 00068 00069 $this->requestedUser = ''; 00070 if ( $un != '' ) { 00071 $username = Title::makeTitleSafe( NS_USER, $un ); 00072 if( ! is_null( $username ) ) { 00073 $this->requestedUser = $username->getText(); 00074 } 00075 } 00076 parent::__construct(); 00077 } 00078 00082 function getIndexField() { 00083 return $this->creationSort ? 'user_id' : 'user_name'; 00084 } 00085 00089 function getQueryInfo() { 00090 $dbr = wfGetDB( DB_SLAVE ); 00091 $conds = array(); 00092 // Don't show hidden names 00093 if( !$this->getUser()->isAllowed( 'hideuser' ) ) { 00094 $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0'; 00095 } 00096 00097 $options = array(); 00098 00099 if( $this->requestedGroup != '' ) { 00100 $conds['ug_group'] = $this->requestedGroup; 00101 } else { 00102 //$options['USE INDEX'] = $this->creationSort ? 'PRIMARY' : 'user_name'; 00103 } 00104 if( $this->requestedUser != '' ) { 00105 # Sorted either by account creation or name 00106 if( $this->creationSort ) { 00107 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) ); 00108 } else { 00109 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser ); 00110 } 00111 } 00112 if( $this->editsOnly ) { 00113 $conds[] = 'user_editcount > 0'; 00114 } 00115 00116 $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name'; 00117 00118 $query = array( 00119 'tables' => array( 'user', 'user_groups', 'ipblocks' ), 00120 'fields' => array( 00121 'user_name' => $this->creationSort ? 'MAX(user_name)' : 'user_name', 00122 'user_id' => $this->creationSort ? 'user_id' : 'MAX(user_id)', 00123 'edits' => 'MAX(user_editcount)', 00124 'numgroups' => 'COUNT(ug_group)', 00125 'singlegroup' => 'MAX(ug_group)', // the usergroup if there is only one 00126 'creation' => 'MIN(user_registration)', 00127 'ipb_deleted' => 'MAX(ipb_deleted)' // block/hide status 00128 ), 00129 'options' => $options, 00130 'join_conds' => array( 00131 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ), 00132 'ipblocks' => array( 'LEFT JOIN', array( 00133 'user_id=ipb_user', 00134 'ipb_auto' => 0 00135 )), 00136 ), 00137 'conds' => $conds 00138 ); 00139 00140 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) ); 00141 return $query; 00142 } 00143 00148 function formatRow( $row ) { 00149 if ( $row->user_id == 0 ) { #Bug 16487 00150 return ''; 00151 } 00152 00153 $userName = $row->user_name; 00154 00155 $ulinks = Linker::userLink( $row->user_id, $userName ); 00156 $ulinks .= Linker::userToolLinksRedContribs( $row->user_id, $userName, intval( $row->edits ) ); 00157 00158 $lang = $this->getLanguage(); 00159 00160 $groups = ''; 00161 $groups_list = self::getGroups( $row->user_id ); 00162 if( !$this->including && count( $groups_list ) > 0 ) { 00163 $list = array(); 00164 foreach( $groups_list as $group ) 00165 $list[] = self::buildGroupLink( $group, $userName ); 00166 $groups = $lang->commaList( $list ); 00167 } 00168 00169 $item = $lang->specialList( $ulinks, $groups ); 00170 if( $row->ipb_deleted ) { 00171 $item = "<span class=\"deleted\">$item</span>"; 00172 } 00173 00174 $edits = ''; 00175 global $wgEdititis; 00176 if ( !$this->including && $wgEdititis ) { 00177 $edits = ' [' . $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped() . ']'; 00178 } 00179 00180 $created = ''; 00181 # Some rows may be NULL 00182 if( !$this->including && $row->creation ) { 00183 $user = $this->getUser(); 00184 $d = $lang->userDate( $row->creation, $user ); 00185 $t = $lang->userTime( $row->creation, $user ); 00186 $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped(); 00187 $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped(); 00188 } 00189 $blocked = !is_null( $row->ipb_deleted ) ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : ''; 00190 00191 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) ); 00192 return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}{$blocked}" ); 00193 } 00194 00195 function doBatchLookups() { 00196 $batch = new LinkBatch(); 00197 # Give some pointers to make user links 00198 foreach ( $this->mResult as $row ) { 00199 $batch->add( NS_USER, $row->user_name ); 00200 $batch->add( NS_USER_TALK, $row->user_name ); 00201 } 00202 $batch->execute(); 00203 $this->mResult->rewind(); 00204 } 00205 00209 function getPageHeader() { 00210 global $wgScript; 00211 00212 list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() ); 00213 00214 # Form tag 00215 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) . 00216 Xml::fieldset( $this->msg( 'listusers' )->text() ) . 00217 Html::hidden( 'title', $self ); 00218 00219 # Username field 00220 $out .= Xml::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' . 00221 Html::input( 00222 'username', 00223 $this->requestedUser, 00224 'text', 00225 array( 00226 'id' => 'offset', 00227 'size' => 20, 00228 'autofocus' => $this->requestedUser === '' 00229 ) 00230 ) . ' '; 00231 00232 # Group drop-down list 00233 $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' ' . 00234 Xml::openElement( 'select', array( 'name' => 'group', 'id' => 'group' ) ) . 00235 Xml::option( $this->msg( 'group-all' )->text(), '' ); 00236 foreach( $this->getAllGroups() as $group => $groupText ) 00237 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup ); 00238 $out .= Xml::closeElement( 'select' ) . '<br />'; 00239 $out .= Xml::checkLabel( $this->msg( 'listusers-editsonly' )->text(), 'editsOnly', 'editsOnly', $this->editsOnly ); 00240 $out .= ' '; 00241 $out .= Xml::checkLabel( $this->msg( 'listusers-creationsort' )->text(), 'creationSort', 'creationSort', $this->creationSort ); 00242 $out .= '<br />'; 00243 00244 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) ); 00245 00246 # Submit button and form bottom 00247 $out .= Html::hidden( 'limit', $this->mLimit ); 00248 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ); 00249 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) ); 00250 $out .= Xml::closeElement( 'fieldset' ) . 00251 Xml::closeElement( 'form' ); 00252 00253 return $out; 00254 } 00255 00260 function getAllGroups() { 00261 $result = array(); 00262 foreach( User::getAllGroups() as $group ) { 00263 $result[$group] = User::getGroupName( $group ); 00264 } 00265 asort( $result ); 00266 return $result; 00267 } 00268 00273 function getDefaultQuery() { 00274 $query = parent::getDefaultQuery(); 00275 if( $this->requestedGroup != '' ) { 00276 $query['group'] = $this->requestedGroup; 00277 } 00278 if( $this->requestedUser != '' ) { 00279 $query['username'] = $this->requestedUser; 00280 } 00281 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) ); 00282 return $query; 00283 } 00284 00291 protected static function getGroups( $uid ) { 00292 $user = User::newFromId( $uid ); 00293 $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() ); 00294 return $groups; 00295 } 00296 00304 protected static function buildGroupLink( $group, $username ) { 00305 return User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group, $username ) ) ); 00306 } 00307 } 00308 00312 class SpecialListUsers extends IncludableSpecialPage { 00313 00317 public function __construct() { 00318 parent::__construct( 'Listusers' ); 00319 } 00320 00326 public function execute( $par ) { 00327 $this->setHeaders(); 00328 $this->outputHeader(); 00329 00330 $up = new UsersPager( $this->getContext(), $par, $this->including() ); 00331 00332 # getBody() first to check, if empty 00333 $usersbody = $up->getBody(); 00334 00335 $s = ''; 00336 if ( !$this->including() ) { 00337 $s = $up->getPageHeader(); 00338 } 00339 00340 if( $usersbody ) { 00341 $s .= $up->getNavigationBar(); 00342 $s .= Html::rawElement( 'ul', array(), $usersbody ); 00343 $s .= $up->getNavigationBar(); 00344 } else { 00345 $s .= $this->msg( 'listusers-noresult' )->parseAsBlock(); 00346 } 00347 00348 $this->getOutput()->addHTML( $s ); 00349 } 00350 00351 protected function getGroupName() { 00352 return 'users'; 00353 } 00354 }