r61602 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61601‎ | r61602 | r61603 >
Date:20:41, 27 January 2010
Author:ialex
Status:ok
Tags:
Comment:
Coding style fixes only: ran stylize.php, removed trailing whitespaces, etc.
Modified paths:
  • /trunk/extensions/CentralAuth/SpecialGlobalGroupPermissions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/SpecialGlobalGroupPermissions.php
@@ -1,15 +1,15 @@
22 <?php
33
4 -#This file is part of MediaWiki.
 4+# This file is part of MediaWiki.
55
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.
99
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.
1414
1515 /**
1616 * Special page to allow managing global groups
@@ -24,53 +24,53 @@
2525 }
2626
2727
28 -class SpecialGlobalGroupPermissions extends SpecialPage
29 -{
 28+class SpecialGlobalGroupPermissions extends SpecialPage {
3029 function __construct() {
3130 parent::__construct( 'GlobalGroupPermissions' );
32 - wfLoadExtensionMessages('SpecialCentralAuth');
 31+ wfLoadExtensionMessages( 'SpecialCentralAuth' );
3332 }
34 -
35 - function userCanEdit($user) {
 33+
 34+ function userCanEdit( $user ) {
3635 $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() ) {
4039 return false;
4140 }
42 -
43 - ## Permission MUST be gained from global rights.
 41+
 42+ # # Permission MUST be gained from global rights.
4443 return $globalUser->hasGlobalPermission( 'globalgrouppermissions' );
4544 }
4645
4746 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 ) ) {
5150 $this->displayRestrictionError();
5251 return;
5352 }
54 -
 53+
5554 $wgOut->setPageTitle( wfMsg( 'globalgrouppermissions' ) );
5655 $wgOut->setRobotPolicy( "noindex,nofollow" );
5756 $wgOut->setArticleRelated( false );
5857 $wgOut->enableClientCache( false );
59 -
60 - if ($subpage == '' ) {
 58+
 59+ if ( $subpage == '' ) {
6160 $subpage = $wgRequest->getVal( 'wpGroup' );
6261 }
6362
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 );
6867 } else {
6968 $this->buildMainView();
7069 }
7170 }
7271
7372 function buildMainView() {
74 - global $wgOut,$wgUser,$wgScript;
 73+ global $wgOut, $wgUser, $wgScript;
 74+
7575 $sk = $wgUser->getSkin();
7676
7777 $groups = CentralAuthUser::availableGlobalGroups();
@@ -80,12 +80,12 @@
8181
8282 $wgOut->addHTML( $html );
8383
84 - if (count($groups)) {
 84+ if ( count( $groups ) ) {
8585 $wgOut->addWikiMsg( 'centralauth-globalgroupperms-grouplist' );
8686 $wgOut->addHTML( '<ul>' );
8787
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 );
9090
9191 $wgOut->addHTML( "<li> $text </li>" );
9292 }
@@ -100,18 +100,18 @@
101101 $html = Xml::fieldset( wfMsg( 'centralauth-newgroup-legend' ) );
102102 $html .= wfMsgExt( 'centralauth-newgroup-intro', array( 'parse' ) );
103103 $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+
106106 $fields = array( 'centralauth-globalgroupperms-newgroupname' => Xml::input( 'wpGroup' ) );
107 -
 107+
108108 $html .= Xml::buildForm( $fields, 'centralauth-globalgroupperms-creategroup-submit' );
109109 $html .= Xml::closeElement( 'form' );
110110 $html .= Xml::closeElement( 'fieldset' );
111 -
 111+
112112 $wgOut->addHTML( $html );
113113 }
114114 }
115 -
 115+
116116 function buildGroupView( $group ) {
117117 global $wgOut, $wgUser, $wgScript;
118118
@@ -122,47 +122,47 @@
123123 $html = Xml::fieldset( wfMsg( 'centralauth-editgroup-fieldset', $group ) );
124124
125125 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' ) );
127127 $html .= Xml::hidden( 'wpGroup', $group );
128128 $html .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
129129 }
130 -
 130+
131131 $fields = array();
132 -
 132+
133133 $fields['centralauth-editgroup-name'] = $group;
134134 $fields['centralauth-editgroup-display'] = wfMsgExt( 'centralauth-editgroup-display-edit', array( 'parseinline' ), $group, User::getGroupName( $group ) );
135135 $fields['centralauth-editgroup-member'] = wfMsgExt( 'centralauth-editgroup-member-edit', array( 'parseinline' ), $group, User::getGroupMember( $group ) );
136136 $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+
140140 if ( $editable ) {
141141 $fields['centralauth-editgroup-reason'] = Xml::input( 'wpReason', 60 );
142142 }
143 -
 143+
144144 $html .= Xml::buildForm( $fields, $editable ? 'centralauth-editgroup-submit' : null );
145 -
146 - if ($editable)
 145+
 146+ if ( $editable )
147147 $html .= Xml::closeElement( 'form' );
148 -
 148+
149149 $html .= Xml::closeElement( 'fieldset' );
150 -
 150+
151151 $wgOut->addHTML( $html );
152 -
 152+
153153 $this->showLogFragment( $group, $wgOut );
154154 }
155155
156156 function buildWikiSetSelector( $group ) {
157157 $sets = WikiSet::getAllWikiSets();
158158 $default = WikiSet::getWikiSetForGroup( $group );
159 -
 159+
160160 global $wgUser;
161161 if ( !$this->userCanEdit( $wgUser ) )
162162 return htmlspecialchars( $default );
163163
164164 $select = new XmlSelect( 'set', 'wikiset', $default );
165165 $select->addOption( wfMsg( 'centralauth-editgroup-noset' ), '0' );
166 - foreach( $sets as $set ) {
 166+ foreach ( $sets as $set ) {
167167 $select->addOption( $set->getName(), $set->getID() );
168168 }
169169
@@ -171,22 +171,22 @@
172172 }
173173
174174 function buildCheckboxes( $group ) {
175 -
176175 global $wgUser, $wgOut;
 176+
177177 $editable = $this->userCanEdit( $wgUser );
178 -
 178+
179179 $rights = User::getAllRights();
180180 $assignedRights = $this->getAssignedRights( $group );
181 -
182 - sort($rights);
183 -
 181+
 182+ sort( $rights );
 183+
184184 $checkboxes = array();
185185 $attribs = array();
186 -
187 - if (!$editable)
 186+
 187+ if ( !$editable )
188188 $attribs['disabled'] = 'disabled';
189 -
190 - foreach( $rights as $right ) {
 189+
 190+ foreach ( $rights as $right ) {
191191 # Build a checkbox.
192192 $checked = in_array( $right, $assignedRights );
193193
@@ -196,124 +196,124 @@
197197 $checkbox = Xml::check( "wpRightAssigned-$right", $checked, $attribs );
198198 $label = Xml::tags( 'label', array( 'for' => "wpRightAssigned-$right" ),
199199 $desc );
200 -
 200+
201201 $checkboxes[] = "<li>$checkbox&nbsp;$label</li>";
202202 }
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+
211211 $html = '<table><tbody><tr><td><ul>';
212 -
213 - foreach( $checkboxes1 as $cb ) {
 212+
 213+ foreach ( $checkboxes1 as $cb ) {
214214 $html .= $cb;
215215 }
216 -
 216+
217217 $html .= '</ul></td><td><ul>';
218 -
219 - foreach( $checkboxes2 as $cb ) {
 218+
 219+ foreach ( $checkboxes2 as $cb ) {
220220 $html .= $cb;
221221 }
222 -
 222+
223223 $html .= '</ul></td></tr></tbody></table>';
224 -
 224+
225225 return $html;
226226 }
227 -
 227+
228228 function getAssignedRights( $group ) {
229229 return CentralAuthUser::globalGroupPermissions( $group );
230230 }
231 -
 231+
232232 function doSubmit( $group ) {
233 - global $wgRequest,$wgOut,$wgScript,$wgUser;
234 -
 233+ global $wgRequest, $wgOut, $wgScript, $wgUser;
 234+
235235 // Paranoia -- the edit token shouldn't match anyway
236 - if (!$this->userCanEdit( $wgUser ))
 236+ if ( !$this->userCanEdit( $wgUser ) )
237237 return;
238 -
 238+
239239 $newRights = array();
240240 $addRights = array();
241241 $removeRights = array();
242242 $oldRights = $this->getAssignedRights( $group );
243243 $allRights = User::getAllRights();
244 -
 244+
245245 $reason = $wgRequest->getVal( 'wpReason', '' );
246 -
247 - foreach ($allRights as $right) {
 246+
 247+ foreach ( $allRights as $right ) {
248248 $alreadyAssigned = in_array( $right, $oldRights );
249 -
250 - if ($wgRequest->getCheck( "wpRightAssigned-$right" )) {
 249+
 250+ if ( $wgRequest->getCheck( "wpRightAssigned-$right" ) ) {
251251 $newRights[] = $right;
252252 }
253 -
254 - if (!$alreadyAssigned && $wgRequest->getCheck( "wpRightAssigned-$right" )) {
 253+
 254+ if ( !$alreadyAssigned && $wgRequest->getCheck( "wpRightAssigned-$right" ) ) {
255255 $addRights[] = $right;
256 - } else if ($alreadyAssigned && !$wgRequest->getCheck( "wpRightAssigned-$right" ) ) {
 256+ } else if ( $alreadyAssigned && !$wgRequest->getCheck( "wpRightAssigned-$right" ) ) {
257257 $removeRights[] = $right;
258258 } # Otherwise, do nothing.
259259 }
260 -
 260+
261261 // Assign the rights.
262 - if (count($addRights)>0)
 262+ if ( count( $addRights ) > 0 )
263263 $this->grantRightsToGroup( $group, $addRights );
264 - if (count($removeRights)>0)
 264+ if ( count( $removeRights ) > 0 )
265265 $this->revokeRightsFromGroup( $group, $removeRights );
266 -
 266+
267267 // Log it
268 - if (!(count($addRights)==0 && count($removeRights)==0))
 268+ if ( !( count( $addRights ) == 0 && count( $removeRights ) == 0 ) )
269269 $this->addLogEntry( $group, $addRights, $removeRights, $reason );
270270
271271 // Change set
272272 $current = WikiSet::getWikiSetForGroup( $group );
273273 $new = $wgRequest->getVal( 'set' );
274 - if( $current != $new ) {
 274+ if ( $current != $new ) {
275275 $this->setRestrictions( $group, $new );
276276 $this->addLogEntry2( $group, $current, $new, $reason );
277277 }
278278
279279 $this->invalidateRightsCache( $group );
280 -
 280+
281281 // Display success
282282 $wgOut->setSubTitle( wfMsg( 'centralauth-editgroup-success' ) );
283283 $wgOut->addWikiMsg( 'centralauth-editgroup-success-text', $group );
284284 }
285 -
 285+
286286 function revokeRightsFromGroup( $group, $rights ) {
287287 $dbw = CentralAuthUser::getCentralDB();
288 -
 288+
289289 # 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__ );
291291 }
292 -
 292+
293293 function grantRightsToGroup( $group, $rights ) {
294294 $dbw = CentralAuthUser::getCentralDB();
295 -
296 - if (!is_array($rights)) {
297 - $rights = array($rights);
 295+
 296+ if ( !is_array( $rights ) ) {
 297+ $rights = array( $rights );
298298 }
299 -
 299+
300300 $insertRows = array();
301 - foreach( $rights as $right ) {
 301+ foreach ( $rights as $right ) {
302302 $insertRows[] = array( 'ggp_group' => $group, 'ggp_permission' => $right );
303303 }
304 -
 304+
305305 # Replace into the DB
306306 $dbw->replace( 'global_group_permissions', array( 'ggp_group', 'ggp_permission' ), $insertRows, __METHOD__ );
307307 }
308 -
 308+
309309 protected function showLogFragment( $group, $output ) {
310310 $title = SpecialPage::getTitleFor( 'GlobalUsers', $group );
311311 $output->addHTML( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) );
312312 LogEventsList::showLogExtract( $output, 'gblrights', $title->getPrefixedText() );
313313 }
314 -
 314+
315315 function addLogEntry( $group, $addRights, $removeRights, $reason ) {
316316 global $wgRequest;
317 -
 317+
318318 $log = new LogPage( 'gblrights' );
319319
320320 $log->addEntry( 'groupprms2',
@@ -325,14 +325,14 @@
326326 )
327327 );
328328 }
329 -
 329+
330330 function makeRightsList( $ids ) {
331 - return (bool)count($ids) ? implode( ', ', $ids ) : wfMsgForContent( 'rightsnone' );
 331+ return (bool)count( $ids ) ? implode( ', ', $ids ) : wfMsgForContent( 'rightsnone' );
332332 }
333333
334334 function setRestrictions( $group, $set ) {
335335 $dbw = CentralAuthUser::getCentralDB();
336 - if( $set == 0 ) {
 336+ if ( $set == 0 ) {
337337 $dbw->delete( 'global_group_restrictions', array( 'ggr_group' => $group ), __METHOD__ );
338338 } else {
339339 $dbw->replace( 'global_group_restrictions', array( 'ggr_group' ),
@@ -343,7 +343,7 @@
344344
345345 function addLogEntry2( $group, $old, $new, $reason ) {
346346 global $wgRequest;
347 -
 347+
348348 $log = new LogPage( 'gblrights' );
349349
350350 $log->addEntry( 'groupprms3',
@@ -357,7 +357,7 @@
358358 }
359359
360360 function getWikiSetName( $id ) {
361 - if( $id )
 361+ if ( $id )
362362 return WikiSet::newFromID( $id )->getName();
363363 else
364364 return wfMsgForContent( 'centralauth-editgroup-noset' );
@@ -365,14 +365,14 @@
366366
367367 function invalidateRightsCache( $group ) {
368368 global $wgMemc;
369 -
 369+
370370 // Figure out all the users in this group.
371371 $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+
375375 // Invalidate their rights cache.
376 - while ($row = $res->fetchObject() ) {
 376+ while ( $row = $res->fetchObject() ) {
377377 $cu = new CentralAuthUser( $row->gu_name );
378378 $cu->quickInvalidateCache();
379379 }

Status & tagging log