r71446 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71445‎ | r71446 | r71447 >
Date:21:34, 22 August 2010
Author:ashley
Status:ok
Tags:
Comment:
coding style tweaks
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Implements Special:Userlogin
 4+ * Implements Special:UserLogin
55 *
66 * This program is free software; you can redistribute it and/or modify
77 * it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
2323 */
2424
2525 /**
26 - * constructor
 26+ * Constructor
2727 */
2828 function wfSpecialUserlogin( $par = '' ) {
2929 global $wgRequest;
@@ -35,7 +35,7 @@
3636 }
3737
3838 /**
39 - * Implements Special:Login
 39+ * Implements Special:UserLogin
4040 *
4141 * @ingroup SpecialPage
4242 */
@@ -91,7 +91,7 @@
9292 $this->mRemember = $request->getCheck( 'wpRemember' );
9393 $this->mLanguage = $request->getText( 'uselang' );
9494 $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
95 - $this->mToken = ($this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
 95+ $this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
9696
9797 if ( $wgRedirectOnLogin ) {
9898 $this->mReturnTo = $wgRedirectOnLogin;
@@ -126,14 +126,14 @@
127127 if ( !is_null( $this->mCookieCheck ) ) {
128128 $this->onCookieRedirectCheck( $this->mCookieCheck );
129129 return;
130 - } else if( $this->mPosted ) {
 130+ } elseif( $this->mPosted ) {
131131 if( $this->mCreateaccount ) {
132132 return $this->addNewAccount();
133 - } else if ( $this->mCreateaccountMail ) {
 133+ } elseif ( $this->mCreateaccountMail ) {
134134 return $this->addNewAccountMailPassword();
135 - } else if ( $this->mMailmypassword ) {
 135+ } elseif ( $this->mMailmypassword ) {
136136 return $this->mailPassword();
137 - } else if ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
 137+ } elseif ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
138138 return $this->processLogin();
139139 }
140140 }
@@ -153,7 +153,7 @@
154154
155155 $u = $this->addNewaccountInternal();
156156
157 - if ($u == null) {
 157+ if ( $u == null ) {
158158 return;
159159 }
160160
@@ -178,7 +178,6 @@
179179 $u = 0;
180180 }
181181
182 -
183182 /**
184183 * @private
185184 */
@@ -187,14 +186,16 @@
188187
189188 # Create the account and abort if there's a problem doing so
190189 $u = $this->addNewAccountInternal();
191 - if( $u == null )
 190+ if( $u == null ) {
192191 return;
 192+ }
193193
194194 # If we showed up language selection links, and one was in use, be
195195 # smart (and sensible) and save that language as the user's preference
196196 global $wgLoginLanguageSelector;
197 - if( $wgLoginLanguageSelector && $this->mLanguage )
 197+ if( $wgLoginLanguageSelector && $this->mLanguage ) {
198198 $u->setOption( 'language', $this->mLanguage );
 199+ }
199200
200201 # Send out an email authentication message if needed
201202 if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) {
@@ -274,13 +275,13 @@
275276 $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
276277 return false;
277278 }
278 -
 279+
279280 # The user didn't pass a createaccount token
280281 if ( !$this->mToken ) {
281282 $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
282283 return false;
283284 }
284 -
 285+
285286 # Validate the createaccount token
286287 if ( $this->mToken !== self::getCreateaccountToken() ) {
287288 $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
@@ -376,7 +377,7 @@
377378 return false;
378379 }
379380
380 - self::clearCreateaccountToken();
 381+ self::clearCreateaccountToken();
