* (bug 1184) expiry time of indefinite blocks shown as the current time
[lhc/web/wiklou.git] / includes / SpecialListusers.php
1 <?php
2 # Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
3 # Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
21 /**
22 *
23 * @package MediaWiki
24 * @subpackage SpecialPage
25 */
26
27 /**
28 *
29 */
30 require_once("QueryPage.php");
31
32 /**
33 * This class is used to get a list of user. The ones with specials
34 * rights (sysop, bureaucrat, developer) will have them displayed
35 * next to their names.
36 *
37 * @package MediaWiki
38 * @subpackage SpecialPage
39 */
40 class ListUsersPage extends QueryPage {
41 var $requestedGroup = '';
42 var $requestedUser = '';
43
44 function getName() {
45 return "Listusers";
46 }
47 function isSyndicated() { return false; }
48
49 /**
50 * Show a drop down list to select a group as well as a user name
51 * search box.
52 * @TODO: localize
53 */
54 function getPageHeader( ) {
55 global $wgScript;
56
57 // Various variables used for the form
58 $action = htmlspecialchars( $wgScript );
59 $title = Title::makeTitle( NS_SPECIAL, 'Listusers' );
60 $special = htmlspecialchars( $title->getPrefixedDBkey() );
61
62 // form header
63 $out = '<form method="get" action="'.$action.'">' .
64 '<input type="hidden" name="title" value="'.$special.'" />' .
65 'Group: <select name="group">' .
66
67 // get all group names and id
68 $dbr = & wfGetDB( DB_SLAVE );
69 $group = $dbr->tableName( 'group' );
70 $sql = "SELECT group_id, group_name FROM $group;";
71 $result = $dbr->query($sql);
72
73 // we want a default empty group
74 $out.= '<option value=""></option>';
75
76 // build the dropdown list menu using datas from the database
77 while($agroup = $dbr->fetchObject( $result )) {
78 $selected = ($agroup->group_id == $this->requestedGroup) ? " selected " : "" ;
79 $out.= '<option value="'.$agroup->group_id.'" '.$selected.'>'.$agroup->group_name.'</option>';
80 }
81 $out .= '</select> ';
82
83 $out .= 'User: <input type="text" name="username" /> ';
84
85 // OK button, end of form.
86 $out .= '<input type="submit" /></form>';
87 // congratulations the form is now build
88 return $out;
89 }
90
91 function getSQL() {
92 $dbr =& wfGetDB( DB_SLAVE );
93 /* system showing possible actions for users
94 $user = $dbr->tableName( 'user' );
95 $user_rights = $dbr->tableName( 'user_rights' );
96 $userspace = Namespace::getUser();
97 return "SELECT ur_rights as type, $userspace as namespace, user_name as title, " .
98 "user_name as value FROM $user LEFT JOIN $user_rights ON user_id = ur_user";
99 */
100 /** Show groups instead */
101 $user = $dbr->tableName( 'user' );
102 $group = $dbr->tableName( 'group' );
103 $user_groups = $dbr->tableName( 'user_groups' );
104
105 $userspace = Namespace::getUser();
106 $sql = "SELECT group_name as type, $userspace AS namespace, user_name AS title, user_name as value " .
107 "FROM $user LEFT JOIN $user_groups ON user_id =ug_user " .
108 "LEFT JOIN $group ON ug_group = group_id ";
109
110 if($this->requestedGroup != '') {
111 $sql .= "WHERE group_id= '" . IntVal( $this->requestedGroup ) . "' ";
112 if($this->requestedUser != '') {
113 $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser ) . " ";
114 }
115 } else {
116 if($this->requestedUser !='') {
117 $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser ) . " ";
118 }
119 }
120
121 return $sql;
122 }
123
124 function sortDescending() {
125 return false;
126 }
127
128 function formatResult( $skin, $result ) {
129 global $wgContLang;
130 $name = $skin->makeLink( $wgContLang->getNsText($result->namespace) . ':' . $result->title, $result->title );
131 if( '' != $result->type ) {
132 $name .= ' (' .
133 $skin->makeLink( wfMsgForContent( 'administrators' ), $result->type) .
134 ')';
135 }
136 return $name;
137 }
138 }
139
140 /**
141 * constructor
142 */
143 function wfSpecialListusers() {
144 global $wgUser, $wgOut, $wgLang, $wgRequest;
145
146 list( $limit, $offset ) = wfCheckLimits();
147
148 $slu = new ListUsersPage();
149
150 /**
151 * Get some parameters
152 */
153 $slu->requestedGroup = $wgRequest->getVal('group');
154 $slu->requestedUser = $wgRequest->getVal('username');
155
156 return $slu->doQuery( $offset, $limit );
157 }
158
159 ?>