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