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