MediaWiki
REL1_19
|
00001 <?php 00033 class ActiveUsersPager extends UsersPager { 00034 00038 protected $opts; 00039 00043 protected $groups; 00044 00050 function __construct( IContextSource $context = null, $group = null, $par = null ) { 00051 global $wgActiveUserDays; 00052 00053 parent::__construct( $context ); 00054 00055 $this->RCMaxAge = $wgActiveUserDays; 00056 $un = $this->getRequest()->getText( 'username', $par ); 00057 $this->requestedUser = ''; 00058 if ( $un != '' ) { 00059 $username = Title::makeTitleSafe( NS_USER, $un ); 00060 if( !is_null( $username ) ) { 00061 $this->requestedUser = $username->getText(); 00062 } 00063 } 00064 00065 $this->setupOptions(); 00066 } 00067 00068 public function setupOptions() { 00069 $this->opts = new FormOptions(); 00070 00071 $this->opts->add( 'hidebots', false, FormOptions::BOOL ); 00072 $this->opts->add( 'hidesysops', false, FormOptions::BOOL ); 00073 00074 $this->opts->fetchValuesFromRequest( $this->getRequest() ); 00075 00076 $this->groups = array(); 00077 if ( $this->opts->getValue( 'hidebots' ) == 1 ) { 00078 $this->groups['bot'] = true; 00079 } 00080 if ( $this->opts->getValue( 'hidesysops' ) == 1 ) { 00081 $this->groups['sysop'] = true; 00082 } 00083 } 00084 00085 function getIndexField() { 00086 return 'rc_user_text'; 00087 } 00088 00089 function getQueryInfo() { 00090 $dbr = wfGetDB( DB_SLAVE ); 00091 $conds = array( 'rc_user > 0' ); // Users - no anons 00092 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names 00093 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'"; 00094 $conds[] = "rc_timestamp >= '{$dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 )}'"; 00095 00096 if( $this->requestedUser != '' ) { 00097 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser ); 00098 } 00099 00100 $query = array( 00101 'tables' => array( 'recentchanges', 'user', 'ipblocks' ), 00102 'fields' => array( 'rc_user_text AS user_name', // inheritance 00103 'rc_user_text', // for Pager 00104 'user_id', 00105 'COUNT(*) AS recentedits', 00106 'MAX(ipb_user) AS blocked' 00107 ), 00108 'options' => array( 00109 'GROUP BY' => 'rc_user_text, user_id', 00110 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' ) 00111 ), 00112 'join_conds' => array( 00113 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ), 00114 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ), 00115 ), 00116 'conds' => $conds 00117 ); 00118 return $query; 00119 } 00120 00121 function formatRow( $row ) { 00122 $userName = $row->user_name; 00123 00124 $ulinks = Linker::userLink( $row->user_id, $userName ); 00125 $ulinks .= Linker::userToolLinks( $row->user_id, $userName ); 00126 00127 $lang = $this->getLanguage(); 00128 00129 $list = array(); 00130 foreach( self::getGroups( $row->user_id ) as $group ) { 00131 if ( isset( $this->groups[$group] ) ) { 00132 return; 00133 } 00134 $list[] = self::buildGroupLink( $group, $userName ); 00135 } 00136 $groups = $lang->commaList( $list ); 00137 00138 $item = $lang->specialList( $ulinks, $groups ); 00139 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits ) 00140 ->params( $userName )->numParams( $this->RCMaxAge )->escaped(); 00141 $blocked = $row->blocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : ''; 00142 00143 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" ); 00144 } 00145 00146 function getPageHeader() { 00147 global $wgScript; 00148 00149 $self = $this->getTitle(); 00150 $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : ''; 00151 00152 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag 00153 $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n"; 00154 $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n"; 00155 00156 $out .= Xml::inputLabel( $this->msg( 'activeusers-from' )->text(), 00157 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field 00158 00159 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(), 00160 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) ); 00161 00162 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(), 00163 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />'; 00164 00165 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n";# Submit button and form bottom 00166 $out .= Xml::closeElement( 'fieldset' ); 00167 $out .= Xml::closeElement( 'form' ); 00168 00169 return $out; 00170 } 00171 } 00172 00176 class SpecialActiveUsers extends SpecialPage { 00177 00181 public function __construct() { 00182 parent::__construct( 'Activeusers' ); 00183 } 00184 00190 public function execute( $par ) { 00191 global $wgActiveUserDays; 00192 00193 $this->setHeaders(); 00194 $this->outputHeader(); 00195 00196 $out = $this->getOutput(); 00197 $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>", 00198 array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) ); 00199 00200 $up = new ActiveUsersPager( $this->getContext(), null, $par ); 00201 00202 # getBody() first to check, if empty 00203 $usersbody = $up->getBody(); 00204 00205 $out->addHTML( $up->getPageHeader() ); 00206 if ( $usersbody ) { 00207 $out->addHTML( 00208 $up->getNavigationBar() . 00209 Html::rawElement( 'ul', array(), $usersbody ) . 00210 $up->getNavigationBar() 00211 ); 00212 } else { 00213 $out->addWikiMsg( 'activeusers-noresult' ); 00214 } 00215 } 00216 00217 }