Index: trunk/phase3/includes/specials/SpecialUserrights.php |
— | — | @@ -63,24 +63,26 @@ |
64 | 64 | public function execute( $par ) { |
65 | 65 | // If the visitor doesn't have permissions to assign or remove |
66 | 66 | // any groups, it's a bit silly to give them the user search prompt. |
67 | | - global $wgUser, $wgRequest, $wgOut; |
68 | 67 | |
69 | | - if( $par !== null ) { |
70 | | - $this->mTarget = $par; |
71 | | - } else { |
72 | | - $this->mTarget = $wgRequest->getVal( 'user' ); |
73 | | - } |
| 68 | + $user = $this->getUser(); |
74 | 69 | |
75 | 70 | /* |
76 | 71 | * If the user is blocked and they only have "partial" access |
77 | 72 | * (e.g. they don't have the userrights permission), then don't |
78 | 73 | * allow them to use Special:UserRights. |
79 | 74 | */ |
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 ); |
83 | 77 | } |
84 | 78 | |
| 79 | + $request = $this->getRequest(); |
| 80 | + |
| 81 | + if( $par !== null ) { |
| 82 | + $this->mTarget = $par; |
| 83 | + } else { |
| 84 | + $this->mTarget = $request->getVal( 'user' ); |
| 85 | + } |
| 86 | + |
85 | 87 | $available = $this->changeableGroups(); |
86 | 88 | |
87 | 89 | if ( $this->mTarget === null ) { |
— | — | @@ -90,29 +92,30 @@ |
91 | 93 | * target. |
92 | 94 | */ |
93 | 95 | if ( !count( $available['add'] ) && !count( $available['remove'] ) ) |
94 | | - $this->mTarget = $wgUser->getName(); |
| 96 | + $this->mTarget = $user->getName(); |
95 | 97 | } |
96 | 98 | |
97 | | - if ( User::getCanonicalName( $this->mTarget ) == $wgUser->getName() ) { |
| 99 | + if ( User::getCanonicalName( $this->mTarget ) == $user->getName() ) { |
98 | 100 | $this->isself = true; |
99 | 101 | } |
100 | 102 | |
101 | | - if( !$this->userCanChangeRights( $wgUser, true ) ) { |
| 103 | + $out = $this->getOutput(); |
| 104 | + |
| 105 | + if( !$this->userCanChangeRights( $user, true ) ) { |
102 | 106 | // @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() |
105 | 109 | ? 'userrights-nologin' |
106 | 110 | : 'userrights-notallowed' ) ) ); |
107 | 111 | return; |
108 | 112 | } |
109 | 113 | |
110 | 114 | if ( wfReadOnly() ) { |
111 | | - $wgOut->readOnlyPage(); |
112 | | - return; |
| 115 | + throw new ReadOnlyError; |
113 | 116 | } |
114 | 117 | |
115 | 118 | $this->outputHeader(); |
116 | | - $wgOut->addModuleStyles( 'mediawiki.special' ); |
| 119 | + $out->addModuleStyles( 'mediawiki.special' ); |
117 | 120 | $this->setHeaders(); |
118 | 121 | |
119 | 122 | // show the general form |
— | — | @@ -120,19 +123,18 @@ |
121 | 124 | $this->switchForm(); |
122 | 125 | } |
123 | 126 | |
124 | | - if( $wgRequest->wasPosted() ) { |
| 127 | + if( $request->wasPosted() ) { |
125 | 128 | // 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 ) ) { |
130 | 133 | $this->saveUserGroups( |
131 | 134 | $this->mTarget, |
132 | 135 | $reason |
133 | 136 | ); |
134 | 137 | |
135 | | - $url = $this->getSuccessURL(); |
136 | | - $wgOut->redirect( $url ); |
| 138 | + $out->redirect( $this->getSuccessURL() ); |
137 | 139 | return; |
138 | 140 | } |
139 | 141 | } |
— | — | @@ -157,11 +159,9 @@ |
158 | 160 | * @return null |
159 | 161 | */ |
160 | 162 | function saveUserGroups( $username, $reason = '' ) { |
161 | | - global $wgRequest, $wgOut; |
162 | | - |
163 | 163 | $status = $this->fetchUser( $username ); |
164 | 164 | if( !$status->isOK() ) { |
165 | | - $wgOut->addWikiText( $status->getWikiText() ); |
| 165 | + $this->getOutput()->addWikiText( $status->getWikiText() ); |
166 | 166 | return; |
167 | 167 | } else { |
168 | 168 | $user = $status->value; |
— | — | @@ -176,7 +176,7 @@ |
177 | 177 | foreach ( $allgroups as $group ) { |
178 | 178 | // We'll tell it to remove all unchecked groups, and add all checked groups. |
179 | 179 | // Later on, this gets filtered for what can actually be removed |
180 | | - if ( $wgRequest->getCheck( "wpGroup-$group" ) ) { |
| 180 | + if ( $this->getRequest()->getCheck( "wpGroup-$group" ) ) { |
181 | 181 | $addgroup[] = $group; |
182 | 182 | } else { |
183 | 183 | $removegroup[] = $group; |
— | — | @@ -196,10 +196,8 @@ |
197 | 197 | * @return Array: Tuple of added, then removed groups |
198 | 198 | */ |
199 | 199 | function doSaveUserGroups( $user, $add, $remove, $reason = '' ) { |
200 | | - global $wgUser; |
201 | | - |
202 | 200 | // Validate input set... |
203 | | - $isself = ( $user->getName() == $wgUser->getName() ); |
| 201 | + $isself = ( $user->getName() == $this->getUser()->getName() ); |
204 | 202 | $groups = $user->getGroups(); |
205 | 203 | $changeable = $this->changeableGroups(); |
206 | 204 | $addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : array() ); |
— | — | @@ -265,11 +263,9 @@ |
266 | 264 | * @param $username String: name of the user. |
267 | 265 | */ |
268 | 266 | function editUserGroupsForm( $username ) { |
269 | | - global $wgOut; |
270 | | - |
271 | 267 | $status = $this->fetchUser( $username ); |
272 | 268 | if( !$status->isOK() ) { |
273 | | - $wgOut->addWikiText( $status->getWikiText() ); |
| 269 | + $this->getOutput()->addWikiText( $status->getWikiText() ); |
274 | 270 | return; |
275 | 271 | } else { |
276 | 272 | $user = $status->value; |
— | — | @@ -281,7 +277,7 @@ |
282 | 278 | |
283 | 279 | // This isn't really ideal logging behavior, but let's not hide the |
284 | 280 | // interwiki logs if we're using them as is. |
285 | | - $this->showLogFragment( $user, $wgOut ); |
| 281 | + $this->showLogFragment( $user, $this->getOutput() ); |
286 | 282 | } |
287 | 283 | |
288 | 284 | /** |
— | — | @@ -292,7 +288,7 @@ |
293 | 289 | * @return Status object |
294 | 290 | */ |
295 | 291 | public function fetchUser( $username ) { |
296 | | - global $wgUser, $wgUserrightsInterwikiDelimiter; |
| 292 | + global $wgUserrightsInterwikiDelimiter; |
297 | 293 | |
298 | 294 | $parts = explode( $wgUserrightsInterwikiDelimiter, $username ); |
299 | 295 | if( count( $parts ) < 2 ) { |
— | — | @@ -304,7 +300,7 @@ |
305 | 301 | if( $database == wfWikiID() ) { |
306 | 302 | $database = ''; |
307 | 303 | } else { |
308 | | - if( !$wgUser->isAllowed( 'userrights-interwiki' ) ) { |
| 304 | + if( !$this->getUser()->isAllowed( 'userrights-interwiki' ) ) { |
309 | 305 | return Status::newFatal( 'userrights-no-interwiki' ); |
310 | 306 | } |
311 | 307 | if( !UserRightsProxy::validDatabase( $database ) ) { |
— | — | @@ -372,8 +368,8 @@ |
373 | 369 | * Output a form to allow searching for a user |
374 | 370 | */ |
375 | 371 | function switchForm() { |
376 | | - global $wgOut, $wgScript; |
377 | | - $wgOut->addHTML( |
| 372 | + global $wgScript; |
| 373 | + $this->getOutput()->addHTML( |
378 | 374 | Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'name' => 'uluser', 'id' => 'mw-userrights-form1' ) ) . |
379 | 375 | Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . |
380 | 376 | Xml::fieldset( wfMsg( 'userrights-lookup-user' ) ) . |
— | — | @@ -414,8 +410,6 @@ |
415 | 411 | * @param $groups Array: Array of groups the user is in |
416 | 412 | */ |
417 | 413 | protected function showEditUserGroupsForm( $user, $groups ) { |
418 | | - global $wgOut, $wgUser, $wgLang, $wgRequest; |
419 | | - |
420 | 414 | $list = array(); |
421 | 415 | foreach( $groups as $group ) { |
422 | 416 | $list[] = self::buildGroupLink( $group ); |
— | — | @@ -432,17 +426,17 @@ |
433 | 427 | $count = count( $list ); |
434 | 428 | if( $count > 0 ) { |
435 | 429 | $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"; |
437 | 431 | } |
438 | 432 | $count = count( $autolist ); |
439 | 433 | if( $count > 0 ) { |
440 | 434 | $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"; |
442 | 436 | } |
443 | | - $wgOut->addHTML( |
| 437 | + $this->getOutput()->addHTML( |
444 | 438 | Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalURL(), 'name' => 'editGroup', 'id' => 'mw-userrights-form2' ) ) . |
445 | 439 | Html::hidden( 'user', $this->mTarget ) . |
446 | | - Html::hidden( 'wpEditToken', $wgUser->editToken( $this->mTarget ) ) . |
| 440 | + Html::hidden( 'wpEditToken', $this->getUser()->editToken( $this->mTarget ) ) . |
447 | 441 | Xml::openElement( 'fieldset' ) . |
448 | 442 | Xml::element( 'legend', array(), wfMsg( 'userrights-editusergroup' ) ) . |
449 | 443 | wfMsgExt( 'editinguser', array( 'parse' ), wfEscapeWikiText( $user->getName() ) ) . |
— | — | @@ -455,7 +449,7 @@ |
456 | 450 | Xml::label( wfMsg( 'userrights-reason' ), 'wpReason' ) . |
457 | 451 | "</td> |
458 | 452 | <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 ), |
460 | 454 | array( 'id' => 'wpReason', 'maxlength' => 255 ) ) . |
461 | 455 | "</td> |
462 | 456 | </tr> |
— | — | @@ -588,13 +582,12 @@ |
589 | 583 | } |
590 | 584 | |
591 | 585 | /** |
592 | | - * Returns $wgUser->changeableGroups() |
| 586 | + * Returns $this->getUser()->changeableGroups() |
593 | 587 | * |
594 | 588 | * @return Array array( 'add' => array( addablegroups ), 'remove' => array( removablegroups ) , 'add-self' => array( addablegroups to self), 'remove-self' => array( removable groups from self) ) |
595 | 589 | */ |
596 | 590 | function changeableGroups() { |
597 | | - global $wgUser; |
598 | | - return $wgUser->changeableGroups(); |
| 591 | + return $this->getUser()->changeableGroups(); |
599 | 592 | } |
600 | 593 | |
601 | 594 | /** |