MediaWiki  REL1_21
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                 if( !$this->getUser()->isAllowed( 'hideuser' ) ) {
00097                         $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0'; // don't show hidden names
00098                 }
00099                 $conds[] = 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' );
00100                 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes(
00101                         $dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 ) );
00102 
00103                 if( $this->requestedUser != '' ) {
00104                         $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
00105                 }
00106 
00107                 return array(
00108                         'tables' => array( 'recentchanges', 'ipblocks' ),
00109                         'fields' => array(
00110                                 'user_name' => 'rc_user_text', // for Pager inheritance
00111                                 'rc_user_text', // for Pager
00112                                 'user_id' => 'rc_user',
00113                                 'recentedits' => 'COUNT(*)',
00114                                 'ipb_deleted' => 'MAX(ipb_deleted)'
00115                         ),
00116                         'options' => array(
00117                                 'GROUP BY' => array( 'rc_user_text', 'user_id' ),
00118                                 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
00119                         ),
00120                         'join_conds' => array( // check for suppression blocks
00121                                 'ipblocks' => array( 'LEFT JOIN', array(
00122                                         'rc_user=ipb_user',
00123                                         'ipb_auto' => 0 # avoid duplicate blocks
00124                                 )),
00125                         ),
00126                         'conds' => $conds
00127                 );
00128         }
00129 
00130         function formatRow( $row ) {
00131                 $userName = $row->user_name;
00132 
00133                 $ulinks = Linker::userLink( $row->user_id, $userName );
00134                 $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
00135 
00136                 $lang = $this->getLanguage();
00137 
00138                 $list = array();
00139                 $user = User::newFromId( $row->user_id );
00140 
00141                 // User right filter
00142                 foreach( $this->hideRights as $right ) {
00143                         // Calling User::getRights() within the loop so that
00144                         // if the hideRights() filter is empty, we don't have to
00145                         // trigger the lazy-init of the big userrights array in the
00146                         // User object
00147                         if ( in_array( $right, $user->getRights() ) ) {
00148                                 return '';
00149                         }
00150                 }
00151 
00152                 // User group filter
00153                 // Note: This is a different loop than for user rights,
00154                 // because we're reusing it to build the group links
00155                 // at the same time
00156                 foreach( $user->getGroups() as $group ) {
00157                         if ( in_array( $group, $this->hideGroups ) ) {
00158                                 return '';
00159                         }
00160                         $list[] = self::buildGroupLink( $group, $userName );
00161                 }
00162 
00163                 $groups = $lang->commaList( $list );
00164 
00165                 $item = $lang->specialList( $ulinks, $groups );
00166                 if( $row->ipb_deleted ) {
00167                         $item = "<span class=\"deleted\">$item</span>";
00168                 }
00169                 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
00170                         ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
00171                 $blocked = !is_null( $row->ipb_deleted ) ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
00172 
00173                 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
00174         }
00175 
00176         function getPageHeader() {
00177                 global $wgScript;
00178 
00179                 $self = $this->getTitle();
00180                 $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
00181 
00182                 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
00183                 $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
00184                 $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
00185 
00186                 $out .= Xml::inputLabel( $this->msg( 'activeusers-from' )->text(),
00187                         'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
00188 
00189                 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
00190                         'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
00191 
00192                 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(),
00193                         'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
00194 
00195                 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n";# Submit button and form bottom
00196                 $out .= Xml::closeElement( 'fieldset' );
00197                 $out .= Xml::closeElement( 'form' );
00198 
00199                 return $out;
00200         }
00201 }
00202 
00206 class SpecialActiveUsers extends SpecialPage {
00207 
00211         public function __construct() {
00212                 parent::__construct( 'Activeusers' );
00213         }
00214 
00220         public function execute( $par ) {
00221                 global $wgActiveUserDays;
00222 
00223                 $this->setHeaders();
00224                 $this->outputHeader();
00225 
00226                 $out = $this->getOutput();
00227                 $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
00228                         array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) );
00229 
00230                 $up = new ActiveUsersPager( $this->getContext(), null, $par );
00231 
00232                 # getBody() first to check, if empty
00233                 $usersbody = $up->getBody();
00234 
00235                 $out->addHTML( $up->getPageHeader() );
00236                 if ( $usersbody ) {
00237                         $out->addHTML(
00238                                 $up->getNavigationBar() .
00239                                 Html::rawElement( 'ul', array(), $usersbody ) .
00240                                 $up->getNavigationBar()
00241                         );
00242                 } else {
00243                         $out->addWikiMsg( 'activeusers-noresult' );
00244                 }
00245         }
00246 
00247         protected function getGroupName() {
00248                 return 'users';
00249         }
00250 }