5fb7fa5da35fd6d6f843542db919f43ca12faa49
[lhc/web/wiklou.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 parent::__construct();
44 }
45
46 function getIndexField() {
47 return 'rc_user_text';
48 }
49
50 function getQueryInfo() {
51 $dbr = wfGetDB( DB_SLAVE );
52 $conds = array( 'rc_user > 0' ); // Users - no anons
53 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
54 $conds[] = 'rc_log_type IS NULL OR rc_log_type != "newusers"';
55 if( $this->requestedUser != '' ) {
56 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
57 }
58
59 $query = array(
60 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
61 'fields' => array( 'rc_user_text AS user_name', // inheritance
62 'rc_user_text', // for Pager
63 'MAX(user_id) AS user_id',
64 'COUNT(*) AS recentedits',
65 'MAX(ipb_user) AS blocked'
66 ),
67 'options' => array(
68 'GROUP BY' => 'rc_user_text',
69 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
70 ),
71 'join_conds' => array(
72 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
73 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
74 ),
75 'conds' => $conds
76 );
77 return $query;
78 }
79
80 function formatRow( $row ) {
81 global $wgLang;
82 $userName = $row->user_name;
83
84 $ulinks = $this->getSkin()->userLink( $row->user_id, $userName );
85 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id, $userName );
86
87 $list = array();
88 foreach( self::getGroups( $row->user_id ) as $group ) {
89 $list[] = self::buildGroupLink( $group );
90 }
91 $groups = $wgLang->commaList( $list );
92
93 $item = wfSpecialList( $ulinks, $groups );
94 $count = wfMsgExt( 'activeusers-count',
95 array( 'parsemag' ),
96 $wgLang->formatNum( $row->recentedits ),
97 $userName,
98 $wgLang->formatNum ( $this->RCMaxAge )
99 );
100 $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
101
102 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
103 }
104
105 function getPageHeader() {
106 global $wgScript, $wgRequest;
107 $self = $this->getTitle();
108 $limit = $this->mLimit ? Xml::hidden( 'limit', $this->mLimit ) : '';
109
110 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . # Form tag
111 Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n" .
112 Xml::hidden( 'title', $self->getPrefixedDBkey() ) .
113 $limit . "\n" .
114 Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . ' ' . # Username field
115 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .# Submit button and form bottom
116 Xml::closeElement( 'fieldset' ) .
117 Xml::closeElement( 'form' );
118 }
119 }
120
121 /**
122 * @ingroup SpecialPage
123 */
124 class SpecialActiveUsers extends SpecialPage {
125
126 /**
127 * Constructor
128 */
129 public function __construct() {
130 parent::__construct( 'Activeusers' );
131 }
132
133 /**
134 * Show the special page
135 *
136 * @param $par Mixed: parameter passed to the page or null
137 */
138 public function execute( $par ) {
139 global $wgOut;
140
141 $this->setHeaders();
142
143 $up = new ActiveUsersPager();
144
145 # getBody() first to check, if empty
146 $usersbody = $up->getBody();
147 $s = $up->getPageHeader();
148 if( $usersbody ) {
149 $s .= $up->getNavigationBar();
150 $s .= Html::rawElement( 'ul', array(), $usersbody );
151 $s .= $up->getNavigationBar();
152 } else {
153 $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
154 }
155
156 $wgOut->addHTML( $s );
157 }
158
159 }