* Split out 'deletedcontent' from 'undelete' right (bug 19199/bug 9884)
[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 '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 $userPage = Title::makeTitle( NS_USER, $userName );
84 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
85
86 $list = array();
87 foreach( self::getGroups( $row->user_id ) as $group )
88 $list[] = self::buildGroupLink( $group );
89 $groups = $wgLang->commaList( $list );
90
91 $item = wfSpecialList( $name, $groups );
92 $count = wfMsgExt( 'activeusers-count',
93 array( 'parsemag' ),
94 $wgLang->formatNum( $row->recentedits ),
95 $userName,
96 $wgLang->formatNum ( $this->RCMaxAge )
97 );
98 $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
99
100 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
101 }
102
103 function getPageHeader() {
104 global $wgScript, $wgRequest;
105 $self = $this->getTitle();
106 $limit = $this->mLimit ? Xml::hidden( 'limit', $this->mLimit ) : '';
107
108 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . # Form tag
109 Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n" .
110 Xml::hidden( 'title', $self->getPrefixedDBkey() ) .
111 $limit . "\n" .
112 Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . ' ' . # Username field
113 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .# Submit button and form bottom
114 Xml::closeElement( 'fieldset' ) .
115 Xml::closeElement( 'form' );
116 }
117 }
118
119 /**
120 * @ingroup SpecialPage
121 */
122 class SpecialActiveUsers extends SpecialPage {
123
124 /**
125 * Constructor
126 */
127 public function __construct() {
128 parent::__construct( 'Activeusers' );
129 }
130
131 /**
132 * Show the special page
133 *
134 * @param $par Mixed: parameter passed to the page or null
135 */
136 public function execute( $par ) {
137 global $wgOut;
138
139 $this->setHeaders();
140
141 $up = new ActiveUsersPager();
142
143 # getBody() first to check, if empty
144 $usersbody = $up->getBody();
145 $s = $up->getPageHeader();
146 if( $usersbody ) {
147 $s .= $up->getNavigationBar();
148 $s .= Html::rawElement( 'ul', array(), $usersbody );
149 $s .= $up->getNavigationBar();
150 } else {
151 $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
152 }
153
154 $wgOut->addHTML( $s );
155 }
156
157 }