* Added a test for a link with multiple pipes
[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 var $previousResult = null;
44 var $concatGroups = '';
45
46 function getName() {
47 return 'Listusers';
48 }
49 function isSyndicated() { return false; }
50
51 /**
52 * Show a drop down list to select a group as well as a user name
53 * search box.
54 * @todo localize
55 */
56 function getPageHeader( ) {
57 global $wgScript;
58
59 // Various variables used for the form
60 $action = htmlspecialchars( $wgScript );
61 $title = Title::makeTitle( NS_SPECIAL, 'Listusers' );
62 $special = htmlspecialchars( $title->getPrefixedDBkey() );
63
64 // form header
65 $out = '<form method="get" action="'.$action.'">' .
66 '<input type="hidden" name="title" value="'.$special.'" />' .
67 wfMsg( 'grouplevels-editgroup-name' ) . '<select name="group">';
68
69 // get all group names and id
70 $dbr = & wfGetDB( DB_SLAVE );
71 $group = $dbr->tableName( 'group' );
72 $sql = "SELECT group_id, group_name FROM $group;";
73 $result = $dbr->query($sql);
74
75 // we want a default empty group
76 $out.= '<option value=""></option>';
77
78 // build the dropdown list menu using datas from the database
79 while($agroup = $dbr->fetchObject( $result )) {
80 $selected = ($agroup->group_id == $this->requestedGroup) ? ' selected ' : '' ;
81 $out.= '<option value="'.$agroup->group_id.'" '.$selected.'>'.$agroup->group_name.'</option>';
82 }
83 $out .= '</select> ';
84
85 $out .= wfMsg( 'specialloguserlabel' ) . '<input type="text" name="username" /> ';
86
87 // OK button, end of form.
88 $out .= '<input type="submit" /></form>';
89 // congratulations the form is now build
90 return $out;
91 }
92
93 function getSQL() {
94 $dbr =& wfGetDB( DB_SLAVE );
95 /* system showing possible actions for users
96 $user = $dbr->tableName( 'user' );
97 $user_rights = $dbr->tableName( 'user_rights' );
98 $userspace = Namespace::getUser();
99 return "SELECT ur_rights as type, $userspace as namespace, user_name as title, " .
100 "user_name as value FROM $user LEFT JOIN $user_rights ON user_id = ur_user";
101 */
102 /** Show groups instead */
103 $user = $dbr->tableName( 'user' );
104 $group = $dbr->tableName( 'group' );
105 $user_groups = $dbr->tableName( 'user_groups' );
106
107 $userspace = NS_USER;
108 $sql = "SELECT group_name as type, $userspace AS namespace, user_name AS title, user_name as value " .
109 "FROM $user ".
110 "LEFT JOIN $user_groups ON user_id =ug_user " .
111 "LEFT JOIN $group ON ug_group = group_id ";
112
113 if($this->requestedGroup != '') {
114 $sql .= "WHERE group_id= '" . IntVal( $this->requestedGroup ) . "' ";
115 if($this->requestedUser != '') {
116 $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' ';
117 }
118 } else {
119 if($this->requestedUser !='') {
120 $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' ';
121 }
122 }
123
124 return $sql;
125 }
126
127 /**
128 * When calling formatResult we output the previous result instead of the
129 * current one. We need an additional step to flush out the last result.
130 */
131 function tryLastResult( ) {
132 return true;
133 }
134
135 function sortDescending() {
136 return false;
137 }
138
139 function appendGroups($group) {
140 $this->concatGroups .= $group.' ';
141 }
142
143 function clearGroups() {
144 $this->concatGroups = '';
145 }
146 /*
147 var $previousResult = false;
148 var $concatGroups = '';
149 */
150 function formatResult( $skin, $result ) {
151 global $wgContLang;
152 $name = false;
153
154 if( is_object( $this->previousResult ) &&
155 (is_null( $result ) || ( $this->previousResult->title != $result->title ) ) ) {
156 // Different username, give back name(group1,group2)
157 $name = $skin->makeLink( $wgContLang->getNsText($this->previousResult->namespace) . ':' . $this->previousResult->title, $this->previousResult->title );
158 $name .= $this->concatGroups ? ' ('.substr($this->concatGroups,0,-1).')' : '';
159 $this->clearGroups();
160 }
161
162 if( is_object( $result ) && $result->type != '') {
163 $this->appendGroups( $skin->makeLink( wfMsgForContent( 'administrators' ), $result->type ) );
164 }
165
166 $this->previousResult = $result;
167 return $name;
168 }
169 }
170
171 /**
172 * constructor
173 */
174 function wfSpecialListusers() {
175 global $wgRequest;
176
177 list( $limit, $offset ) = wfCheckLimits();
178
179 $slu = new ListUsersPage();
180
181 /**
182 * Get some parameters
183 */
184 $slu->requestedGroup = $wgRequest->getVal('group');
185 $slu->requestedUser = $wgRequest->getVal('username');
186
187 return $slu->doQuery( $offset, $limit );
188 }
189
190 ?>