MediaWiki
REL1_19
|
00001 <?php 00035 class UsersPager extends AlphabeticPager { 00036 00037 function __construct( IContextSource $context = null, $par = null ) { 00038 if ( $context ) { 00039 $this->setContext( $context ); 00040 } 00041 00042 $request = $this->getRequest(); 00043 $par = ( $par !== null ) ? $par : ''; 00044 $parms = explode( '/', $par ); 00045 $symsForAll = array( '*', 'user' ); 00046 if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) { 00047 $this->requestedGroup = $par; 00048 $un = $request->getText( 'username' ); 00049 } elseif ( count( $parms ) == 2 ) { 00050 $this->requestedGroup = $parms[0]; 00051 $un = $parms[1]; 00052 } else { 00053 $this->requestedGroup = $request->getVal( 'group' ); 00054 $un = ( $par != '' ) ? $par : $request->getText( 'username' ); 00055 } 00056 if ( in_array( $this->requestedGroup, $symsForAll ) ) { 00057 $this->requestedGroup = ''; 00058 } 00059 $this->editsOnly = $request->getBool( 'editsOnly' ); 00060 $this->creationSort = $request->getBool( 'creationSort' ); 00061 00062 $this->requestedUser = ''; 00063 if ( $un != '' ) { 00064 $username = Title::makeTitleSafe( NS_USER, $un ); 00065 if( ! is_null( $username ) ) { 00066 $this->requestedUser = $username->getText(); 00067 } 00068 } 00069 parent::__construct(); 00070 } 00071 00072 function getIndexField() { 00073 return $this->creationSort ? 'user_id' : 'user_name'; 00074 } 00075 00076 function getQueryInfo() { 00077 $dbr = wfGetDB( DB_SLAVE ); 00078 $conds = array(); 00079 // Don't show hidden names 00080 if( !$this->getUser()->isAllowed('hideuser') ) { 00081 $conds[] = 'ipb_deleted IS NULL'; 00082 } 00083 00084 $options = array(); 00085 00086 if( $this->requestedGroup != '' ) { 00087 $conds['ug_group'] = $this->requestedGroup; 00088 } else { 00089 //$options['USE INDEX'] = $this->creationSort ? 'PRIMARY' : 'user_name'; 00090 } 00091 if( $this->requestedUser != '' ) { 00092 # Sorted either by account creation or name 00093 if( $this->creationSort ) { 00094 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) ); 00095 } else { 00096 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser ); 00097 } 00098 } 00099 if( $this->editsOnly ) { 00100 $conds[] = 'user_editcount > 0'; 00101 } 00102 00103 $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name'; 00104 00105 $query = array( 00106 'tables' => array( 'user', 'user_groups', 'ipblocks'), 00107 'fields' => array( 00108 $this->creationSort ? 'MAX(user_name) AS user_name' : 'user_name', 00109 $this->creationSort ? 'user_id' : 'MAX(user_id) AS user_id', 00110 'MAX(user_editcount) AS edits', 00111 'COUNT(ug_group) AS numgroups', 00112 'MAX(ug_group) AS singlegroup', // the usergroup if there is only one 00113 'MIN(user_registration) AS creation', 00114 'MAX(ipb_deleted) AS ipb_deleted' // block/hide status 00115 ), 00116 'options' => $options, 00117 'join_conds' => array( 00118 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ), 00119 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_deleted=1 AND ipb_auto=0' ), 00120 ), 00121 'conds' => $conds 00122 ); 00123 00124 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) ); 00125 return $query; 00126 } 00127 00128 function formatRow( $row ) { 00129 if ($row->user_id == 0) #Bug 16487 00130 return ''; 00131 00132 $userPage = Title::makeTitle( NS_USER, $row->user_name ); 00133 $name = Linker::link( $userPage, htmlspecialchars( $userPage->getText() ) ); 00134 00135 $lang = $this->getLanguage(); 00136 00137 $groups_list = self::getGroups( $row->user_id ); 00138 if( count( $groups_list ) > 0 ) { 00139 $list = array(); 00140 foreach( $groups_list as $group ) 00141 $list[] = self::buildGroupLink( $group, $userPage->getText() ); 00142 $groups = $lang->commaList( $list ); 00143 } else { 00144 $groups = ''; 00145 } 00146 00147 $item = $lang->specialList( $name, $groups ); 00148 if( $row->ipb_deleted ) { 00149 $item = "<span class=\"deleted\">$item</span>"; 00150 } 00151 00152 global $wgEdititis; 00153 if ( $wgEdititis ) { 00154 $editCount = $lang->formatNum( $row->edits ); 00155 $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']'; 00156 } else { 00157 $edits = ''; 00158 } 00159 00160 $created = ''; 00161 # Some rows may be NULL 00162 if( $row->creation ) { 00163 $d = $lang->date( wfTimestamp( TS_MW, $row->creation ), true ); 00164 $t = $lang->time( wfTimestamp( TS_MW, $row->creation ), true ); 00165 $created = ' (' . wfMsgExt( 'usercreated', array( 'parsemag', 'escape' ), $d, $t, $row->user_name ) . ')'; 00166 } 00167 00168 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) ); 00169 return "<li>{$item}{$edits}{$created}</li>"; 00170 } 00171 00172 function getBody() { 00173 if( !$this->mQueryDone ) { 00174 $this->doQuery(); 00175 } 00176 $this->mResult->rewind(); 00177 $batch = new LinkBatch; 00178 foreach ( $this->mResult as $row ) { 00179 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) ); 00180 } 00181 $batch->execute(); 00182 $this->mResult->rewind(); 00183 return parent::getBody(); 00184 } 00185 00186 function getPageHeader( ) { 00187 global $wgScript; 00188 // @todo Add a PrefixedBaseDBKey 00189 list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() ); 00190 00191 # Form tag 00192 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) . 00193 Xml::fieldset( wfMsg( 'listusers' ) ) . 00194 Html::hidden( 'title', $self ); 00195 00196 # Username field 00197 $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' . 00198 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' '; 00199 00200 # Group drop-down list 00201 $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' . 00202 Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) . 00203 Xml::option( wfMsg( 'group-all' ), '' ); 00204 foreach( $this->getAllGroups() as $group => $groupText ) 00205 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup ); 00206 $out .= Xml::closeElement( 'select' ) . '<br />'; 00207 $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly ); 00208 $out .= ' '; 00209 $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort ); 00210 $out .= '<br />'; 00211 00212 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) ); 00213 00214 # Submit button and form bottom 00215 $out .= Html::hidden( 'limit', $this->mLimit ); 00216 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ); 00217 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) ); 00218 $out .= Xml::closeElement( 'fieldset' ) . 00219 Xml::closeElement( 'form' ); 00220 00221 return $out; 00222 } 00223 00228 function getAllGroups() { 00229 $result = array(); 00230 foreach( User::getAllGroups() as $group ) { 00231 $result[$group] = User::getGroupName( $group ); 00232 } 00233 asort( $result ); 00234 return $result; 00235 } 00236 00241 function getDefaultQuery() { 00242 $query = parent::getDefaultQuery(); 00243 if( $this->requestedGroup != '' ) 00244 $query['group'] = $this->requestedGroup; 00245 if( $this->requestedUser != '' ) 00246 $query['username'] = $this->requestedUser; 00247 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) ); 00248 return $query; 00249 } 00250 00257 protected static function getGroups( $uid ) { 00258 $user = User::newFromId( $uid ); 00259 $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() ); 00260 return $groups; 00261 } 00262 00270 protected static function buildGroupLink( $group, $username ) { 00271 return User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group, $username ) ) ); 00272 } 00273 } 00274 00278 class SpecialListUsers extends SpecialPage { 00279 00283 public function __construct() { 00284 parent::__construct( 'Listusers' ); 00285 } 00286 00292 public function execute( $par ) { 00293 $this->setHeaders(); 00294 $this->outputHeader(); 00295 00296 $up = new UsersPager( $this->getContext(), $par ); 00297 00298 # getBody() first to check, if empty 00299 $usersbody = $up->getBody(); 00300 00301 $s = $up->getPageHeader(); 00302 if( $usersbody ) { 00303 $s .= $up->getNavigationBar(); 00304 $s .= Html::rawElement( 'ul', array(), $usersbody ); 00305 $s .= $up->getNavigationBar(); 00306 } else { 00307 $s .= wfMessage( 'listusers-noresult' )->parseAsBlock(); 00308 } 00309 00310 $this->getOutput()->addHTML( $s ); 00311 } 00312 }