r94045 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94044‎ | r94045 | r94046 >
Date:14:41, 7 August 2011
Author:ialex
Status:ok
Tags:
Comment:
Use local context instead of global variables
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUserrights.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUserrights.php
@@ -63,24 +63,26 @@
6464 public function execute( $par ) {
6565 // If the visitor doesn't have permissions to assign or remove
6666 // any groups, it's a bit silly to give them the user search prompt.
67 - global $wgUser, $wgRequest, $wgOut;
6867
69 - if( $par !== null ) {
70 - $this->mTarget = $par;
71 - } else {
72 - $this->mTarget = $wgRequest->getVal( 'user' );
73 - }
 68+ $user = $this->getUser();
7469
7570 /*
7671 * If the user is blocked and they only have "partial" access
7772 * (e.g. they don't have the userrights permission), then don't
7873 * allow them to use Special:UserRights.
7974 */
80 - if( $wgUser->isBlocked() && !$wgUser->isAllowed( 'userrights' ) ) {
81 - $wgOut->blockedPage();
82 - return;
 75+ if( $user->isBlocked() && !$user->isAllowed( 'userrights' ) ) {
 76+ throw new UserBlockedError( $user->mBlock );
8377 }
8478
 79+ $request = $this->getRequest();
 80+
 81+ if( $par !== null ) {
 82+ $this->mTarget = $par;
 83+ } else {
 84+ $this->mTarget = $request->getVal( 'user' );
 85+ }
 86+
8587 $available = $this->changeableGroups();
8688
8789 if ( $this->mTarget === null ) {
@@ -90,29 +92,30 @@
9193 * target.
9294 */
9395 if ( !count( $available['add'] ) && !count( $available['remove'] ) )
94 - $this->mTarget = $wgUser->getName();
 96+ $this->mTarget = $user->getName();
9597 }
9698
97 - if ( User::getCanonicalName( $this->mTarget ) == $wgUser->getName() ) {
 99+ if ( User::getCanonicalName( $this->mTarget ) == $user->getName() ) {
98100 $this->isself = true;
99101 }
100102
101 - if( !$this->userCanChangeRights( $wgUser, true ) ) {
 103+ $out = $this->getOutput();
 104+
 105+ if( !$this->userCanChangeRights( $user, true ) ) {
102106 // @todo FIXME: There may be intermediate groups we can mention.
103 - $wgOut->showPermissionsErrorPage( array( array(
104 - $wgUser->isAnon()
 107+ $out->showPermissionsErrorPage( array( array(
 108+ $user->isAnon()
105109 ? 'userrights-nologin'
106110 : 'userrights-notallowed' ) ) );
107111 return;
108112 }
109113
110114 if ( wfReadOnly() ) {
111 - $wgOut->readOnlyPage();
112 - return;
 115+ throw new ReadOnlyError;
113116 }
114117
115118 $this->outputHeader();
116 - $wgOut->addModuleStyles( 'mediawiki.special' );
 119+ $out->addModuleStyles( 'mediawiki.special' );
117120 $this->setHeaders();
118121
119122 // show the general form
@@ -120,19 +123,18 @@
121124 $this->switchForm();
122125 }
123126
124 - if( $wgRequest->wasPosted() ) {
 127+ if( $request->wasPosted() ) {
125128 // save settings
126 - if( $wgRequest->getCheck( 'saveusergroups' ) ) {
127 - $reason = $wgRequest->getVal( 'user-reason' );
128 - $tok = $wgRequest->getVal( 'wpEditToken' );
129 - if( $wgUser->matchEditToken( $tok, $this->mTarget ) ) {
 129+ if( $request->getCheck( 'saveusergroups' ) ) {
 130+ $reason = $request->getVal( 'user-reason' );
 131+ $tok = $request->getVal( 'wpEditToken' );
 132+ if( $user->matchEditToken( $tok, $this->mTarget ) ) {
130133 $this->saveUserGroups(
131134 $this->mTarget,
132135 $reason
133136 );
134137
135 - $url = $this->getSuccessURL();
136 - $wgOut->redirect( $url );
 138+ $out->redirect( $this->getSuccessURL() );
137139 return;
138140 }
139141 }
@@ -157,11 +159,9 @@
158160 * @return null
159161 */
160162 function saveUserGroups( $username, $reason = '' ) {
161 - global $wgRequest, $wgOut;
162 -
163163 $status = $this->fetchUser( $username );
164164 if( !$status->isOK() ) {
165 - $wgOut->addWikiText( $status->getWikiText() );
 165+ $this->getOutput()->addWikiText( $status->getWikiText() );
166166 return;
167167 } else {
168168 $user = $status->value;
@@ -176,7 +176,7 @@
177177 foreach ( $allgroups as $group ) {
178178 // We'll tell it to remove all unchecked groups, and add all checked groups.
179179 // Later on, this gets filtered for what can actually be removed
180 - if ( $wgRequest->getCheck( "wpGroup-$group" ) ) {
 180+ if ( $this->getRequest()->getCheck( "wpGroup-$group" ) ) {
181181 $addgroup[] = $group;
182182 } else {
183183 $removegroup[] = $group;
@@ -196,10 +196,8 @@
197197 * @return Array: Tuple of added, then removed groups
198198 */
199199 function doSaveUserGroups( $user, $add, $remove, $reason = '' ) {
200 - global $wgUser;
201 -
202200 // Validate input set...
203 - $isself = ( $user->getName() == $wgUser->getName() );
 201+ $isself = ( $user->getName() == $this->getUser()->getName() );
204202 $groups = $user->getGroups();
205203 $changeable = $this->changeableGroups();
206204 $addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : array() );
@@ -265,11 +263,9 @@
266264 * @param $username String: name of the user.
267265 */
268266 function editUserGroupsForm( $username ) {
269 - global $wgOut;
270 -
271267 $status = $this->fetchUser( $username );
272268 if( !$status->isOK() ) {
273 - $wgOut->addWikiText( $status->getWikiText() );
 269+ $this->getOutput()->addWikiText( $status->getWikiText() );
274270 return;
275271 } else {
276272 $user = $status->value;
@@ -281,7 +277,7 @@
282278
283279 // This isn't really ideal logging behavior, but let's not hide the
284280 // interwiki logs if we're using them as is.
285 - $this->showLogFragment( $user, $wgOut );
 281+ $this->showLogFragment( $user, $this->getOutput() );
286282 }
287283
288284 /**
@@ -292,7 +288,7 @@
293289 * @return Status object
294290 */
295291 public function fetchUser( $username ) {
296 - global $wgUser, $wgUserrightsInterwikiDelimiter;
 292+ global $wgUserrightsInterwikiDelimiter;
297293
298294 $parts = explode( $wgUserrightsInterwikiDelimiter, $username );
299295 if( count( $parts ) < 2 ) {
@@ -304,7 +300,7 @@
305301 if( $database == wfWikiID() ) {
306302 $database = '';
307303 } else {
308 - if( !$wgUser->isAllowed( 'userrights-interwiki' ) ) {
 304+ if( !$this->getUser()->isAllowed( 'userrights-interwiki' ) ) {
309305 return Status::newFatal( 'userrights-no-interwiki' );
310306 }
311307 if( !UserRightsProxy::validDatabase( $database ) ) {
@@ -372,8 +368,8 @@
373369 * Output a form to allow searching for a user
374370 */
375371 function switchForm() {
376 - global $wgOut, $wgScript;
377 - $wgOut->addHTML(
 372+ global $wgScript;
 373+ $this->getOutput()->addHTML(
378374 Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'name' => 'uluser', 'id' => 'mw-userrights-form1' ) ) .
379375 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
380376 Xml::fieldset( wfMsg( 'userrights-lookup-user' ) ) .
@@ -414,8 +410,6 @@
415411 * @param $groups Array: Array of groups the user is in
416412 */
417413 protected function showEditUserGroupsForm( $user, $groups ) {
418 - global $wgOut, $wgUser, $wgLang, $wgRequest;
419 -
420414 $list = array();
421415 foreach( $groups as $group ) {
422416 $list[] = self::buildGroupLink( $group );
@@ -432,17 +426,17 @@
433427 $count = count( $list );
434428 if( $count > 0 ) {
435429 $grouplist = wfMessage( 'userrights-groupsmember', $count)->parse();
436 - $grouplist = '<p>' . $grouplist . ' ' . $wgLang->listToText( $list ) . "</p>\n";
 430+ $grouplist = '<p>' . $grouplist . ' ' . $this->getLang()->listToText( $list ) . "</p>\n";
437431 }
438432 $count = count( $autolist );
439433 if( $count > 0 ) {
440434 $autogrouplistintro = wfMessage( 'userrights-groupsmember-auto', $count)->parse();
441 - $grouplist .= '<p>' . $autogrouplistintro . ' ' . $wgLang->listToText( $autolist ) . "</p>\n";
 435+ $grouplist .= '<p>' . $autogrouplistintro . ' ' . $this->getLang()->listToText( $autolist ) . "</p>\n";
442436 }
443 - $wgOut->addHTML(
 437+ $this->getOutput()->addHTML(
444438 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalURL(), 'name' => 'editGroup', 'id' => 'mw-userrights-form2' ) ) .
445439 Html::hidden( 'user', $this->mTarget ) .
446 - Html::hidden( 'wpEditToken', $wgUser->editToken( $this->mTarget ) ) .
 440+ Html::hidden( 'wpEditToken', $this->getUser()->editToken( $this->mTarget ) ) .
447441 Xml::openElement( 'fieldset' ) .
448442 Xml::element( 'legend', array(), wfMsg( 'userrights-editusergroup' ) ) .
449443 wfMsgExt( 'editinguser', array( 'parse' ), wfEscapeWikiText( $user->getName() ) ) .
@@ -455,7 +449,7 @@
456450 Xml::label( wfMsg( 'userrights-reason' ), 'wpReason' ) .
457451 "</td>
458452 <td class='mw-input'>" .
459 - Xml::input( 'user-reason', 60, $wgRequest->getVal( 'user-reason', false ),
 453+ Xml::input( 'user-reason', 60, $this->getRequest()->getVal( 'user-reason', false ),
460454 array( 'id' => 'wpReason', 'maxlength' => 255 ) ) .
461455 "</td>
462456 </tr>
@@ -588,13 +582,12 @@
589583 }
590584
591585 /**
592 - * Returns $wgUser->changeableGroups()
 586+ * Returns $this->getUser()->changeableGroups()
593587 *
594588 * @return Array array( 'add' => array( addablegroups ), 'remove' => array( removablegroups ) , 'add-self' => array( addablegroups to self), 'remove-self' => array( removable groups from self) )
595589 */
596590 function changeableGroups() {
597 - global $wgUser;
598 - return $wgUser->changeableGroups();
 591+ return $this->getUser()->changeableGroups();
599592 }
600593
601594 /**

Status & tagging log