381382 return $this->initUser( $u, false );
382383 }
383384
@@ -431,16 +432,16 @@
432433 */
433434 public function authenticateUserData() {
434435 global $wgUser, $wgAuth, $wgMemc;
435 -
 436+
436437 if ( $this->mName == '' ) {
437438 return self::NO_NAME;
438439 }
439 -
 440+
440441 // We require a login token to prevent login CSRF
441442 // Handle part of this before incrementing the throttle so
442443 // token-less login attempts don't count towards the throttle
443444 // but wrong-token attempts do.
444 -
 445+
445446 // If the user doesn't have a login token yet, set one.
446447 if ( !self::getLoginToken() ) {
447448 self::setLoginToken();
@@ -450,7 +451,7 @@
451452 if ( !$this->mToken ) {
452453 return self::NEED_TOKEN;
453454 }
454 -
 455+
455456 global $wgPasswordAttemptThrottle;
456457
457458 $throttleCount = 0;
@@ -458,17 +459,17 @@
459460 $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) );
460461 $count = $wgPasswordAttemptThrottle['count'];
461462 $period = $wgPasswordAttemptThrottle['seconds'];
462 -
 463+
463464 $throttleCount = $wgMemc->get( $throttleKey );
464465 if ( !$throttleCount ) {
465466 $wgMemc->add( $throttleKey, 1, $period ); // start counter
466 - } else if ( $throttleCount < $count ) {
467 - $wgMemc->incr($throttleKey);
468 - } else if ( $throttleCount >= $count ) {
 467+ } elseif ( $throttleCount < $count ) {
 468+ $wgMemc->incr( $throttleKey );
 469+ } elseif ( $throttleCount >= $count ) {
469470 return self::THROTTLED;
470471 }
471472 }
472 -
 473+
473474 // Validate the login token
474475 if ( $this->mToken !== self::getLoginToken() ) {
475476 return self::WRONG_TOKEN;
@@ -481,7 +482,7 @@
482483 // for user existence using User::newFromName($name)->getId() below
483484 // will effectively be using stale data.
484485 if ( $wgUser->getName() === $this->mName ) {
485 - wfDebug( __METHOD__.": already logged in as {$this->mName}\n" );
 486+ wfDebug( __METHOD__ . ": already logged in as {$this->mName}\n" );
486487 return self::SUCCESS;
487488 }
488489
@@ -522,7 +523,7 @@
523524 }
524525
525526 global $wgBlockDisablesLogin;
526 - if (!$u->checkPassword( $this->mPassword )) {
 527+ if ( !$u->checkPassword( $this->mPassword ) ) {
527528 if( $u->checkTemporaryPassword( $this->mPassword ) ) {
528529 // The e-mailed temporary password should not be used for actu-
529530 // al logins; that's a very sloppy habit, and insecure if an
@@ -550,7 +551,7 @@
551552 // faces etc will probably just fail cleanly here.
552553 $retval = self::RESET_PASS;
553554 } else {
554 - $retval = ($this->mPassword == '') ? self::EMPTY_PASS : self::WRONG_PASS;
 555+ $retval = ( $this->mPassword == '' ) ? self::EMPTY_PASS : self::WRONG_PASS;
555556 }
556557 } elseif ( $wgBlockDisablesLogin && $u->isBlocked() ) {
557558 // If we've enabled it, make it so that a blocked user cannot login
@@ -560,8 +561,8 @@
561562 $wgUser = $u;
562563
563564 // Please reset throttle for successful logins, thanks!
564 - if($throttleCount) {
565 - $wgMemc->delete($throttleKey);
 565+ if( $throttleCount ) {
 566+ $wgMemc->delete( $throttleKey );
566567 }
567568
568569 if ( $isAutoCreated ) {
@@ -584,7 +585,7 @@
585586 global $wgAuth, $wgUser, $wgAutocreatePolicy;
586587
587588 if ( $wgUser->isBlockedFromCreateAccount() ) {
588 - wfDebug( __METHOD__.": user is blocked from account creation\n" );
 589+ wfDebug( __METHOD__ . ": user is blocked from account creation\n" );
589590 return self::CREATE_BLOCKED;
590591 }
591592
@@ -608,16 +609,16 @@
609610 return self::NOT_EXISTS;
610611 }
611612 if ( !$wgAuth->userExists( $user->getName() ) ) {
612 - wfDebug( __METHOD__.": user does not exist\n" );
 613+ wfDebug( __METHOD__ . ": user does not exist\n" );
613614 return self::NOT_EXISTS;
614615 }
615616 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword ) ) {
616 - wfDebug( __METHOD__.": \$wgAuth->authenticate() returned false, aborting\n" );
 617+ wfDebug( __METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n" );
617618 return self::WRONG_PLUGIN_PASS;
618619 }
619620 }
620621
621 - wfDebug( __METHOD__.": creating account\n" );
 622+ wfDebug( __METHOD__ . ": creating account\n" );
622623 $user = $this->initUser( $user, true );
623624 return self::SUCCESS;
624625 }
@@ -654,7 +655,7 @@
655656 return $this->cookieRedirectCheck( 'login' );
656657 }
657658 break;
658 -
 659+
