MediaWiki  REL1_22
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 = $this->getDatabase();
00095 
00096         $conds = array( 'rc_user > 0' ); // Users - no anons
00097         $conds[] = 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' );
00098         $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes(
00099             $dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge * 24 * 3600 ) );
00100 
00101         if ( $this->requestedUser != '' ) {
00102             $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
00103         }
00104 
00105         if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
00106             $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
00107                 'ipblocks', '1', array( 'rc_user=ipb_user', 'ipb_deleted' => 1 )
00108             ) . ')';
00109         }
00110 
00111         return array(
00112             'tables' => array( 'recentchanges' ),
00113             'fields' => array(
00114                 'user_name' => 'rc_user_text', // for Pager inheritance
00115                 'rc_user_text', // for Pager
00116                 'user_id' => 'MAX(rc_user)', // Postgres
00117                 'recentedits' => 'COUNT(*)'
00118             ),
00119             'options' => array(
00120                 'GROUP BY' => array( 'rc_user_text' ),
00121                 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
00122             ),
00123             'conds' => $conds
00124         );
00125     }
00126 
00127     function doBatchLookups() {
00128         $uids = array();
00129         foreach ( $this->mResult as $row ) {
00130             $uids[] = $row->user_id;
00131         }
00132         // Fetch the block status of the user for showing "(blocked)" text and for
00133         // striking out names of suppressed users when privileged user views the list.
00134         // Although the first query already hits the block table for un-privileged, this
00135         // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
00136         $dbr = $this->getDatabase();
00137         $res = $dbr->select( 'ipblocks',
00138             array( 'ipb_user', 'MAX(ipb_deleted) AS block_status' ),
00139             array( 'ipb_user' => $uids ),
00140             __METHOD__,
00141             array( 'GROUP BY' => array( 'ipb_user' ) )
00142         );
00143         $this->blockStatusByUid = array();
00144         foreach ( $res as $row ) {
00145             $this->blockStatusByUid[$row->ipb_user] = $row->block_status; // 0 or 1
00146         }
00147         $this->mResult->seek( 0 );
00148     }
00149 
00150     function formatRow( $row ) {
00151         $userName = $row->user_name;
00152 
00153         $ulinks = Linker::userLink( $row->user_id, $userName );
00154         $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
00155 
00156         $lang = $this->getLanguage();
00157 
00158         $list = array();
00159         $user = User::newFromId( $row->user_id );
00160 
00161         // User right filter
00162         foreach ( $this->hideRights as $right ) {
00163             // Calling User::getRights() within the loop so that
00164             // if the hideRights() filter is empty, we don't have to
00165             // trigger the lazy-init of the big userrights array in the
00166             // User object
00167             if ( in_array( $right, $user->getRights() ) ) {
00168                 return '';
00169             }
00170         }
00171 
00172         // User group filter
00173         // Note: This is a different loop than for user rights,
00174         // because we're reusing it to build the group links
00175         // at the same time
00176         foreach ( $user->getGroups() as $group ) {
00177             if ( in_array( $group, $this->hideGroups ) ) {
00178                 return '';
00179             }
00180             $list[] = self::buildGroupLink( $group, $userName );
00181         }
00182 
00183         $groups = $lang->commaList( $list );
00184 
00185         $item = $lang->specialList( $ulinks, $groups );
00186 
00187         $isBlocked = isset( $this->blockStatusByUid[$row->user_id] );
00188         if ( $isBlocked && $this->blockStatusByUid[$row->user_id] == 1 ) {
00189             $item = "<span class=\"deleted\">$item</span>";
00190         }
00191         $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
00192             ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
00193         $blocked = $isBlocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
00194 
00195         return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
00196     }
00197 
00198     function getPageHeader() {
00199         global $wgScript;
00200 
00201         $self = $this->getTitle();
00202         $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
00203 
00204         $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
00205         $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
00206         $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
00207 
00208         $out .= Xml::inputLabel( $this->msg( 'activeusers-from' )->text(),
00209             'username', 'offset', 20, $this->requestedUser, array( 'tabindex' => 1 ) ) . '<br />';# Username field
00210 
00211         $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
00212             'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ), array( 'tabindex' => 2 ) );
00213 
00214         $out .= Xml::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(),
00215             'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ), array( 'tabindex' => 3 ) ) . '<br />';
00216 
00217         $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text(), array( 'tabindex' => 4 ) ) . "\n";# Submit button and form bottom
00218         $out .= Xml::closeElement( 'fieldset' );
00219         $out .= Xml::closeElement( 'form' );
00220 
00221         return $out;
00222     }
00223 }
00224 
00228 class SpecialActiveUsers extends SpecialPage {
00229 
00233     public function __construct() {
00234         parent::__construct( 'Activeusers' );
00235     }
00236 
00242     public function execute( $par ) {
00243         global $wgActiveUserDays;
00244 
00245         $this->setHeaders();
00246         $this->outputHeader();
00247 
00248         $out = $this->getOutput();
00249         $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
00250             array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) );
00251 
00252         $up = new ActiveUsersPager( $this->getContext(), null, $par );
00253 
00254         # getBody() first to check, if empty
00255         $usersbody = $up->getBody();
00256 
00257         $out->addHTML( $up->getPageHeader() );
00258         if ( $usersbody ) {
00259             $out->addHTML(
00260                 $up->getNavigationBar() .
00261                 Html::rawElement( 'ul', array(), $usersbody ) .
00262                 $up->getNavigationBar()
00263             );
00264         } else {
00265             $out->addWikiMsg( 'activeusers-noresult' );
00266         }
00267     }
00268 
00269     protected function getGroupName() {
00270         return 'users';
00271     }
00272 }