Index: trunk/extensions/CentralAuth/SpecialGlobalGroupMembership.php |
— | — | @@ -1,69 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * |
6 | | - * Equivalent of Special:Userrights for global groups. |
7 | | - * @addtogroup extensions |
8 | | - */ |
9 | | - |
10 | | -class SpecialGlobalGroupMembership extends UserrightsPage { |
11 | | - var $mGlobalUser; |
12 | | - function SpecialGlobalGroupMembership() { |
13 | | - SpecialPage::SpecialPage( 'GlobalGroupMembership' ); |
14 | | - |
15 | | - global $wgUser; |
16 | | - $this->mGlobalUser = CentralAuthUser::getInstance( $wgUser ); |
17 | | - } |
18 | | - |
19 | | - function changeableGroups() { |
20 | | - global $wgUser; |
21 | | - |
22 | | - ## Should be a global user |
23 | | - if (!$this->mGlobalUser->exists() || !$this->mGlobalUser->isAttached()) { |
24 | | - return array(); |
25 | | - } |
26 | | - |
27 | | - $allgroups = CentralAuthUser::availableGlobalGroups(); |
28 | | - |
29 | | - ## Permission MUST be gained from global rights. |
30 | | - return $this->mGlobalUser->hasGlobalPermission( 'globalgroupmembership' ) ? array( 'add' => $allgroups, 'remove' => $allgroups): array(); |
31 | | - } |
32 | | - |
33 | | - function fetchUser( $username ) { |
34 | | - global $wgOut, $wgUser; |
35 | | - |
36 | | - $user = CentralAuthGroupMembershipProxy::newFromName( $username ); |
37 | | - |
38 | | - if( !$user ) { |
39 | | - $wgOut->addWikiMsg( 'nosuchusershort', $username ); |
40 | | - return null; |
41 | | - } |
42 | | - |
43 | | - return $user; |
44 | | - } |
45 | | - |
46 | | - protected static function getAllGroups() { |
47 | | - return CentralAuthUser::availableGlobalGroups(); |
48 | | - } |
49 | | - |
50 | | - protected function showLogFragment( $user, $output ) { |
51 | | - $pagetitle = Title::makeTitleSafe( NS_USER, $user->getName()); |
52 | | - $output->addHtml( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) ); |
53 | | - LogEventsList::showLogExtract( $output, 'globalrights', $pagetitle->getPrefixedText ); |
54 | | - } |
55 | | - |
56 | | - function addLogEntry( $user, $oldGroups, $newGroups ) { |
57 | | - global $wgRequest; |
58 | | - |
59 | | - $log = new LogPage( 'gblrights' ); |
60 | | - |
61 | | - $log->addEntry( 'usergroups', |
62 | | - $user->getUserPage(), |
63 | | - $wgRequest->getText( 'user-reason' ), |
64 | | - array( |
65 | | - $this->makeGroupNameList( $oldGroups ), |
66 | | - $this->makeGroupNameList( $newGroups ) |
67 | | - ) |
68 | | - ); |
69 | | - } |
70 | | -} |
Index: trunk/extensions/CentralAuth/SpecialGlobalGroupPermissions.php |
— | — | @@ -1,512 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -#This file is part of MediaWiki. |
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. |
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. |
14 | | - |
15 | | -/** |
16 | | - * Special page to allow managing global groups |
17 | | - * Prototype for a similar system in core. |
18 | | - * |
19 | | - * @addtogroup Extensions |
20 | | - */ |
21 | | - |
22 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
23 | | - echo "CentralAuth extension\n"; |
24 | | - exit( 1 ); |
25 | | -} |
26 | | - |
27 | | - |
28 | | -class SpecialGlobalGroupPermissions extends SpecialPage |
29 | | -{ |
30 | | - function __construct() { |
31 | | - SpecialPage::SpecialPage('GlobalGroupPermissions', 'globalgrouppermissions'); |
32 | | - wfLoadExtensionMessages('SpecialCentralAuth'); |
33 | | - } |
34 | | - |
35 | | - function userCanExecute($user) { |
36 | | - $globalUser = CentralAuthUser::getInstance( $user ); |
37 | | - |
38 | | - ## Should be a global user |
39 | | - if (!$globalUser->exists() || !$globalUser->isAttached()) { |
40 | | - return false; |
41 | | - } |
42 | | - |
43 | | - ## Permission MUST be gained from global rights. |
44 | | - return $globalUser->hasGlobalPermission( 'globalgrouppermissions' ); |
45 | | - } |
46 | | - |
47 | | - function execute( $subpage ) { |
48 | | - global $wgRequest,$wgOut,$wgUser; |
49 | | - |
50 | | - if (!$this->userCanExecute($wgUser)) { |
51 | | - $this->displayRestrictionError(); |
52 | | - return; |
53 | | - } |
54 | | - |
55 | | - $wgOut->setPageTitle( wfMsg( 'globalgrouppermissions' ) ); |
56 | | - $wgOut->setRobotpolicy( "noindex,nofollow" ); |
57 | | - $wgOut->setArticleRelated( false ); |
58 | | - $wgOut->enableClientCache( false ); |
59 | | - |
60 | | - if ($subpage == '' ) { |
61 | | - $subpage = $wgRequest->getVal( 'wpGroup' ); |
62 | | - } |
63 | | - |
64 | | - if ($subpage != '' && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )) { |
65 | | - $this->doSubmit($subpage); |
66 | | - } else if ($subpage != '') { |
67 | | - $this->buildGroupView($subpage); |
68 | | - } else { |
69 | | - $this->buildMainView(); |
70 | | - } |
71 | | - } |
72 | | - |
73 | | - function buildMainView() { |
74 | | - global $wgOut,$wgUser,$wgInvitationTypes; |
75 | | - $sk = $wgUser->getSkin(); |
76 | | - |
77 | | - $groups = CentralAuthUser::availableGlobalGroups(); |
78 | | - |
79 | | - // Existing groups |
80 | | - $html = Xml::openElement( 'fieldset' ); |
81 | | - $html .= Xml::element( 'legend', null, wfMsg( 'centralauth-existinggroup-legend' ) ); |
82 | | - |
83 | | - $wgOut->addHtml( $html ); |
84 | | - |
85 | | - if (count($groups)) { |
86 | | - $wgOut->addWikitext( wfMsg( 'centralauth-globalgroupperms-grouplist' ) ); |
87 | | - $wgOut->addHTML( '<ul>' ); |
88 | | - |
89 | | - foreach ($groups as $group) { |
90 | | - $text = wfMsgExt( 'centralauth-globalgroupperms-grouplistitem', array( 'parseinline' ), User::getGroupName($group), $group ); |
91 | | - |
92 | | - $wgOut->addHTML( "<li> $text </li>" ); |
93 | | - } |
94 | | - } else { |
95 | | - $wgOut->addWikitext( wfMsg( 'centralauth-globalgroupperms-nogroups' ) ); |
96 | | - } |
97 | | - |
98 | | - $wgOut->addHtml( Xml::closeElement( 'fieldset' ) ); |
99 | | - |
100 | | - // "Create a group" prompt |
101 | | - $html = Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'centralauth-newgroup-legend' ) ); |
102 | | - $html .= wfMsgExt( 'centralauth-newgroup-intro', array( 'parse' ) ); |
103 | | - $html .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'centralauth-globalgroups-newgroup' ) ); |
104 | | - $html .= Xml::hidden( 'title', SpecialPage::getTitleFor('GlobalGroupPermissions')->getPrefixedText() ); |
105 | | - $html .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
106 | | - |
107 | | - $fields = array( 'centralauth-globalgroupperms-newgroupname' => wfInput( 'wpGroup' ) ); |
108 | | - |
109 | | - $html .= wfBuildForm( $fields, 'centralauth-globalgroupperms-creategroup-submit' ); |
110 | | - $html .= Xml::closeElement( 'fieldset' ); |
111 | | - |
112 | | - $wgOut->addHtml( $html ); |
113 | | - } |
114 | | - |
115 | | - function buildGroupView( $group ) { |
116 | | - global $wgOut, $wgUser; |
117 | | - |
118 | | - $wgOut->setSubtitle( wfMsg( 'centralauth-editgroup-subtitle', $group ) ); |
119 | | - |
120 | | - $html = Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'centralauth-editgroup-fieldset', $group ) ); |
121 | | - $html .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'centralauth-globalgroups-newgroup' ) ); |
122 | | - $html .= Xml::hidden( 'title', SpecialPage::getTitleFor('GlobalGroupPermissions')->getPrefixedText() ); |
123 | | - $html .= Xml::hidden( 'wpGroup', $group ); |
124 | | - $html .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
125 | | - |
126 | | - $fields = array(); |
127 | | - |
128 | | - $fields['centralauth-editgroup-name'] = $group; |
129 | | - $fields['centralauth-editgroup-display'] = wfMsgExt( 'centralauth-editgroup-display-edit', array( 'parseinline' ), $group, User::getGroupName( $group ) ); |
130 | | - $fields['centralauth-editgroup-member'] = wfMsgExt( 'centralauth-editgroup-member-edit', array( 'parseinline' ), $group, User::getGroupMember( $group ) ); |
131 | | - $fields['centralauth-editgroup-members'] = wfMsgExt( 'centralauth-editgroup-members-link', array( 'parseinline' ), $group, User::getGroupMember( $group ) ); |
132 | | - $fields['centralauth-editgroup-perms'] = $this->buildCheckboxes($group); |
133 | | - $fields['centralauth-editgroup-reason'] = wfInput( 'wpReason' ); |
134 | | - |
135 | | - $html .= wfBuildForm( $fields, 'centralauth-editgroup-submit' ); |
136 | | - |
137 | | - $html .= Xml::closeElement( 'form' ); |
138 | | - $html .= Xml::closeElement( 'fieldset' ); |
139 | | - |
140 | | - $wgOut->addHtml( $html ); |
141 | | - |
142 | | - $this->showLogFragment( $group, $wgOut ); |
143 | | - } |
144 | | - |
145 | | - function buildCheckboxes( $group ) { |
146 | | - $html = '<ul>'; |
147 | | - |
148 | | - $rights = wfGetAvailableRights(); |
149 | | - $assignedRights = $this->getAssignedRights( $group ); |
150 | | - |
151 | | - foreach( $rights as $right ) { |
152 | | - # Build a checkbox. |
153 | | - $checked = in_array( $right, $assignedRights ); |
154 | | - |
155 | | - $checkbox = wfCheckLabel( wfMsg( "right-$right" ), "wpRightAssigned-$right", "wpRightAssigned-$right", $checked ); |
156 | | - |
157 | | - $html .= "<li>$checkbox</li>"; |
158 | | - } |
159 | | - |
160 | | - $html .= '</ul>'; |
161 | | - |
162 | | - return $html; |
163 | | - } |
164 | | - |
165 | | - function getAssignedRights( $group ) { |
166 | | - return CentralAuthUser::globalGroupPermissions( $group ); |
167 | | - } |
168 | | - |
169 | | - function doSubmit( $group ) { |
170 | | - global $wgRequest,$wgOut; |
171 | | - |
172 | | - $newRights = array(); |
173 | | - $addRights = array(); |
174 | | - $removeRights = array(); |
175 | | - $oldRights = $this->getAssignedRights( $group ); |
176 | | - $allRights = wfGetAvailableRights(); |
177 | | - |
178 | | - $reason = $wgRequest->getVal( 'wpReason', '' ); |
179 | | - |
180 | | - foreach ($allRights as $right) { |
181 | | - $alreadyAssigned = in_array( $right, $oldRights ); |
182 | | - |
183 | | - if ($wgRequest->getCheck( "wpRightAssigned-$right" )) { |
184 | | - $newGroups[] = $right; |
185 | | - } |
186 | | - |
187 | | - if (!$alreadyAssigned && $wgRequest->getCheck( "wpRightAssigned-$right" )) { |
188 | | - $addRights[] = $right; |
189 | | - } else if ($alreadyAssigned && !$wgRequest->getCheck( "wpRightAssigned-$right" ) ) { |
190 | | - $removeRights[] = $right; |
191 | | - } # Otherwise, do nothing. |
192 | | - } |
193 | | - |
194 | | - // Assign the rights. |
195 | | - if (count($addRights)>0) |
196 | | - $this->grantRightsToGroup( $group, $addRights ); |
197 | | - if (count($removeRights)>0) |
198 | | - $this->revokeRightsFromGroup( $group, $removeRights ); |
199 | | - |
200 | | - // Log it |
201 | | - if (!(count($addRights)==0 && count($removeRights)==0)) |
202 | | - $this->addLogEntry( $group, $oldRights, $newRights, $reason ); |
203 | | - |
204 | | - // Display success |
205 | | - $wgOut->setSubTitle( wfMsg( 'centralauth-editgroup-success' ) ); |
206 | | - $wgOut->addWikitext( wfMsg( 'centralauth-editgroup-success-text' ) ); |
207 | | - } |
208 | | - |
209 | | - function revokeRightsFromGroup( $group, $rights ) { |
210 | | - $dbw = CentralAuthUser::getCentralDB(); |
211 | | - |
212 | | - # Delete from the DB |
213 | | - $dbw->delete( 'global_group_permissions', array( 'ggp_group' => $group, 'ggp_permission' => $rights), __METHOD__ ); |
214 | | - } |
215 | | - |
216 | | - function grantRightsToGroup( $group, $rights ) { |
217 | | - $dbw = CentralAuthUser::getCentralDB(); |
218 | | - |
219 | | - if (!is_array($rights)) { |
220 | | - $rights = array($rights); |
221 | | - } |
222 | | - |
223 | | - $insert_rows = array(); |
224 | | - foreach( $rights as $right ) { |
225 | | - $insert_rows[] = array( 'ggp_group' => $group, 'ggp_permission' => $right ); |
226 | | - } |
227 | | - |
228 | | - # Replace into the DB |
229 | | - $dbw->replace( 'global_group_permissions', array( 'ggp_group', 'ggp_permission' ), $insert_rows, __METHOD__ ); |
230 | | - } |
231 | | - |
232 | | - protected function showLogFragment( $group, $output ) { |
233 | | - $title = SpecialPage::getTitleFor( 'ListUsers', $group ); |
234 | | - $output->addHtml( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) ); |
235 | | - LogEventsList::showLogExtract( $output, 'globalrights', $title->getPrefixedText() ); |
236 | | - } |
237 | | - |
238 | | - function addLogEntry( $group, $oldRights, $newRights, $reason ) { |
239 | | - global $wgRequest; |
240 | | - |
241 | | - $log = new LogPage( 'gblrights' ); |
242 | | - |
243 | | - $log->addEntry( 'groupperms', |
244 | | - SpecialPage::getTitleFor( 'ListUsers', $group ), |
245 | | - $reason, |
246 | | - array( |
247 | | - $this->makeRightsList( $oldRights ), |
248 | | - $this->makeRightsList( $newRights ) |
249 | | - ) |
250 | | - ); |
251 | | - } |
252 | | - |
253 | | - function makeRightsList( $ids ) { |
254 | | - return implode( ', ', $ids ); |
255 | | - } |
256 | | -} |
257 | | -<?php |
258 | | - |
259 | | -#This file is part of MediaWiki. |
260 | | - |
261 | | -#MediaWiki is free software: you can redistribute it and/or modify |
262 | | -#it under the terms of version 2 of the GNU General Public License |
263 | | -#as published by the Free Software Foundation. |
264 | | - |
265 | | -#MediaWiki is distributed in the hope that it will be useful, |
266 | | -#but WITHOUT ANY WARRANTY; without even the implied warranty of |
267 | | -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
268 | | -#GNU General Public License for more details. |
269 | | - |
270 | | -/** |
271 | | - * Special page to allow managing global groups |
272 | | - * Prototype for a similar system in core. |
273 | | - * |
274 | | - * @addtogroup Extensions |
275 | | - */ |
276 | | - |
277 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
278 | | - echo "CentralAuth extension\n"; |
279 | | - exit( 1 ); |
280 | | -} |
281 | | - |
282 | | - |
283 | | -class SpecialGlobalGroupPermissions extends SpecialPage |
284 | | -{ |
285 | | - function __construct() { |
286 | | - SpecialPage::SpecialPage('GlobalGroupPermissions', 'globalgrouppermissions'); |
287 | | - wfLoadExtensionMessages('SpecialCentralAuth'); |
288 | | - } |
289 | | - |
290 | | - function userCanExecute($user) { |
291 | | - $globalUser = CentralAuthUser::getInstance( $user ); |
292 | | - |
293 | | - ## Should be a global user |
294 | | - if (!$globalUser->exists() || !$globalUser->isAttached()) { |
295 | | - return false; |
296 | | - } |
297 | | - |
298 | | - ## Permission MUST be gained from global rights. |
299 | | - return $globalUser->hasGlobalPermission( 'globalgrouppermissions' ); |
300 | | - } |
301 | | - |
302 | | - function execute( $subpage ) { |
303 | | - global $wgRequest,$wgOut,$wgUser; |
304 | | - |
305 | | - if (!$this->userCanExecute($wgUser)) { |
306 | | - $this->displayRestrictionError(); |
307 | | - return; |
308 | | - } |
309 | | - |
310 | | - $wgOut->setPageTitle( wfMsg( 'globalgrouppermissions' ) ); |
311 | | - $wgOut->setRobotpolicy( "noindex,nofollow" ); |
312 | | - $wgOut->setArticleRelated( false ); |
313 | | - $wgOut->enableClientCache( false ); |
314 | | - |
315 | | - if ($subpage == '' ) { |
316 | | - $subpage = $wgRequest->getVal( 'wpGroup' ); |
317 | | - } |
318 | | - |
319 | | - if ($subpage != '' && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )) { |
320 | | - $this->doSubmit($subpage); |
321 | | - } else if ($subpage != '') { |
322 | | - $this->buildGroupView($subpage); |
323 | | - } else { |
324 | | - $this->buildMainView(); |
325 | | - } |
326 | | - } |
327 | | - |
328 | | - function buildMainView() { |
329 | | - global $wgOut,$wgUser,$wgInvitationTypes; |
330 | | - $sk = $wgUser->getSkin(); |
331 | | - |
332 | | - $groups = CentralAuthUser::availableGlobalGroups(); |
333 | | - |
334 | | - // Existing groups |
335 | | - $html = Xml::openElement( 'fieldset' ); |
336 | | - $html .= Xml::element( 'legend', null, wfMsg( 'centralauth-existinggroup-legend' ) ); |
337 | | - |
338 | | - $wgOut->addHtml( $html ); |
339 | | - |
340 | | - if (count($groups)) { |
341 | | - $wgOut->addWikitext( wfMsg( 'centralauth-globalgroupperms-grouplist' ) ); |
342 | | - $wgOut->addHTML( '<ul>' ); |
343 | | - |
344 | | - foreach ($groups as $group) { |
345 | | - $text = wfMsgExt( 'centralauth-globalgroupperms-grouplistitem', array( 'parseinline' ), User::getGroupName($group), $group ); |
346 | | - |
347 | | - $wgOut->addHTML( "<li> $text </li>" ); |
348 | | - } |
349 | | - |
350 | | - $wgOut->addHTML( '</ul>' ); |
351 | | - } else { |
352 | | - $wgOut->addWikitext( wfMsg( 'centralauth-globalgroupperms-nogroups' ) ); |
353 | | - } |
354 | | - |
355 | | - $wgOut->addHtml( Xml::closeElement( 'fieldset' ) ); |
356 | | - |
357 | | - // "Create a group" prompt |
358 | | - $html = Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'centralauth-newgroup-legend' ) ); |
359 | | - $html .= wfMsgExt( 'centralauth-newgroup-intro', array( 'parse' ) ); |
360 | | - $html .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'centralauth-globalgroups-newgroup' ) ); |
361 | | - $html .= Xml::hidden( 'title', SpecialPage::getTitleFor('GlobalGroupPermissions')->getPrefixedText() ); |
362 | | - $html .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
363 | | - |
364 | | - $fields = array( 'centralauth-globalgroupperms-newgroupname' => wfInput( 'wpGroup' ) ); |
365 | | - |
366 | | - $html .= wfBuildForm( $fields, 'centralauth-globalgroupperms-creategroup-submit' ); |
367 | | - $html .= Xml::closeElement( 'fieldset' ); |
368 | | - |
369 | | - $wgOut->addHtml( $html ); |
370 | | - } |
371 | | - |
372 | | - function buildGroupView( $group ) { |
373 | | - global $wgOut, $wgUser; |
374 | | - |
375 | | - $wgOut->setSubtitle( wfMsg( 'centralauth-editgroup-subtitle', $group ) ); |
376 | | - |
377 | | - $html = Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'centralauth-editgroup-fieldset', $group ) ); |
378 | | - $html .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'centralauth-globalgroups-newgroup' ) ); |
379 | | - $html .= Xml::hidden( 'title', SpecialPage::getTitleFor('GlobalGroupPermissions')->getPrefixedText() ); |
380 | | - $html .= Xml::hidden( 'wpGroup', $group ); |
381 | | - $html .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
382 | | - |
383 | | - $fields = array(); |
384 | | - |
385 | | - $fields['centralauth-editgroup-name'] = $group; |
386 | | - $fields['centralauth-editgroup-display'] = wfMsgExt( 'centralauth-editgroup-display-edit', array( 'parseinline' ), $group, User::getGroupName( $group ) ); |
387 | | - $fields['centralauth-editgroup-member'] = wfMsgExt( 'centralauth-editgroup-member-edit', array( 'parseinline' ), $group, User::getGroupMember( $group ) ); |
388 | | - $fields['centralauth-editgroup-members'] = wfMsgExt( 'centralauth-editgroup-members-link', array( 'parseinline' ), $group, User::getGroupMember( $group ) ); |
389 | | - $fields['centralauth-editgroup-perms'] = $this->buildCheckboxes($group); |
390 | | - $fields['centralauth-editgroup-reason'] = wfInput( 'wpReason' ); |
391 | | - |
392 | | - $html .= wfBuildForm( $fields, 'centralauth-editgroup-submit' ); |
393 | | - |
394 | | - $html .= Xml::closeElement( 'form' ); |
395 | | - $html .= Xml::closeElement( 'fieldset' ); |
396 | | - |
397 | | - $wgOut->addHtml( $html ); |
398 | | - |
399 | | - $this->showLogFragment( $group, $wgOut ); |
400 | | - } |
401 | | - |
402 | | - function buildCheckboxes( $group ) { |
403 | | - $html = '<ul>'; |
404 | | - |
405 | | - $rights = wfGetAvailableRights(); |
406 | | - $assignedRights = $this->getAssignedRights( $group ); |
407 | | - |
408 | | - foreach( $rights as $right ) { |
409 | | - # Build a checkbox. |
410 | | - $checked = in_array( $right, $assignedRights ); |
411 | | - |
412 | | - $checkbox = wfCheckLabel( wfMsg( "right-$right" ), "wpRightAssigned-$right", "wpRightAssigned-$right", $checked ); |
413 | | - |
414 | | - $html .= "<li>$checkbox</li>"; |
415 | | - } |
416 | | - |
417 | | - $html .= '</ul>'; |
418 | | - |
419 | | - return $html; |
420 | | - } |
421 | | - |
422 | | - function getAssignedRights( $group ) { |
423 | | - return CentralAuthUser::globalGroupPermissions( $group ); |
424 | | - } |
425 | | - |
426 | | - function doSubmit( $group ) { |
427 | | - global $wgRequest,$wgOut; |
428 | | - |
429 | | - $newRights = array(); |
430 | | - $addRights = array(); |
431 | | - $removeRights = array(); |
432 | | - $oldRights = $this->getAssignedRights( $group ); |
433 | | - $allRights = wfGetAvailableRights(); |
434 | | - |
435 | | - $reason = $wgRequest->getVal( 'wpReason', '' ); |
436 | | - |
437 | | - foreach ($allRights as $right) { |
438 | | - $alreadyAssigned = in_array( $right, $oldRights ); |
439 | | - |
440 | | - if ($wgRequest->getCheck( "wpRightAssigned-$right" )) { |
441 | | - $newGroups[] = $right; |
442 | | - } |
443 | | - |
444 | | - if (!$alreadyAssigned && $wgRequest->getCheck( "wpRightAssigned-$right" )) { |
445 | | - $addRights[] = $right; |
446 | | - } else if ($alreadyAssigned && !$wgRequest->getCheck( "wpRightAssigned-$right" ) ) { |
447 | | - $removeRights[] = $right; |
448 | | - } # Otherwise, do nothing. |
449 | | - } |
450 | | - |
451 | | - // Assign the rights. |
452 | | - if (count($addRights)>0) |
453 | | - $this->grantRightsToGroup( $group, $addRights ); |
454 | | - if (count($removeRights)>0) |
455 | | - $this->revokeRightsFromGroup( $group, $removeRights ); |
456 | | - |
457 | | - // Log it |
458 | | - if (!(count($addRights)==0 && count($removeRights)==0)) |
459 | | - $this->addLogEntry( $group, $oldRights, $newRights, $reason ); |
460 | | - |
461 | | - // Display success |
462 | | - $wgOut->setSubTitle( wfMsg( 'centralauth-editgroup-success' ) ); |
463 | | - $wgOut->addWikitext( wfMsg( 'centralauth-editgroup-success-text' ) ); |
464 | | - } |
465 | | - |
466 | | - function revokeRightsFromGroup( $group, $rights ) { |
467 | | - $dbw = CentralAuthUser::getCentralDB(); |
468 | | - |
469 | | - # Delete from the DB |
470 | | - $dbw->delete( 'global_group_permissions', array( 'ggp_group' => $group, 'ggp_permission' => $rights), __METHOD__ ); |
471 | | - } |
472 | | - |
473 | | - function grantRightsToGroup( $group, $rights ) { |
474 | | - $dbw = CentralAuthUser::getCentralDB(); |
475 | | - |
476 | | - if (!is_array($rights)) { |
477 | | - $rights = array($rights); |
478 | | - } |
479 | | - |
480 | | - $insert_rows = array(); |
481 | | - foreach( $rights as $right ) { |
482 | | - $insert_rows[] = array( 'ggp_group' => $group, 'ggp_permission' => $right ); |
483 | | - } |
484 | | - |
485 | | - # Replace into the DB |
486 | | - $dbw->replace( 'global_group_permissions', array( 'ggp_group', 'ggp_permission' ), $insert_rows, __METHOD__ ); |
487 | | - } |
488 | | - |
489 | | - protected function showLogFragment( $group, $output ) { |
490 | | - $title = SpecialPage::getTitleFor( 'ListUsers', $group ); |
491 | | - $output->addHtml( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) ); |
492 | | - LogEventsList::showLogExtract( $output, 'globalrights', $title->getPrefixedText() ); |
493 | | - } |
494 | | - |
495 | | - function addLogEntry( $group, $oldRights, $newRights, $reason ) { |
496 | | - global $wgRequest; |
497 | | - |
498 | | - $log = new LogPage( 'gblrights' ); |
499 | | - |
500 | | - $log->addEntry( 'groupperms', |
501 | | - SpecialPage::getTitleFor( 'ListUsers', $group ), |
502 | | - $reason, |
503 | | - array( |
504 | | - $this->makeRightsList( $oldRights ), |
505 | | - $this->makeRightsList( $newRights ) |
506 | | - ) |
507 | | - ); |
508 | | - } |
509 | | - |
510 | | - function makeRightsList( $ids ) { |
511 | | - return implode( ', ', $ids ); |
512 | | - } |
513 | | -} |
\ No newline at end of file |