r98272 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98271‎ | r98272 | r98273 >
Date:22:05, 27 September 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Use getUser() instead of $wgUser
* Renamed getRequest() account function to getAccountData() avoid collision with parent
Modified paths:
  • /trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php
@@ -7,11 +7,12 @@
88 }
99
1010 function execute( $par ) {
11 - global $wgUser, $wgAccountRequestTypes;
 11+ global $wgAccountRequestTypes;
1212 $out = $this->getOutput();
1313 $request = $this->getRequest();
 14+ $reqUser = $this->getUser();
1415
15 - if ( !$wgUser->isAllowed( 'lookupcredentials' ) ) {
 16+ if ( !$reqUser->isAllowed( 'lookupcredentials' ) ) {
1617 $out->permissionRequired( 'lookupcredentials' );
1718 return;
1819 }
@@ -23,7 +24,7 @@
2425 # Attachments
2526 $this->file = $request->getVal( 'file' );
2627
27 - $this->skin = $wgUser->getSkin();
 28+ $this->skin = $reqUser->getSkin();
2829
2930 if ( $this->file ) {
3031 $this->showFile( $this->file );
@@ -55,12 +56,13 @@
5657 }
5758
5859 function showCredentials() {
59 - global $wgUser, $wgLang, $wgAccountRequestTypes;
 60+ global $wgLang, $wgAccountRequestTypes;
 61+ $reqUser = $this->getUser();
6062 $out = $this->getOutput();
6163
6264 $titleObj = SpecialPage::getTitleFor( 'UserCredentials' );
6365
64 - $row = $this->getRequest();
 66+ $row = $this->getAccountData();
6567 if ( !$row ) {
6668 $out->addHTML( wfMsgHtml( 'usercredentials-badid' ) );
6769 return;
@@ -159,7 +161,7 @@
160162 $form .= ConfirmAccountsPage::parseLinks( $row->acd_urls );
161163 }
162164
163 - if ( $wgUser->isAllowed( 'requestips' ) ) {
 165+ if ( $reqUser->isAllowed( 'requestips' ) ) {
164166 $blokip = SpecialPage::getTitleFor( 'blockip' );
165167 $form .= "<p>" . wfMsgHtml( 'usercredentials-ip' ) . " " . htmlspecialchars( $row->acd_ip ) . "</p>\n";
166168 }
@@ -206,7 +208,7 @@
207209 wfStreamFile( $path );
208210 }
209211
210 - function getRequest() {
 212+ function getAccountData() {
211213 $uid = User::idFromName( $this->target );
212214 if ( !$uid )
213215 return false;
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
@@ -7,14 +7,15 @@
88 }
99
1010 function execute( $par ) {
11 - global $wgUser, $wgUseRealNamesOnly,
 11+ global $wgUseRealNamesOnly,
1212 $wgAccountRequestToS, $wgAccountRequestExtraInfo, $wgAccountRequestTypes;
1313 # If a user cannot make accounts, don't let them request them either
1414 global $wgAccountRequestWhileBlocked;
1515
 16+ $reqUser = $this->getUser();
1617 $request = $this->getRequest();
1718 $out = $this->getOutput();
18 - if ( !$wgAccountRequestWhileBlocked && $wgUser->isBlockedFromCreateAccount() ) {
 19+ if ( !$wgAccountRequestWhileBlocked && $reqUser->isBlockedFromCreateAccount() ) {
1920 $out->blockedPage();
2021 return;
2122 }
@@ -62,10 +63,10 @@
6364 # We may be confirming an email address here
6465 $emailCode = $request->getText( 'wpEmailToken' );
6566
66 - $this->skin = $wgUser->getSkin();
 67+ $this->skin = $reqUser->getSkin();
6768
6869 $action = $request->getVal( 'action' );
69 - if ( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
 70+ if ( $request->wasPosted() && $reqUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
7071 $this->mPrevAttachment = $this->mPrevAttachment ? $this->mPrevAttachment : $this->mSrcName;
7172 $this->doSubmit();
7273 } elseif ( $action == 'confirmemail' ) {
@@ -77,10 +78,12 @@
7879 }
7980
8081 protected function showForm( $msg = '', $forgotFile = 0 ) {
81 - global $wgUser, $wgUseRealNamesOnly, $wgAllowRealName;
 82+ global $wgUseRealNamesOnly, $wgAllowRealName;
8283 global $wgAccountRequestToS, $wgAccountRequestTypes, $wgAccountRequestExtraInfo,
8384 $wgAllowAccountRequestFiles, $wgMakeUserPageFromBio;
8485
 86+ $reqUser = $this->getUser();
 87+
8588 $this->mForgotAttachment = $forgotFile;
8689
8790 $out = $this->getOutput();
@@ -90,7 +93,7 @@
9194 $out->addHTML( '<div class="errorbox">' . $msg . '</div><div class="visualClear"></div>' );
9295 }
9396 # Give notice to users that are logged in
94 - if ( $wgUser->getID() ) {
 97+ if ( $reqUser->getID() ) {
9598 $out->addWikiMsg( 'requestaccount-dup' );
9699 }
97100
@@ -198,7 +201,7 @@
199202 # FIXME: do this better...
200203 global $wgConfirmAccountCaptchas, $wgCaptchaClass, $wgCaptchaTriggers;
201204 if ( $wgConfirmAccountCaptchas && isset( $wgCaptchaClass )
202 - && $wgCaptchaTriggers['createaccount'] && !$wgUser->isAllowed( 'skipcaptcha' ) )
 205+ && $wgCaptchaTriggers['createaccount'] && !$reqUser->isAllowed( 'skipcaptcha' ) )
203206 {
204207 $captcha = new $wgCaptchaClass;
205208 # Hook point to add captchas
@@ -208,7 +211,7 @@
209212 $form .= '</fieldset>';
210213 }
211214 $form .= Html::Hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n";
212 - $form .= Html::Hidden( 'wpEditToken', $wgUser->editToken() ) . "\n";
 215+ $form .= Html::Hidden( 'wpEditToken', $reqUser->editToken() ) . "\n";
213216 $form .= Html::Hidden( 'attachment', $this->mPrevAttachment ) . "\n";
214217 $form .= Html::Hidden( 'forgotAttachment', $this->mForgotAttachment ) . "\n";
215218 $form .= "<p>" . Xml::submitButton( wfMsgHtml( 'requestaccount-submit' ) ) . "</p>";
@@ -220,7 +223,8 @@
221224 }
222225
223226 protected function doSubmit() {
224 - global $wgUser, $wgAuth, $wgAccountRequestThrottle;
 227+ global $wgAuth, $wgAccountRequestThrottle;
 228+ $reqUser = $this->getUser();
225229 $out = $this->getOutput();
226230 # Now create a dummy user ($u) and check if it is valid
227231 $name = trim( $this->mUsername );
@@ -247,7 +251,7 @@
248252 $wgCaptchaTriggers['createaccount'] = $old;
249253 }
250254 # No request spamming...
251 - if ( $wgAccountRequestThrottle && $wgUser->isPingLimitable() ) {
 255+ if ( $wgAccountRequestThrottle && $reqUser->isPingLimitable() ) {
252256 global $wgMemc;
253257 $key = wfMemcKey( 'acctrequest', 'ip', wfGetIP() );
254258 $value = $wgMemc->get( $key );
@@ -386,7 +390,7 @@
387391 $wgMemc->delete( $key );
388392 # No request spamming...
389393 # BC: check if isPingLimitable() exists
390 - if ( $wgAccountRequestThrottle && $wgUser->isPingLimitable() ) {
 394+ if ( $wgAccountRequestThrottle && $reqUser->isPingLimitable() ) {
391395 $key = wfMemcKey( 'acctrequest', 'ip', wfGetIP() );
392396 if ( !$value = $wgMemc->incr( $key ) ) {
393397 $wgMemc->set( $key, 1, 86400 );
@@ -428,7 +432,8 @@
429433 * @param int $limit number of accounts allowed to be requested from the same IP
430434 */
431435 protected function confirmEmailToken( $code ) {
432 - global $wgUser, $wgConfirmAccountContact, $wgPasswordSender;
 436+ global $wgConfirmAccountContact, $wgPasswordSender;
 437+ $reqUser = $this->getUser();
433438 $out = $this->getOutput();
434439 # Confirm if this token is in the pending requests
435440 $name = ConfirmAccount::requestNameFromEmailToken( $code );
@@ -457,9 +462,9 @@
458463 $user = User::newFromConfirmationCode( $code );
459464 if ( is_object( $user ) ) {
460465 if ( $user->confirmEmail() ) {
461 - $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
 466+ $message = $reqUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
462467 $out->addWikiMsg( $message );
463 - if ( !$wgUser->isLoggedIn() ) {
 468+ if ( !$reqUser->isLoggedIn() ) {
464469 $title = SpecialPage::getTitleFor( 'Userlogin' );
465470 $out->returnToMain( true, $title->getPrefixedUrl() );
466471 }
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
@@ -8,15 +8,16 @@
99
1010 // @TODO: split out listlink mess
1111 function execute( $par ) {
12 - global $wgUser, $wgAccountRequestTypes, $wgLang;
 12+ global $wgAccountRequestTypes, $wgLang;
1313
 14+ $reqUser = $this->getUser();
1415 $request = $this->getRequest();
1516 $out = $this->getOutput();
16 - if( !$wgUser->isAllowed( 'confirmaccount' ) ) {
 17+ if( !$reqUser->isAllowed( 'confirmaccount' ) ) {
1718 $out->permissionRequired( 'confirmaccount' );
1819 return;
1920 }
20 - if( !$wgUser->getID() ) {
 21+ if( !$reqUser->getID() ) {
2122 $out->permissionRequired( 'user' );
2223 return;
2324 }
@@ -73,7 +74,7 @@
7475 }
7576 }
7677
77 - $this->skin = $wgUser->getSkin();
 78+ $this->skin = $reqUser->getSkin();
7879
7980 $titleObj = SpecialPage::getTitleFor( 'ConfirmAccounts', $this->specialPageParameter );
8081
@@ -131,7 +132,7 @@
132133 "</i></strong> [{$listLink}] <strong>{$viewall}</strong>" );
133134 }
134135
135 - if( $request->wasPosted() && $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
 136+ if( $request->wasPosted() && $reqUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
136137 $this->doSubmit();
137138 } elseif( $this->file ) {
138139 $this->showFile( $this->file );
@@ -190,7 +191,8 @@
191192 }
192193
193194 protected function showForm( $msg='' ) {
194 - global $wgUser, $wgLang, $wgAccountRequestTypes;
 195+ global $wgLang, $wgAccountRequestTypes;
 196+ $reqUser = $this->getUser();
195197 $out = $this->getOutput();
196198
197199 $titleObj = SpecialPage::getTitleFor( 'ConfirmAccounts', $this->specialPageParameter );
@@ -306,7 +308,7 @@
307309 "</textarea></p>\n";
308310 $form .= '</fieldset>';
309311 global $wgAccountRequestExtraInfo;
310 - if ($wgAccountRequestExtraInfo || $wgUser->isAllowed( 'requestips' ) ) {
 312+ if ($wgAccountRequestExtraInfo || $reqUser->isAllowed( 'requestips' ) ) {
311313 $form .= '<fieldset>';
312314 $form .= '<legend>' . wfMsgHtml('confirmaccount-leg-other') . '</legend>';
313315 if( $wgAccountRequestExtraInfo ) {
@@ -324,7 +326,7 @@
325327 $form .= "<p>".wfMsgHtml('confirmaccount-urls')."</p>\n";
326328 $form .= self::parseLinks($row->acr_urls);
327329 }
328 - if( $wgUser->isAllowed( 'requestips' ) ) {
 330+ if( $reqUser->isAllowed( 'requestips' ) ) {
329331 $blokip = SpecialPage::getTitleFor( 'Block' );
330332 $form .= "<p>".wfMsgHtml('confirmaccount-ip')." ".htmlspecialchars($row->acr_ip).
331333 " (" . $this->skin->makeKnownLinkObj( $blokip, wfMsgHtml('blockip'),
@@ -362,7 +364,7 @@
363365 $form .= Html::Hidden( 'action', 'reject' );
364366 $form .= Html::Hidden( 'acrid', $row->acr_id );
365367 $form .= Html::Hidden( 'wpShowRejects', $this->showRejects );
366 - $form .= Html::Hidden( 'wpEditToken', $wgUser->editToken() )."\n";
 368+ $form .= Html::Hidden( 'wpEditToken', $reqUser->editToken() )."\n";
367369 $form .= Xml::closeElement( 'form' );
368370
369371 $out->addHTML( $form );
@@ -371,7 +373,7 @@
372374 # Set a key to who is looking at this request.
373375 # Have it expire in 10 minutes...
374376 $key = wfMemcKey( 'acctrequest', 'view', $row->acr_id );
375 - $wgMemc->set( $key, $wgUser->getID(), 60*10 );
 377+ $wgMemc->set( $key, $reqUser->getID(), 60*10 );
376378 }
377379
378380 /**
@@ -400,7 +402,7 @@
401403 }
402404
403405 protected function doSubmit() {
404 - global $wgUser;
 406+ $reqUser = $this->getUser();
405407 $out = $this->getOutput();
406408
407409 $titleObj = SpecialPage::getTitleFor( 'ConfirmAccounts', $this->specialPageParameter );
@@ -422,7 +424,7 @@
423425 $dbw->begin();
424426 $dbw->update( 'account_requests',
425427 array( 'acr_rejected' => $dbw->timestamp(),
426 - 'acr_user' => $wgUser->getID(),
 428+ 'acr_user' => $reqUser->getID(),
427429 'acr_comment' => ($this->submitType == 'spam') ? '' : $this->reason,
428430 'acr_deleted' => 1 ),
429431 array( 'acr_id' => $this->acrID, 'acr_deleted' => 0 ),
@@ -533,7 +535,7 @@
534536 'acd_areas' => $row->acr_areas,
535537 'acd_registration' => $row->acr_registration,
536538 'acd_accepted' => $dbw->timestamp(),
537 - 'acd_user' => $wgUser->getID(),
 539+ 'acd_user' => $reqUser->getID(),
538540 'acd_comment' => $this->reason,
539541 'acd_id' => $acd_id ),
540542 __METHOD__
@@ -687,7 +689,7 @@
688690 # Finally, done!!!
689691 $this->showSuccess( $this->submitType, $user->getName(), array( $error ) );
690692 } elseif( $this->submitType === 'hold' ) {
691 - global $wgUser;
 693+ $reqUser = $this->getUser();
692694
693695 # Make proxy user to email a message
694696 $u = User::newFromName( $row->acr_name, 'creatable' );
@@ -709,7 +711,7 @@
710712 $dbw->begin();
711713 $dbw->update( 'account_requests',
712714 array( 'acr_held' => $dbw->timestamp(),
713 - 'acr_user' => $wgUser->getID(),
 715+ 'acr_user' => $reqUser->getID(),
714716 'acr_comment' => $this->reason ),
715717 array( 'acr_id' => $this->acrID, 'acr_held IS NULL', 'acr_deleted' => 0 ),
716718 __METHOD__
@@ -831,7 +833,8 @@
832834 }
833835
834836 protected function showList() {
835 - global $wgUser, $wgLang;
 837+ global $wgLang;
 838+ $reqUser = $this->getUser();
836839 $out = $this->getOutput();
837840
838841 $titleObj = SpecialPage::getTitleFor( 'ConfirmAccounts', $this->specialPageParameter );
@@ -870,7 +873,8 @@
871874 }
872875
873876 public function formatRow( $row ) {
874 - global $wgLang, $wgUser, $wgUseRealNamesOnly, $wgAllowRealName;
 877+ global $wgLang, $wgUseRealNamesOnly, $wgAllowRealName;
 878+ $reqUser = $this->getUser();
875879
876880 $titleObj = SpecialPage::getTitleFor( 'ConfirmAccounts', $this->specialPageParameter );
877881 if( $this->showRejects || $this->showStale ) {

Status & tagging log