Index: trunk/extensions/CentralAuth/SpecialGlobalGroupPermissions.php |
— | — | @@ -1,15 +1,15 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -#This file is part of MediaWiki. |
| 4 | +# This file is part of MediaWiki. |
5 | 5 | |
6 | | -#MediaWiki is free software: you can redistribute it and/or modify |
7 | | -#it under the terms of version 2 of the GNU General Public License |
8 | | -#as published by the Free Software Foundation. |
| 6 | +# MediaWiki is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of version 2 of the GNU General Public License |
| 8 | +# as published by the Free Software Foundation. |
9 | 9 | |
10 | | -#MediaWiki is distributed in the hope that it will be useful, |
11 | | -#but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | -#GNU General Public License for more details. |
| 10 | +# MediaWiki is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Special page to allow managing global groups |
— | — | @@ -24,53 +24,53 @@ |
25 | 25 | } |
26 | 26 | |
27 | 27 | |
28 | | -class SpecialGlobalGroupPermissions extends SpecialPage |
29 | | -{ |
| 28 | +class SpecialGlobalGroupPermissions extends SpecialPage { |
30 | 29 | function __construct() { |
31 | 30 | parent::__construct( 'GlobalGroupPermissions' ); |
32 | | - wfLoadExtensionMessages('SpecialCentralAuth'); |
| 31 | + wfLoadExtensionMessages( 'SpecialCentralAuth' ); |
33 | 32 | } |
34 | | - |
35 | | - function userCanEdit($user) { |
| 33 | + |
| 34 | + function userCanEdit( $user ) { |
36 | 35 | $globalUser = CentralAuthUser::getInstance( $user ); |
37 | | - |
38 | | - ## Should be a global user |
39 | | - if (!$globalUser->exists() || !$globalUser->isAttached()) { |
| 36 | + |
| 37 | + # # Should be a global user |
| 38 | + if ( !$globalUser->exists() || !$globalUser->isAttached() ) { |
40 | 39 | return false; |
41 | 40 | } |
42 | | - |
43 | | - ## Permission MUST be gained from global rights. |
| 41 | + |
| 42 | + # # Permission MUST be gained from global rights. |
44 | 43 | return $globalUser->hasGlobalPermission( 'globalgrouppermissions' ); |
45 | 44 | } |
46 | 45 | |
47 | 46 | function execute( $subpage ) { |
48 | | - global $wgRequest,$wgOut,$wgUser; |
49 | | - |
50 | | - if (!$this->userCanExecute($wgUser)) { |
| 47 | + global $wgRequest, $wgOut, $wgUser; |
| 48 | + |
| 49 | + if ( !$this->userCanExecute( $wgUser ) ) { |
51 | 50 | $this->displayRestrictionError(); |
52 | 51 | return; |
53 | 52 | } |
54 | | - |
| 53 | + |
55 | 54 | $wgOut->setPageTitle( wfMsg( 'globalgrouppermissions' ) ); |
56 | 55 | $wgOut->setRobotPolicy( "noindex,nofollow" ); |
57 | 56 | $wgOut->setArticleRelated( false ); |
58 | 57 | $wgOut->enableClientCache( false ); |
59 | | - |
60 | | - if ($subpage == '' ) { |
| 58 | + |
| 59 | + if ( $subpage == '' ) { |
61 | 60 | $subpage = $wgRequest->getVal( 'wpGroup' ); |
62 | 61 | } |
63 | 62 | |
64 | | - if ($subpage != '' && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )) { |
65 | | - $this->doSubmit($subpage); |
66 | | - } else if ($subpage != '') { |
67 | | - $this->buildGroupView($subpage); |
| 63 | + if ( $subpage != '' && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
| 64 | + $this->doSubmit( $subpage ); |
| 65 | + } else if ( $subpage != '' ) { |
| 66 | + $this->buildGroupView( $subpage ); |
68 | 67 | } else { |
69 | 68 | $this->buildMainView(); |
70 | 69 | } |
71 | 70 | } |
72 | 71 | |
73 | 72 | function buildMainView() { |
74 | | - global $wgOut,$wgUser,$wgScript; |
| 73 | + global $wgOut, $wgUser, $wgScript; |
| 74 | + |
75 | 75 | $sk = $wgUser->getSkin(); |
76 | 76 | |
77 | 77 | $groups = CentralAuthUser::availableGlobalGroups(); |
— | — | @@ -80,12 +80,12 @@ |
81 | 81 | |
82 | 82 | $wgOut->addHTML( $html ); |
83 | 83 | |
84 | | - if (count($groups)) { |
| 84 | + if ( count( $groups ) ) { |
85 | 85 | $wgOut->addWikiMsg( 'centralauth-globalgroupperms-grouplist' ); |
86 | 86 | $wgOut->addHTML( '<ul>' ); |
87 | 87 | |
88 | | - foreach ($groups as $group) { |
89 | | - $text = wfMsgExt( 'centralauth-globalgroupperms-grouplistitem', array( 'parseinline' ), User::getGroupName($group), $group ); |
| 88 | + foreach ( $groups as $group ) { |
| 89 | + $text = wfMsgExt( 'centralauth-globalgroupperms-grouplistitem', array( 'parseinline' ), User::getGroupName( $group ), $group ); |
90 | 90 | |
91 | 91 | $wgOut->addHTML( "<li> $text </li>" ); |
92 | 92 | } |
— | — | @@ -100,18 +100,18 @@ |
101 | 101 | $html = Xml::fieldset( wfMsg( 'centralauth-newgroup-legend' ) ); |
102 | 102 | $html .= wfMsgExt( 'centralauth-newgroup-intro', array( 'parse' ) ); |
103 | 103 | $html .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'centralauth-globalgroups-newgroup' ) ); |
104 | | - $html .= Xml::hidden( 'title', SpecialPage::getTitleFor('GlobalGroupPermissions')->getPrefixedText() ); |
105 | | - |
| 104 | + $html .= Xml::hidden( 'title', SpecialPage::getTitleFor( 'GlobalGroupPermissions' )->getPrefixedText() ); |
| 105 | + |
106 | 106 | $fields = array( 'centralauth-globalgroupperms-newgroupname' => Xml::input( 'wpGroup' ) ); |
107 | | - |
| 107 | + |
108 | 108 | $html .= Xml::buildForm( $fields, 'centralauth-globalgroupperms-creategroup-submit' ); |
109 | 109 | $html .= Xml::closeElement( 'form' ); |
110 | 110 | $html .= Xml::closeElement( 'fieldset' ); |
111 | | - |
| 111 | + |
112 | 112 | $wgOut->addHTML( $html ); |
113 | 113 | } |
114 | 114 | } |
115 | | - |
| 115 | + |
116 | 116 | function buildGroupView( $group ) { |
117 | 117 | global $wgOut, $wgUser, $wgScript; |
118 | 118 | |
— | — | @@ -122,47 +122,47 @@ |
123 | 123 | $html = Xml::fieldset( wfMsg( 'centralauth-editgroup-fieldset', $group ) ); |
124 | 124 | |
125 | 125 | if ( $editable ) { |
126 | | - $html .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => SpecialPage::getTitleFor('GlobalGroupPermissions', $group)->getLocalUrl(), 'name' => 'centralauth-globalgroups-newgroup' ) ); |
| 126 | + $html .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => SpecialPage::getTitleFor( 'GlobalGroupPermissions', $group )->getLocalUrl(), 'name' => 'centralauth-globalgroups-newgroup' ) ); |
127 | 127 | $html .= Xml::hidden( 'wpGroup', $group ); |
128 | 128 | $html .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
129 | 129 | } |
130 | | - |
| 130 | + |
131 | 131 | $fields = array(); |
132 | | - |
| 132 | + |
133 | 133 | $fields['centralauth-editgroup-name'] = $group; |
134 | 134 | $fields['centralauth-editgroup-display'] = wfMsgExt( 'centralauth-editgroup-display-edit', array( 'parseinline' ), $group, User::getGroupName( $group ) ); |
135 | 135 | $fields['centralauth-editgroup-member'] = wfMsgExt( 'centralauth-editgroup-member-edit', array( 'parseinline' ), $group, User::getGroupMember( $group ) ); |
136 | 136 | $fields['centralauth-editgroup-members'] = wfMsgExt( 'centralauth-editgroup-members-link', array( 'parseinline' ), $group, User::getGroupMember( $group ) ); |
137 | | - $fields['centralauth-editgroup-restrictions'] = $this->buildWikiSetSelector($group); |
138 | | - $fields['centralauth-editgroup-perms'] = $this->buildCheckboxes($group); |
139 | | - |
| 137 | + $fields['centralauth-editgroup-restrictions'] = $this->buildWikiSetSelector( $group ); |
| 138 | + $fields['centralauth-editgroup-perms'] = $this->buildCheckboxes( $group ); |
| 139 | + |
140 | 140 | if ( $editable ) { |
141 | 141 | $fields['centralauth-editgroup-reason'] = Xml::input( 'wpReason', 60 ); |
142 | 142 | } |
143 | | - |
| 143 | + |
144 | 144 | $html .= Xml::buildForm( $fields, $editable ? 'centralauth-editgroup-submit' : null ); |
145 | | - |
146 | | - if ($editable) |
| 145 | + |
| 146 | + if ( $editable ) |
147 | 147 | $html .= Xml::closeElement( 'form' ); |
148 | | - |
| 148 | + |
149 | 149 | $html .= Xml::closeElement( 'fieldset' ); |
150 | | - |
| 150 | + |
151 | 151 | $wgOut->addHTML( $html ); |
152 | | - |
| 152 | + |
153 | 153 | $this->showLogFragment( $group, $wgOut ); |
154 | 154 | } |
155 | 155 | |
156 | 156 | function buildWikiSetSelector( $group ) { |
157 | 157 | $sets = WikiSet::getAllWikiSets(); |
158 | 158 | $default = WikiSet::getWikiSetForGroup( $group ); |
159 | | - |
| 159 | + |
160 | 160 | global $wgUser; |
161 | 161 | if ( !$this->userCanEdit( $wgUser ) ) |
162 | 162 | return htmlspecialchars( $default ); |
163 | 163 | |
164 | 164 | $select = new XmlSelect( 'set', 'wikiset', $default ); |
165 | 165 | $select->addOption( wfMsg( 'centralauth-editgroup-noset' ), '0' ); |
166 | | - foreach( $sets as $set ) { |
| 166 | + foreach ( $sets as $set ) { |
167 | 167 | $select->addOption( $set->getName(), $set->getID() ); |
168 | 168 | } |
169 | 169 | |
— | — | @@ -171,22 +171,22 @@ |
172 | 172 | } |
173 | 173 | |
174 | 174 | function buildCheckboxes( $group ) { |
175 | | - |
176 | 175 | global $wgUser, $wgOut; |
| 176 | + |
177 | 177 | $editable = $this->userCanEdit( $wgUser ); |
178 | | - |
| 178 | + |
179 | 179 | $rights = User::getAllRights(); |
180 | 180 | $assignedRights = $this->getAssignedRights( $group ); |
181 | | - |
182 | | - sort($rights); |
183 | | - |
| 181 | + |
| 182 | + sort( $rights ); |
| 183 | + |
184 | 184 | $checkboxes = array(); |
185 | 185 | $attribs = array(); |
186 | | - |
187 | | - if (!$editable) |
| 186 | + |
| 187 | + if ( !$editable ) |
188 | 188 | $attribs['disabled'] = 'disabled'; |
189 | | - |
190 | | - foreach( $rights as $right ) { |
| 189 | + |
| 190 | + foreach ( $rights as $right ) { |
191 | 191 | # Build a checkbox. |
192 | 192 | $checked = in_array( $right, $assignedRights ); |
193 | 193 | |
— | — | @@ -196,124 +196,124 @@ |
197 | 197 | $checkbox = Xml::check( "wpRightAssigned-$right", $checked, $attribs ); |
198 | 198 | $label = Xml::tags( 'label', array( 'for' => "wpRightAssigned-$right" ), |
199 | 199 | $desc ); |
200 | | - |
| 200 | + |
201 | 201 | $checkboxes[] = "<li>$checkbox $label</li>"; |
202 | 202 | } |
203 | | - |
204 | | - $count = count($checkboxes); |
205 | | - |
206 | | - $firstCol = round($count/2); |
207 | | - |
208 | | - $checkboxes1 = array_slice($checkboxes, 0, $firstCol); |
209 | | - $checkboxes2 = array_slice($checkboxes, $firstCol ); |
210 | | - |
| 203 | + |
| 204 | + $count = count( $checkboxes ); |
| 205 | + |
| 206 | + $firstCol = round( $count / 2 ); |
| 207 | + |
| 208 | + $checkboxes1 = array_slice( $checkboxes, 0, $firstCol ); |
| 209 | + $checkboxes2 = array_slice( $checkboxes, $firstCol ); |
| 210 | + |
211 | 211 | $html = '<table><tbody><tr><td><ul>'; |
212 | | - |
213 | | - foreach( $checkboxes1 as $cb ) { |
| 212 | + |
| 213 | + foreach ( $checkboxes1 as $cb ) { |
214 | 214 | $html .= $cb; |
215 | 215 | } |
216 | | - |
| 216 | + |
217 | 217 | $html .= '</ul></td><td><ul>'; |
218 | | - |
219 | | - foreach( $checkboxes2 as $cb ) { |
| 218 | + |
| 219 | + foreach ( $checkboxes2 as $cb ) { |
220 | 220 | $html .= $cb; |
221 | 221 | } |
222 | | - |
| 222 | + |
223 | 223 | $html .= '</ul></td></tr></tbody></table>'; |
224 | | - |
| 224 | + |
225 | 225 | return $html; |
226 | 226 | } |
227 | | - |
| 227 | + |
228 | 228 | function getAssignedRights( $group ) { |
229 | 229 | return CentralAuthUser::globalGroupPermissions( $group ); |
230 | 230 | } |
231 | | - |
| 231 | + |
232 | 232 | function doSubmit( $group ) { |
233 | | - global $wgRequest,$wgOut,$wgScript,$wgUser; |
234 | | - |
| 233 | + global $wgRequest, $wgOut, $wgScript, $wgUser; |
| 234 | + |
235 | 235 | // Paranoia -- the edit token shouldn't match anyway |
236 | | - if (!$this->userCanEdit( $wgUser )) |
| 236 | + if ( !$this->userCanEdit( $wgUser ) ) |
237 | 237 | return; |
238 | | - |
| 238 | + |
239 | 239 | $newRights = array(); |
240 | 240 | $addRights = array(); |
241 | 241 | $removeRights = array(); |
242 | 242 | $oldRights = $this->getAssignedRights( $group ); |
243 | 243 | $allRights = User::getAllRights(); |
244 | | - |
| 244 | + |
245 | 245 | $reason = $wgRequest->getVal( 'wpReason', '' ); |
246 | | - |
247 | | - foreach ($allRights as $right) { |
| 246 | + |
| 247 | + foreach ( $allRights as $right ) { |
248 | 248 | $alreadyAssigned = in_array( $right, $oldRights ); |
249 | | - |
250 | | - if ($wgRequest->getCheck( "wpRightAssigned-$right" )) { |
| 249 | + |
| 250 | + if ( $wgRequest->getCheck( "wpRightAssigned-$right" ) ) { |
251 | 251 | $newRights[] = $right; |
252 | 252 | } |
253 | | - |
254 | | - if (!$alreadyAssigned && $wgRequest->getCheck( "wpRightAssigned-$right" )) { |
| 253 | + |
| 254 | + if ( !$alreadyAssigned && $wgRequest->getCheck( "wpRightAssigned-$right" ) ) { |
255 | 255 | $addRights[] = $right; |
256 | | - } else if ($alreadyAssigned && !$wgRequest->getCheck( "wpRightAssigned-$right" ) ) { |
| 256 | + } else if ( $alreadyAssigned && !$wgRequest->getCheck( "wpRightAssigned-$right" ) ) { |
257 | 257 | $removeRights[] = $right; |
258 | 258 | } # Otherwise, do nothing. |
259 | 259 | } |
260 | | - |
| 260 | + |
261 | 261 | // Assign the rights. |
262 | | - if (count($addRights)>0) |
| 262 | + if ( count( $addRights ) > 0 ) |
263 | 263 | $this->grantRightsToGroup( $group, $addRights ); |
264 | | - if (count($removeRights)>0) |
| 264 | + if ( count( $removeRights ) > 0 ) |
265 | 265 | $this->revokeRightsFromGroup( $group, $removeRights ); |
266 | | - |
| 266 | + |
267 | 267 | // Log it |
268 | | - if (!(count($addRights)==0 && count($removeRights)==0)) |
| 268 | + if ( !( count( $addRights ) == 0 && count( $removeRights ) == 0 ) ) |
269 | 269 | $this->addLogEntry( $group, $addRights, $removeRights, $reason ); |
270 | 270 | |
271 | 271 | // Change set |
272 | 272 | $current = WikiSet::getWikiSetForGroup( $group ); |
273 | 273 | $new = $wgRequest->getVal( 'set' ); |
274 | | - if( $current != $new ) { |
| 274 | + if ( $current != $new ) { |
275 | 275 | $this->setRestrictions( $group, $new ); |
276 | 276 | $this->addLogEntry2( $group, $current, $new, $reason ); |
277 | 277 | } |
278 | 278 | |
279 | 279 | $this->invalidateRightsCache( $group ); |
280 | | - |
| 280 | + |
281 | 281 | // Display success |
282 | 282 | $wgOut->setSubTitle( wfMsg( 'centralauth-editgroup-success' ) ); |
283 | 283 | $wgOut->addWikiMsg( 'centralauth-editgroup-success-text', $group ); |
284 | 284 | } |
285 | | - |
| 285 | + |
286 | 286 | function revokeRightsFromGroup( $group, $rights ) { |
287 | 287 | $dbw = CentralAuthUser::getCentralDB(); |
288 | | - |
| 288 | + |
289 | 289 | # Delete from the DB |
290 | | - $dbw->delete( 'global_group_permissions', array( 'ggp_group' => $group, 'ggp_permission' => $rights), __METHOD__ ); |
| 290 | + $dbw->delete( 'global_group_permissions', array( 'ggp_group' => $group, 'ggp_permission' => $rights ), __METHOD__ ); |
291 | 291 | } |
292 | | - |
| 292 | + |
293 | 293 | function grantRightsToGroup( $group, $rights ) { |
294 | 294 | $dbw = CentralAuthUser::getCentralDB(); |
295 | | - |
296 | | - if (!is_array($rights)) { |
297 | | - $rights = array($rights); |
| 295 | + |
| 296 | + if ( !is_array( $rights ) ) { |
| 297 | + $rights = array( $rights ); |
298 | 298 | } |
299 | | - |
| 299 | + |
300 | 300 | $insertRows = array(); |
301 | | - foreach( $rights as $right ) { |
| 301 | + foreach ( $rights as $right ) { |
302 | 302 | $insertRows[] = array( 'ggp_group' => $group, 'ggp_permission' => $right ); |
303 | 303 | } |
304 | | - |
| 304 | + |
305 | 305 | # Replace into the DB |
306 | 306 | $dbw->replace( 'global_group_permissions', array( 'ggp_group', 'ggp_permission' ), $insertRows, __METHOD__ ); |
307 | 307 | } |
308 | | - |
| 308 | + |
309 | 309 | protected function showLogFragment( $group, $output ) { |
310 | 310 | $title = SpecialPage::getTitleFor( 'GlobalUsers', $group ); |
311 | 311 | $output->addHTML( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) ); |
312 | 312 | LogEventsList::showLogExtract( $output, 'gblrights', $title->getPrefixedText() ); |
313 | 313 | } |
314 | | - |
| 314 | + |
315 | 315 | function addLogEntry( $group, $addRights, $removeRights, $reason ) { |
316 | 316 | global $wgRequest; |
317 | | - |
| 317 | + |
318 | 318 | $log = new LogPage( 'gblrights' ); |
319 | 319 | |
320 | 320 | $log->addEntry( 'groupprms2', |
— | — | @@ -325,14 +325,14 @@ |
326 | 326 | ) |
327 | 327 | ); |
328 | 328 | } |
329 | | - |
| 329 | + |
330 | 330 | function makeRightsList( $ids ) { |
331 | | - return (bool)count($ids) ? implode( ', ', $ids ) : wfMsgForContent( 'rightsnone' ); |
| 331 | + return (bool)count( $ids ) ? implode( ', ', $ids ) : wfMsgForContent( 'rightsnone' ); |
332 | 332 | } |
333 | 333 | |
334 | 334 | function setRestrictions( $group, $set ) { |
335 | 335 | $dbw = CentralAuthUser::getCentralDB(); |
336 | | - if( $set == 0 ) { |
| 336 | + if ( $set == 0 ) { |
337 | 337 | $dbw->delete( 'global_group_restrictions', array( 'ggr_group' => $group ), __METHOD__ ); |
338 | 338 | } else { |
339 | 339 | $dbw->replace( 'global_group_restrictions', array( 'ggr_group' ), |
— | — | @@ -343,7 +343,7 @@ |
344 | 344 | |
345 | 345 | function addLogEntry2( $group, $old, $new, $reason ) { |
346 | 346 | global $wgRequest; |
347 | | - |
| 347 | + |
348 | 348 | $log = new LogPage( 'gblrights' ); |
349 | 349 | |
350 | 350 | $log->addEntry( 'groupprms3', |
— | — | @@ -357,7 +357,7 @@ |
358 | 358 | } |
359 | 359 | |
360 | 360 | function getWikiSetName( $id ) { |
361 | | - if( $id ) |
| 361 | + if ( $id ) |
362 | 362 | return WikiSet::newFromID( $id )->getName(); |
363 | 363 | else |
364 | 364 | return wfMsgForContent( 'centralauth-editgroup-noset' ); |
— | — | @@ -365,14 +365,14 @@ |
366 | 366 | |
367 | 367 | function invalidateRightsCache( $group ) { |
368 | 368 | global $wgMemc; |
369 | | - |
| 369 | + |
370 | 370 | // Figure out all the users in this group. |
371 | 371 | $dbr = CentralAuthUser::getCentralDB(); |
372 | | - |
373 | | - $res = $dbr->select( array('global_user_groups','globaluser'), 'gu_name', array( 'gug_group' => $group, 'gu_id=gug_user' ), __METHOD__ ); |
374 | | - |
| 372 | + |
| 373 | + $res = $dbr->select( array( 'global_user_groups', 'globaluser' ), 'gu_name', array( 'gug_group' => $group, 'gu_id=gug_user' ), __METHOD__ ); |
| 374 | + |
375 | 375 | // Invalidate their rights cache. |
376 | | - while ($row = $res->fetchObject() ) { |
| 376 | + while ( $row = $res->fetchObject() ) { |
377 | 377 | $cu = new CentralAuthUser( $row->gu_name ); |
378 | 378 | $cu->quickInvalidateCache(); |
379 | 379 | } |