659660 case self::NEED_TOKEN:
660661 case self::WRONG_TOKEN:
661662 $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
@@ -667,7 +668,7 @@
668669 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
669670 break;
670671 case self::NOT_EXISTS:
671 - if( $wgUser->isAllowed( 'createaccount' ) ){
 672+ if( $wgUser->isAllowed( 'createaccount' ) ) {
672673 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mName ) ) );
673674 } else {
674675 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName ) ) );
@@ -693,7 +694,7 @@
694695 array( 'parsemag', 'escape' ), $this->mName ) );
695696 break;
696697 default:
697 - throw new MWException( "Unhandled case value" );
 698+ throw new MWException( 'Unhandled case value' );
698699 }
699700 }
700701
@@ -709,27 +710,27 @@
710711 */
711712 function mailPassword() {
712713 global $wgUser, $wgOut, $wgAuth;
713 -
 714+
714715 if ( wfReadOnly() ) {
715716 $wgOut->readOnlyPage();
716717 return false;
717718 }
718 -
 719+
719720 if( !$wgAuth->allowPasswordChange() ) {
720721 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
721722 return;
722723 }
723724
724 - # Check against blocked IPs so blocked users can't flood admins
 725+ # Check against blocked IPs so blocked users can't flood admins
725726 # with password resets
726727 if( $wgUser->isBlocked() ) {
727728 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
728729 return;
729730 }
730 -
 731+
731732 # Check for hooks
732733 $error = null;
733 - if ( ! wfRunHooks( 'UserLoginMailPassword', array( $this->mName, &$error ) ) ) {
 734+ if ( !wfRunHooks( 'UserLoginMailPassword', array( $this->mName, &$error ) ) ) {
734735 $this->mainLoginForm( $error );
735736 return;
736737 }
@@ -746,7 +747,7 @@
747748 $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
748749 return;
749750 }
750 -
 751+
751752 # Check against the rate limiter
752753 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
753754 $wgOut->rateLimited();
@@ -811,9 +812,9 @@
812813 if( !$ip ) {
813814 return new WikiError( wfMsg( 'badipaddress' ) );
814815 }
815 -
816 - wfRunHooks( 'User::mailPasswordInternal', array(&$wgUser, &$ip, &$u) );
817816
 817+ wfRunHooks( 'User::mailPasswordInternal', array( &$wgUser, &$ip, &$u ) );
 818+
818819 $np = $u->randomPassword();
819820 $u->setNewpassword( $np, $throttle );
820821 $u->saveSettings();
@@ -841,7 +842,7 @@
842843
843844 # Run any hooks; display injected HTML if any, else redirect
844845 $injected_html = '';
845 - wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
 846+ wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
846847
847848 if( $injected_html !== '' ) {
848849 $this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
@@ -864,7 +865,7 @@
865866 global $wgUser;
866867 # Run any hooks; display injected HTML
867868 $injected_html = '';
868 - wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
 869+ wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
869870
870871 $this->displaySuccessfulLogin( 'welcomecreation', $injected_html );
871872 }
@@ -896,7 +897,7 @@
897898 $wgOut->setRobotPolicy( 'noindex,nofollow' );
898899 $wgOut->setArticleRelated( false );
899900
900 - $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
 901+ $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
901902 // Stuff that might want to be added at the end. For example, instruc-
902903 // tions if blocked.
903904 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
@@ -938,12 +939,12 @@
939940 global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail;
940941 global $wgRequest, $wgLoginLanguageSelector;
941942 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
942 -
 943+
943944 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
944 -
 945+
945946 if ( $this->mType == 'signup' ) {
946 - // Block signup here if in readonly. Keeps user from
947 - // going through the process (filling out data, etc)
 947+ // Block signup here if in readonly. Keeps user from
 948+ // going through the process (filling out data, etc)
948949 // and being informed later.
949950 if ( wfReadOnly() ) {
950951 $wgOut->readOnlyPage();
@@ -985,26 +986,29 @@
986987
987988 if ( !empty( $this->mReturnTo ) ) {
988989 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
989 - if ( !empty( $this->mReturnToQuery ) )
 990+ if ( !empty( $this->mReturnToQuery ) ) {
990991 $returnto .= '&returntoquery=' .
991992 wfUrlencode( $this->mReturnToQuery );
 993+ }
992994 $q .= $returnto;
993995 $linkq .= $returnto;
994996 }
995997
996998 # Pass any language selection on to the mode switch link
997 - if( $wgLoginLanguageSelector && $this->mLanguage )
 999+ if( $wgLoginLanguageSelector && $this->mLanguage ) {
9981000 $linkq .= '&uselang=' . $this->mLanguage;
 1001+ }
9991002
1000 - $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
 1003+ $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalURL( $linkq ) ) . '">';
10011004 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
10021005 $link .= '</a>';
10031006
10041007 # Don't show a "create account" link if the user can't
1005 - if( $this->showCreateOrLoginLink( $wgUser ) )
 1008+ if( $this->showCreateOrLoginLink( $wgUser ) ) {
10061009 $template->set( 'link', wfMsgExt( $linkmsg, array( 'parseinline', 'replaceafter' ), $link ) );
1007 - else
 1010+ } else {
10081011 $template->set( 'link', '' );
 1012+ }
10091013
10101014 $template->set( 'header', '' );
10111015 $template->set( 'name', $this->mName );
@@ -1015,7 +1019,7 @@
10161020 $template->set( 'domain', $this->mDomain );
10171021 $template->set( 'reason', $this->mReason );
10181022
1019 - $template->set( 'action', $titleObj->getLocalUrl( $q ) );
 1023+ $template->set( 'action', $titleObj->getLocalURL( $q ) );
10201024 $template->set( 'message', $msg );
10211025 $template->set( 'messagetype', $msgtype );
10221026 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
@@ -1025,7 +1029,7 @@
10261030 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
10271031 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
10281032 $template->set( 'usereason', $wgUser->isLoggedIn() );
1029 - $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember );
 1033+ $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) || $this->mRemember );
