Allow use of GENDER in 'activeusers-count'
[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 $userName = $row->rc_user_text;
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 = implode( ', ', $list );
90
91 $item = wfSpecialList( $name, $groups );
92 $count = wfMsgExt( 'activeusers-count', array('parsemag'), $row->recentedits, $userName );
93 $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
94
95 return "<li>{$item} [{$count}]{$blocked}</li>";
96 }
97
98 function getPageHeader() {
99 global $wgScript, $wgRequest;
100 $self = $this->getTitle();
101
102 # Form tag
103 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
104 '<fieldset>' .
105 Xml::element( 'legend', array(), wfMsg( 'activeusers' ) );
106 $out .= Xml::hidden( 'title', $self->getPrefixedDbKey() );
107
108 # Username field
109 $out .= Xml::label( wfMsg( 'activeusers-from' ), 'offset' ) . ' ' .
110 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
111
112 # Submit button and form bottom
113 if( $this->mLimit )
114 $out .= Xml::hidden( 'limit', $this->mLimit );
115 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
116
117 $out .= '</fieldset>' . Xml::closeElement( 'form' );
118
119 return $out;
120 }
121 }
122
123 /**
124 * constructor
125 * $par string (optional) A group to list users from
126 */
127 function wfSpecialActiveusers( $par = null ) {
128 global $wgRequest, $wgOut;
129
130 $up = new ActiveUsersPager();
131
132 # getBody() first to check, if empty
133 $usersbody = $up->getBody();
134 $s = $up->getPageHeader();
135 if( $usersbody ) {
136 $s .= $up->getNavigationBar();
137 $s .= '<ul>' . $usersbody . '</ul>';
138 $s .= $up->getNavigationBar() ;
139 } else {
140 $s .= '<p>' . wfMsgHTML('activeusers-noresult') . '</p>';
141 };
142
143 $wgOut->addHTML( $s );
144 }