svn:eol-style
[lhc/web/wiklou.git] / includes / specials / SpecialActiveusers.php
1 <?php
2
3 # Copyright (C) 2008 Aaron Schulz
4 #
5 # http://www.mediawiki.org/
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # http://www.gnu.org/copyleft/gpl.html
21 /**
22 *
23 * @addtogroup SpecialPage
24 */
25
26 /**
27 * This class is used to get a list of user. The ones with specials
28 * rights (sysop, bureaucrat, developer) will have them displayed
29 * next to their names.
30 *
31 * @addtogroup SpecialPage
32 */
33
34 class ActiveUsersPager extends UsersPager {
35
36 function __construct($group=null) {
37 global $wgRequest;
38 $un = $wgRequest->getText( 'username' );
39 $this->requestedUser = '';
40 if ( $un != '' ) {
41 $username = Title::makeTitleSafe( NS_USER, $un );
42 if( ! is_null( $username ) ) {
43 $this->requestedUser = $username->getText();
44 }
45 }
46 parent::__construct();
47 }
48
49
50 function getIndexField() {
51 return 'rc_user_text';
52 }
53
54 function getQueryInfo() {
55 $dbr = wfGetDB( DB_SLAVE );
56 $conds = array();
57 // don't show hidden names
58 $conds[] = 'ipb_deleted IS NULL';
59 $useIndex = $dbr->useIndexClause('rc_user_text');
60 if( $this->requestedUser != "" ) {
61 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
62 }
63 $conds[] = 'rc_user > 0'; // Users - no anons
64
65 list ($recentchanges,$ipblocks) = $dbr->tableNamesN('recentchanges','ipblocks');
66
67 $query = array(
68 'tables' => " $recentchanges $useIndex
69 LEFT JOIN $ipblocks ON rc_user=ipb_user AND ipb_auto=0 AND ipb_deleted=1 ",
70 'fields' => array('rc_user_text AS user_name', // inheritance
71 'rc_user_text', // for Pager
72 'MAX(rc_user) AS user_id',
73 'COUNT(*) AS recentedits',
74 'MAX(ipb_user) AS blocked'),
75 'options' => array('GROUP BY' => 'user_name'),
76 'conds' => $conds
77 );
78 return $query;
79 }
80
81 function formatRow( $row ) {
82 $userPage = Title::makeTitle( NS_USER, $row->rc_user_text );
83 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
84
85 $list = array();
86 foreach( self::getGroups( $row->user_id ) as $group )
87 $list[] = self::buildGroupLink( $group );
88 $groups = implode( ', ', $list );
89
90 $item = wfSpecialList( $name, $groups );
91 $count = wfMsgExt( 'activeusers-count', array('parsemag'), $row->recentedits );
92 $blocked = $row->blocked ? ' '.wfMsg('listusers-blocked') : '';
93
94 return "<li>{$item} [{$count}]{$blocked}</li>";
95 }
96
97 function getPageHeader() {
98 global $wgScript, $wgRequest;
99 $self = $this->getTitle();
100
101 # Form tag
102 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
103 '<fieldset>' .
104 Xml::element( 'legend', array(), wfMsg( 'activeusers' ) );
105 $out .= Xml::hidden( 'title', $self->getPrefixedDbKey() );
106
107 # Username field
108 $out .= Xml::label( wfMsg( 'activeusers-from' ), 'offset' ) . ' ' .
109 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
110
111 # Submit button and form bottom
112 if( $this->mLimit )
113 $out .= Xml::hidden( 'limit', $this->mLimit );
114 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
115
116 $out .= '</fieldset>' . Xml::closeElement( 'form' );
117
118 return $out;
119 }
120 }
121
122 /**
123 * constructor
124 * $par string (optional) A group to list users from
125 */
126 function wfSpecialActiveusers( $par = null ) {
127 global $wgRequest, $wgOut;
128
129 $up = new ActiveUsersPager();
130
131 # getBody() first to check, if empty
132 $usersbody = $up->getBody();
133 $s = $up->getPageHeader();
134 if( $usersbody ) {
135 $s .= $up->getNavigationBar();
136 $s .= '<ul>' . $usersbody . '</ul>';
137 $s .= $up->getNavigationBar() ;
138 } else {
139 $s .= '<p>' . wfMsgHTML('activeusers-noresult') . '</p>';
140 };
141
142 $wgOut->addHTML( $s );
143 }