10301034
10311035 if ( $this->mType == 'signup' ) {
10321036 if ( !self::getCreateaccountToken() ) {
@@ -1038,7 +1042,7 @@
10391043 }
10401044 $template->set( 'token', self::getLoginToken() );
10411045 }
1042 -
 1046+
10431047 # Prepare language selection links as needed
10441048 if( $wgLoginLanguageSelector ) {
10451049 $template->set( 'languages', $this->makeLanguageSelector() );
@@ -1054,7 +1058,7 @@
10551059 wfRunHooks( 'UserLoginForm', array( &$template ) );
10561060 }
10571061
1058 - //Changes the title depending on permissions for creating account
 1062+ // Changes the title depending on permissions for creating account
10591063 if ( $wgUser->isAllowed( 'createaccount' ) ) {
10601064 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
10611065 } else {
@@ -1063,7 +1067,7 @@
10641068
10651069 $wgOut->setRobotPolicy( 'noindex,nofollow' );
10661070 $wgOut->setArticleRelated( false );
1067 - $wgOut->disallowUserJs(); // just in case...
 1071+ $wgOut->disallowUserJs(); // just in case...
10681072 $wgOut->addTemplate( $template );
10691073 }
10701074
@@ -1093,7 +1097,7 @@
10941098 global $wgDisableCookieCheck, $wgRequest;
10951099 return $wgDisableCookieCheck ? true : $wgRequest->checkSessionCookie();
10961100 }
1097 -
 1101+
