00001 <?php
00002 # Copyright (C) 2008 Aaron Schulz
00003 #
00004 # http://www.mediawiki.org/
00005 #
00006 # This program is free software; you can redistribute it and/or modify
00007 # it under the terms of the GNU General Public License as published by
00008 # the Free Software Foundation; either version 2 of the License, or
00009 # (at your option) any later version.
00010 #
00011 # This program is distributed in the hope that it will be useful,
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014 # GNU General Public License for more details.
00015 #
00016 # You should have received a copy of the GNU General Public License along
00017 # with this program; if not, write to the Free Software Foundation, Inc.,
00018 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 # http://www.gnu.org/copyleft/gpl.html
00020
00029 class ActiveUsersPager extends UsersPager {
00030
00031 function __construct( $group = null ) {
00032 global $wgRequest, $wgRCMaxAge;
00033 $this->RCMaxAge = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
00034
00035 $un = $wgRequest->getText( 'username' );
00036 $this->requestedUser = '';
00037 if ( $un != '' ) {
00038 $username = Title::makeTitleSafe( NS_USER, $un );
00039 if( !is_null( $username ) ) {
00040 $this->requestedUser = $username->getText();
00041 }
00042 }
00043
00044 $this->setupOptions();
00045
00046 parent::__construct();
00047 }
00048
00049 public function setupOptions() {
00050 global $wgRequest;
00051
00052 $this->opts = new FormOptions();
00053
00054 $this->opts->add( 'hidebots', false, FormOptions::BOOL );
00055 $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
00056
00057 $this->opts->fetchValuesFromRequest( $wgRequest );
00058
00059 $this->groups = array();
00060 if ($this->opts->getValue('hidebots') == 1)
00061 $this->groups['bot'] = true;
00062 if ($this->opts->getValue('hidesysops') == 1)
00063 $this->groups['sysop'] = true;
00064 }
00065
00066 function getIndexField() {
00067 return 'rc_user_text';
00068 }
00069
00070 function getQueryInfo() {
00071 $dbr = wfGetDB( DB_SLAVE );
00072 $conds = array( 'rc_user > 0' );
00073 $conds[] = 'ipb_deleted IS NULL';
00074 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
00075
00076 if( $this->requestedUser != '' ) {
00077 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
00078 }
00079
00080 $query = array(
00081 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
00082 'fields' => array( 'rc_user_text AS user_name',
00083 'rc_user_text',
00084 'user_id',
00085 'COUNT(*) AS recentedits',
00086 'MAX(ipb_user) AS blocked'
00087 ),
00088 'options' => array(
00089 'GROUP BY' => 'rc_user_text, user_id',
00090 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
00091 ),
00092 'join_conds' => array(
00093 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
00094 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
00095 ),
00096 'conds' => $conds
00097 );
00098 return $query;
00099 }
00100
00101 function formatRow( $row ) {
00102 global $wgLang;
00103 $userName = $row->user_name;
00104
00105 $ulinks = $this->getSkin()->userLink( $row->user_id, $userName );
00106 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id, $userName );
00107
00108 $list = array();
00109 foreach( self::getGroups( $row->user_id ) as $group ) {
00110 if (isset($this->groups[$group]))
00111 return;
00112 $list[] = self::buildGroupLink( $group );
00113 }
00114 $groups = $wgLang->commaList( $list );
00115
00116 $item = wfSpecialList( $ulinks, $groups );
00117 $count = wfMsgExt( 'activeusers-count',
00118 array( 'parsemag' ),
00119 $wgLang->formatNum( $row->recentedits ),
00120 $userName,
00121 $wgLang->formatNum ( $this->RCMaxAge )
00122 );
00123 $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
00124
00125 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
00126 }
00127
00128 function getPageHeader() {
00129 global $wgScript, $wgRequest;
00130
00131 $self = $this->getTitle();
00132 $limit = $this->mLimit ? Xml::hidden( 'limit', $this->mLimit ) : '';
00133
00134 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
00135 $out .= Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n";
00136 $out .= Xml::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
00137
00138 $out .= Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
00139
00140 $out .= Xml::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
00141
00142 $out .= Xml::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
00143
00144 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
00145 $out .= Xml::closeElement( 'fieldset' );
00146 $out .= Xml::closeElement( 'form' );
00147
00148 return $out;
00149 }
00150 }
00151
00155 class SpecialActiveUsers extends SpecialPage {
00156
00160 public function __construct() {
00161 parent::__construct( 'Activeusers' );
00162 }
00163
00169 public function execute( $par ) {
00170 global $wgOut, $wgLang, $wgRCMaxAge;
00171
00172 $this->setHeaders();
00173
00174 $up = new ActiveUsersPager();
00175
00176 # getBody() first to check, if empty
00177 $usersbody = $up->getBody();
00178
00179 $s = Html::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
00180 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( ceil( $wgRCMaxAge / 86400 ) ) )
00181 );
00182
00183 $s .= $up->getPageHeader();
00184 if( $usersbody ) {
00185 $s .= $up->getNavigationBar();
00186 $s .= Html::rawElement( 'ul', array(), $usersbody );
00187 $s .= $up->getNavigationBar();
00188 } else {
00189 $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
00190 }
00191
00192 $wgOut->addHTML( $s );
00193 }
00194
00195 }