]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/specials/SpecialActiveusers.php
MediaWiki 1.16.0
[autoinstalls/mediawiki.git] / includes / specials / SpecialActiveusers.php
1 <?php
2 # Copyright (C) 2008 Aaron Schulz
3 #
4 # http://www.mediawiki.org/
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
20
21 /**
22  * This class is used to get a list of active users. The ones with specials
23  * rights (sysop, bureaucrat, developer) will have them displayed
24  * next to their names.
25  *
26  * @file
27  * @ingroup SpecialPage
28  */
29 class ActiveUsersPager extends UsersPager {
30
31         function __construct( $group = null ) {
32                 global $wgRequest, $wgRCMaxAge;
33                 $this->RCMaxAge = ceil( $wgRCMaxAge / ( 3600 * 24 ) ); // Constant
34
35                 $un = $wgRequest->getText( 'username' );
36                 $this->requestedUser = '';
37                 if ( $un != '' ) {
38                         $username = Title::makeTitleSafe( NS_USER, $un );
39                         if( !is_null( $username ) ) {
40                                 $this->requestedUser = $username->getText();
41                         }
42                 }
43                 
44                 $this->setupOptions();
45                 
46                 parent::__construct();
47         }
48
49         public function setupOptions() {
50                 global $wgRequest;
51                 
52                 $this->opts = new FormOptions();
53
54                 $this->opts->add( 'hidebots', false, FormOptions::BOOL );
55                 $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
56
57                 $this->opts->fetchValuesFromRequest( $wgRequest );
58
59                 $this->groups = array();
60                 if ($this->opts->getValue('hidebots') == 1)
61                         $this->groups['bot'] = true;
62                 if ($this->opts->getValue('hidesysops') == 1)
63                         $this->groups['sysop'] = true;
64         }
65
66         function getIndexField() {
67                 return 'rc_user_text';
68         }
69
70         function getQueryInfo() {
71                 $dbr = wfGetDB( DB_SLAVE );
72                 $conds = array( 'rc_user > 0' ); // Users - no anons
73                 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
74                 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
75                 
76                 if( $this->requestedUser != '' ) {
77                         $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
78                 }
79
80                 $query = array(
81                         'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
82                         'fields' => array( 'rc_user_text AS user_name', // inheritance
83                                 'rc_user_text', // for Pager
84                                 'user_id',
85                                 'COUNT(*) AS recentedits',
86                                 'MAX(ipb_user) AS blocked'
87                         ),
88                         'options' => array(
89                                 'GROUP BY' => 'rc_user_text, user_id',
90                                 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
91                         ),
92                         'join_conds' => array(
93                                 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
94                                 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
95                         ),
96                         'conds' => $conds
97                 );
98                 return $query;
99         }
100
101         function formatRow( $row ) {
102                 global $wgLang;
103                 $userName = $row->user_name;
104                 
105                 $ulinks = $this->getSkin()->userLink( $row->user_id, $userName );
106                 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id, $userName );
107
108                 $list = array();
109                 foreach( self::getGroups( $row->user_id ) as $group ) {
110                         if (isset($this->groups[$group]))
111                                 return;
112                         $list[] = self::buildGroupLink( $group );
113                 }
114                 $groups = $wgLang->commaList( $list );
115
116                 $item = wfSpecialList( $ulinks, $groups );
117                 $count = wfMsgExt( 'activeusers-count',
118                         array( 'parsemag' ),
119                         $wgLang->formatNum( $row->recentedits ),
120                         $userName,
121                         $wgLang->formatNum ( $this->RCMaxAge )
122                 );
123                 $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
124
125                 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
126         }
127
128         function getPageHeader() {
129                 global $wgScript, $wgRequest;
130
131                 $self = $this->getTitle();
132                 $limit = $this->mLimit ? Xml::hidden( 'limit', $this->mLimit ) : '';
133
134                 $out  = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
135                 $out .= Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n";
136                 $out .= Xml::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
137
138                 $out .= Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
139
140                 $out .= Xml::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
141
142                 $out .= Xml::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
143
144                 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .  "\n";# Submit button and form bottom
145                 $out .= Xml::closeElement( 'fieldset' );
146                 $out .= Xml::closeElement( 'form' );
147                 
148                 return $out;
149         }
150 }
151
152 /**
153  * @ingroup SpecialPage
154  */
155 class SpecialActiveUsers extends SpecialPage {
156
157         /**
158          * Constructor
159          */
160         public function  __construct() {
161                 parent::__construct( 'Activeusers' );
162         }
163
164         /**
165          * Show the special page
166          *
167          * @param $par Mixed: parameter passed to the page or null
168          */
169         public function execute( $par ) {
170                 global $wgOut, $wgLang, $wgRCMaxAge;
171
172                 $this->setHeaders();
173
174                 $up = new ActiveUsersPager();
175
176                 # getBody() first to check, if empty
177                 $usersbody = $up->getBody();
178
179                 $s = Html::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
180                         wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( ceil( $wgRCMaxAge / 86400 ) ) )
181                 );
182
183                 $s .= $up->getPageHeader();
184                 if( $usersbody ) {
185                         $s .= $up->getNavigationBar();
186                         $s .= Html::rawElement( 'ul', array(), $usersbody );
187                         $s .= $up->getNavigationBar();
188                 } else {
189                         $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
190                 }
191
192                 $wgOut->addHTML( $s );
193         }
194
195 }