10981102 /**
10991103 * Get the login token from the current session
11001104 */
@@ -1101,7 +1105,7 @@
11021106 global $wgRequest;
11031107 return $wgRequest->getSessionData( 'wsLoginToken' );
11041108 }
1105 -
 1109+
11061110 /**
11071111 * Randomly generate a new login token and attach it to the current session
11081112 */
@@ -1111,7 +1115,7 @@
11121116 // because the latter reuses $_SESSION['wsEditToken']
11131117 $wgRequest->setSessionData( 'wsLoginToken', User::generateToken() );
11141118 }
1115 -
 1119+
11161120 /**
11171121 * Remove any login token attached to the current session
11181122 */
@@ -1127,7 +1131,7 @@
11281132 global $wgRequest;
11291133 return $wgRequest->getSessionData( 'wsCreateaccountToken' );
11301134 }
1131 -
 1135+
11321136 /**
11331137 * Randomly generate a new createaccount token and attach it to the current session
11341138 */
@@ -1135,7 +1139,7 @@
11361140 global $wgRequest;
11371141 $wgRequest->setSessionData( 'wsCreateaccountToken', User::generateToken() );
11381142 }
1139 -
 1143+
11401144 /**
11411145 * Remove any createaccount token attached to the current session
11421146 */
@@ -1152,7 +1156,9 @@
11531157
11541158 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
11551159 $query = array( 'wpCookieCheck' => $type );
1156 - if ( $this->mReturnTo ) $query['returnto'] = $this->mReturnTo;
 1160+ if ( $this->mReturnTo ) {
 1161+ $query['returnto'] = $this->mReturnTo;
 1162+ }
11571163 $check = $titleObj->getFullURL( $query );
11581164
11591165 return $wgOut->redirect( $check );
@@ -1165,7 +1171,7 @@
11661172 if ( !$this->hasSessionCookie() ) {
11671173 if ( $type == 'new' ) {
11681174 return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
1169 - } else if ( $type == 'login' ) {
 1175+ } elseif ( $type == 'login' ) {
11701176 return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
11711177 } else {
11721178 # shouldn't happen
@@ -1199,7 +1205,7 @@
12001206 foreach( $langs as $lang ) {
12011207 $lang = trim( $lang, '* ' );
12021208 $parts = explode( '|', $lang );
1203 - if (count($parts) >= 2) {
 1209+ if ( count( $parts ) >= 2 ) {
12041210 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
12051211 }
12061212 }
@@ -1220,10 +1226,12 @@
12211227 global $wgUser;
12221228 $self = SpecialPage::getTitleFor( 'Userlogin' );
12231229 $attr = array( 'uselang' => $lang );
1224 - if( $this->mType == 'signup' )
 1230+ if( $this->mType == 'signup' ) {
12251231 $attr['type'] = 'signup';
1226 - if( $this->mReturnTo )
 1232+ }
 1233+ if( $this->mReturnTo ) {
12271234 $attr['returnto'] = $this->mReturnTo;
 1235+ }
12281236 $skin = $wgUser->getSkin();
12291237 return $skin->linkKnown(
12301238 $self,

Status & tagging log