MediaWiki  REL1_20
SpecialActiveusers.php
Go to the documentation of this file.
00001 <?php
00033 class ActiveUsersPager extends UsersPager {
00034 
00038         protected $opts;
00039 
00043         protected $hideGroups = array();
00044 
00048         protected $hideRights = array();
00049 
00055         function __construct( IContextSource $context = null, $group = null, $par = null ) {
00056                 global $wgActiveUserDays;
00057 
00058                 parent::__construct( $context );
00059 
00060                 $this->RCMaxAge = $wgActiveUserDays;
00061                 $un = $this->getRequest()->getText( 'username', $par );
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 
00070                 $this->setupOptions();
00071         }
00072 
00073         public function setupOptions() {
00074                 $this->opts = new FormOptions();
00075 
00076                 $this->opts->add( 'hidebots', false, FormOptions::BOOL );
00077                 $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
00078 
00079                 $this->opts->fetchValuesFromRequest( $this->getRequest() );
00080 
00081                 if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
00082                         $this->hideRights[] = 'bot';
00083                 }
00084                 if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
00085                         $this->hideGroups[] = 'sysop';
00086                 }
00087         }
00088 
00089         function getIndexField() {
00090                 return 'rc_user_text';
00091         }
00092 
00093         function getQueryInfo() {
00094                 $dbr = wfGetDB( DB_SLAVE );
00095                 $conds = array( 'rc_user > 0' ); // Users - no anons
00096                 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
00097                 $conds[] = 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' );
00098                 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 ) );
00099 
00100                 if( $this->requestedUser != '' ) {
00101                         $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
00102                 }
00103 
00104                 $query = array(
00105                         'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
00106                         'fields' => array( 'user_name' => 'rc_user_text', // inheritance
00107                                 'rc_user_text', // for Pager
00108                                 'user_id',
00109                                 'recentedits' => 'COUNT(*)',
00110                                 'blocked' => 'MAX(ipb_user)'
00111                         ),
00112                         'options' => array(
00113                                 'GROUP BY' => array( 'rc_user_text', 'user_id' ),
00114                                 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
00115                         ),
00116                         'join_conds' => array(
00117                                 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
00118                                 'ipblocks' => array( 'LEFT JOIN', array(
00119                                         'user_id=ipb_user',
00120                                         'ipb_auto' => 0,
00121                                         'ipb_deleted' => 1
00122                                 )),
00123                         ),
00124                         'conds' => $conds
00125                 );
00126                 return $query;
00127         }
00128 
00129         function formatRow( $row ) {
00130                 $userName = $row->user_name;
00131 
00132                 $ulinks = Linker::userLink( $row->user_id, $userName );
00133                 $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
00134 
00135                 $lang = $this->getLanguage();
00136 
00137                 $list = array();
00138                 $user = User::newFromId( $row->user_id );
00139 
00140                 // User right filter
00141                 foreach( $this->hideRights as $right ) {
00142                         // Calling User::getRights() within the loop so that
00143                         // if the hideRights() filter is empty, we don't have to
00144                         // trigger the lazy-init of the big userrights array in the
00145                         // User object
00146                         if ( in_array( $right, $user->getRights() ) ) {
00147                                 return '';
00148                         }
00149                 }
00150 
00151                 // User group filter
00152                 // Note: This is a different loop than for user rights,
00153                 // because we're reusing it to build the group links
00154                 // at the same time
00155                 foreach( $user->getGroups() as $group ) {
00156                         if ( in_array( $group, $this->hideGroups ) ) {
00157                                 return '';
00158                         }
00159                         $list[] = self::buildGroupLink( $group, $userName );
00160                 }
00161 
00162                 $groups = $lang->commaList( $list );
00163 
00164                 $item = $lang->specialList( $ulinks, $groups );
00165                 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
00166                         ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
00167                 $blocked = $row->blocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
00168 
00169                 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
00170         }
00171 
00172         function getPageHeader() {
00173                 global $wgScript;
00174 
00175                 $self = $this->getTitle();
00176                 $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
00177 
00178                 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
00179                 $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
00180                 $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
00181 
00182                 $out .= Xml::inputLabel( $this->msg( 'activeusers-from' )->text(),
00183                         'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
00184 
00185                 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
00186                         'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
00187 
00188                 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(),
00189                         'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
00190 
00191                 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n";# Submit button and form bottom
00192                 $out .= Xml::closeElement( 'fieldset' );
00193                 $out .= Xml::closeElement( 'form' );
00194 
00195                 return $out;
00196         }
00197 }
00198 
00202 class SpecialActiveUsers extends SpecialPage {
00203 
00207         public function __construct() {
00208                 parent::__construct( 'Activeusers' );
00209         }
00210 
00216         public function execute( $par ) {
00217                 global $wgActiveUserDays;
00218 
00219                 $this->setHeaders();
00220                 $this->outputHeader();
00221 
00222                 $out = $this->getOutput();
00223                 $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
00224                         array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) );
00225 
00226                 $up = new ActiveUsersPager( $this->getContext(), null, $par );
00227 
00228                 # getBody() first to check, if empty
00229                 $usersbody = $up->getBody();
00230 
00231                 $out->addHTML( $up->getPageHeader() );
00232                 if ( $usersbody ) {
00233                         $out->addHTML(
00234                                 $up->getNavigationBar() .
00235                                 Html::rawElement( 'ul', array(), $usersbody ) .
00236                                 $up->getNavigationBar()
00237                         );
00238                 } else {
00239                         $out->addWikiMsg( 'activeusers-noresult' );
00240                 }
00241         }
00242 
00243 }