r100114 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100113‎ | r100114 | r100115 >
Date:14:08, 18 October 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Use local context instead of global variables
* Pass the context between Special:Userlogin and Special:ChangePassword when calling the other one
Modified paths:
  • /trunk/phase3/includes/specials/SpecialChangePassword.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialChangePassword.php
@@ -91,6 +91,7 @@
9292 $data['wpRemember'] = 1;
9393 }
9494 $login = new LoginForm( new FauxRequest( $data, true ) );
 95+ $login->setContext( $this->getContext() );
9596 $login->execute( null );
9697 }
9798 $this->doReturnTo();
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -56,17 +56,17 @@
5757 private $mExtUser = null;
5858
5959 /**
 60+ * @ var WebRequest
 61+ */
 62+ private $mOverrideRequest = null;
 63+
 64+ /**
6065 * @param WebRequest $request
6166 */
6267 public function __construct( $request = null ) {
6368 parent::__construct( 'Userlogin' );
6469
65 - if ( $request === null ) {
66 - global $wgRequest;
67 - $this->load( $wgRequest );
68 - } else {
69 - $this->load( $request );
70 - }
 70+ $this->mOverrideRequest = $request;
7171 }
7272
7373 /**
@@ -132,6 +132,13 @@
133133 wfSetupSession();
134134 }
135135
 136+ if ( $this->mOverrideRequest === null ) {
 137+ $request = $this->getRequest();
 138+ } else {
 139+ $request = $this->mOverrideRequest;
 140+ }
 141+ $this->load( $request );
 142+
136143 if ( $par == 'signup' ) { # Check for [[Special:Userlogin/signup]]
137144 $this->mType = 'signup';
138145 }
@@ -155,10 +162,8 @@
156163 * @private
157164 */
158165 function addNewAccountMailPassword() {
159 - global $wgOut;
160 -
161166 if ( $this->mEmail == '' ) {
162 - $this->mainLoginForm( wfMsgExt( 'noemailcreate', array( 'parsemag', 'escape' ) ) );
 167+ $this->mainLoginForm( $this->msg( 'noemailcreate' )->escaped() );
163168 return;
164169 }
165170
@@ -176,13 +181,14 @@
177182 wfRunHooks( 'AddNewAccount', array( $u, true ) );
178183 $u->addNewUserLogEntry( true, $this->mReason );
179184
180 - $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
 185+ $out = $this->getOutput();
 186+ $out->setPageTitle( $this->msg( 'accmailtitle' )->text() );
181187
182188 if( !$result->isGood() ) {
183 - $this->mainLoginForm( wfMsg( 'mailerror', $result->getWikiText() ) );
 189+ $this->mainLoginForm( $this->msg( 'mailerror', $result->getWikiText() )->text() );
184190 } else {
185 - $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
186 - $wgOut->returnToMain( false );
 191+ $out->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
 192+ $out->returnToMain( false );
187193 }
188194 }
189195
@@ -190,7 +196,7 @@
191197 * @private
192198 */
193199 function addNewAccount() {
194 - global $wgUser, $wgEmailAuthentication, $wgOut;
 200+ global $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector;
195201
196202 # Create the account and abort if there's a problem doing so
197203 $u = $this->addNewAccountInternal();
@@ -200,18 +206,19 @@
201207
202208 # If we showed up language selection links, and one was in use, be
203209 # smart (and sensible) and save that language as the user's preference
204 - global $wgLoginLanguageSelector;
205210 if( $wgLoginLanguageSelector && $this->mLanguage ) {
206211 $u->setOption( 'language', $this->mLanguage );
207212 }
208213
 214+ $out = $this->getOutput();
 215+
209216 # Send out an email authentication message if needed
210217 if( $wgEmailAuthentication && Sanitizer::validateEmail( $u->getEmail() ) ) {
211218 $status = $u->sendConfirmationMail();
212219 if( $status->isGood() ) {
213 - $wgOut->addWikiMsg( 'confirmemail_oncreate' );
 220+ $out->addWikiMsg( 'confirmemail_oncreate' );
214221 } else {
215 - $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
 222+ $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
216223 }
217224 }
218225
@@ -221,15 +228,15 @@
222229 # If not logged in, assume the new account as the current one and set
223230 # session cookies then show a "welcome" message or a "need cookies"
224231 # message as needed
225 - if( $wgUser->isAnon() ) {
 232+ if( $this->getUser()->isAnon() ) {
 233+ $u->setCookies();
226234 $wgUser = $u;
227 - $wgUser->setCookies();
228235 // This should set it for OutputPage and the Skin
229236 // which is needed or the personal links will be
230237 // wrong.
231 - RequestContext::getMain()->setUser( $u );
232 - wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
233 - $wgUser->addNewUserLogEntry();
 238+ $this->getContext()->setUser( $u );
 239+ wfRunHooks( 'AddNewAccount', array( $u, false ) );
 240+ $u->addNewUserLogEntry();
234241 if( $this->hasSessionCookie() ) {
235242 return $this->successfulCreation();
236243 } else {
@@ -237,10 +244,9 @@
238245 }
239246 } else {
240247 # Confirm that the account was created
241 - $self = SpecialPage::getTitleFor( 'Userlogin' );
242 - $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
243 - $wgOut->addWikiMsg( 'accountcreatedtext', $u->getName() );
244 - $wgOut->returnToMain( false, $self );
 248+ $out->setPageTitle( $this->msg( 'accountcreated' )->text() );
 249+ $out->addWikiMsg( 'accountcreatedtext', $u->getName() );
 250+ $out->returnToMain( false, $this->getTitle() );
245251 wfRunHooks( 'AddNewAccount', array( $u, false ) );
246252 $u->addNewUserLogEntry( false, $this->mReason );
247253 return true;
@@ -251,14 +257,12 @@
252258 * @private
253259 */
254260 function addNewAccountInternal() {
255 - global $wgUser, $wgOut, $wgRequest;
256 - global $wgMemc, $wgAccountCreationThrottle;
257 - global $wgAuth, $wgMinimalPasswordLength;
258 - global $wgEmailConfirmToEdit;
 261+ global $wgAuth, $wgMemc, $wgAccountCreationThrottle,
 262+ $wgMinimalPasswordLength, $wgEmailConfirmToEdit;
259263
260264 // If the user passes an invalid domain, something is fishy
261265 if( !$wgAuth->validDomain( $this->mDomain ) ) {
262 - $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
 266+ $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() );
263267 return false;
264268 }
265269
@@ -270,47 +274,46 @@
271275 if( 'local' != $this->mDomain && $this->mDomain != '' ) {
272276 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mUsername )
273277 || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) {
274 - $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
 278+ $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() );
275279 return false;
276280 }
277281 }
278282
279283 if ( wfReadOnly() ) {
280 - $wgOut->readOnlyPage();
281 - return false;
 284+ throw new ReadOnlyError;
282285 }
283286
284287 # Request forgery checks.
285288 if ( !self::getCreateaccountToken() ) {
286289 self::setCreateaccountToken();
287 - $this->mainLoginForm( wfMsgExt( 'nocookiesfornew', array( 'parseinline' ) ) );
 290+ $this->mainLoginForm( $this->msg( 'nocookiesfornew' )->parse() );
288291 return false;
289292 }
290293
291294 # The user didn't pass a createaccount token
292295 if ( !$this->mToken ) {
293 - $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
 296+ $this->mainLoginForm( $this->msg( 'sessionfailure' )->text() );
294297 return false;
295298 }
296299
297300 # Validate the createaccount token
298301 if ( $this->mToken !== self::getCreateaccountToken() ) {
299 - $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
 302+ $this->mainLoginForm( $this->msg( 'sessionfailure' )->text() );
300303 return false;
301304 }
302305
303306 # Check permissions
304 - if ( !$wgUser->isAllowed( 'createaccount' ) ) {
305 - $wgOut->permissionRequired( 'createaccount' );
 307+ $currentUser = $this->getUser();
 308+ if ( !$currentUser->isAllowed( 'createaccount' ) ) {
 309+ throw new PermissionsError( 'createaccount' );
 310+ } elseif ( $currentUser->isBlockedFromCreateAccount() ) {
 311+ $this->userBlockedMessage( $currentUser->isBlockedFromCreateAccount() );
306312 return false;
307 - } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
308 - $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() );
309 - return false;
310313 }
311314
312 - $ip = $wgRequest->getIP();
313 - if ( $wgUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
314 - $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
 315+ $ip = $this->getRequest()->getIP();
 316+ if ( $currentUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
 317+ $this->mainLoginForm( $this->msg( 'sorbs_create_account_reason' )->text() . ' (' . htmlspecialchars( $ip ) . ')' );
315318 return false;
316319 }
317320
@@ -318,17 +321,17 @@
319322 $name = trim( $this->mUsername );
320323 $u = User::newFromName( $name, 'creatable' );
321324 if ( !is_object( $u ) ) {
322 - $this->mainLoginForm( wfMsg( 'noname' ) );
 325+ $this->mainLoginForm( $this->msg( 'noname' )->text() );
323326 return false;
324327 }
325328
326329 if ( 0 != $u->idForName() ) {
327 - $this->mainLoginForm( wfMsg( 'userexists' ) );
 330+ $this->mainLoginForm( $this->msg( 'userexists' )->text() );
328331 return false;
329332 }
330333
331334 if ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) {
332 - $this->mainLoginForm( wfMsg( 'badretype' ) );
 335+ $this->mainLoginForm( $this->msg( 'badretype' )->text() );
333336 return false;
334337 }
335338
@@ -343,7 +346,7 @@
344347 $message = $valid;
345348 $params = array( $wgMinimalPasswordLength );
346349 }
347 - $this->mainLoginForm( wfMsgExt( $message, array( 'parsemag' ), $params ) );
 350+ $this->mainLoginForm( $this->msg( $message, $params )->text() );
348351 return false;
349352 } else {
350353 # do not force a password for account creation by email
@@ -355,12 +358,12 @@
356359 # if you need a confirmed email address to edit, then obviously you
357360 # need an email address.
358361 if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) {
359 - $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
 362+ $this->mainLoginForm( $this->msg( 'noemailtitle' )->text() );
360363 return false;
361364 }
362365
363366 if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) {
364 - $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
 367+ $this->mainLoginForm( $this->msg( 'invalidemailaddress' )->text() );
365368 return false;
366369 }
367370
@@ -381,7 +384,7 @@
382385 if ( !wfRunHooks( 'exemptFromAccountCreationThrottle', array( $ip ) ) ) {
383386 wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook allowed account creation w/o throttle\n" );
384387 } else {
385 - if ( ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) ) {
 388+ if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) {
386389 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
387390 $value = $wgMemc->get( $key );
388391 if ( !$value ) {
@@ -396,7 +399,7 @@
397400 }
398401
399402 if( !$wgAuth->addUser( $u, $this->mPassword, $this->mEmail, $this->mRealName ) ) {
400 - $this->mainLoginForm( wfMsg( 'externaldberror' ) );
 403+ $this->mainLoginForm( $this->msg( 'externaldberror' )->text() );
401404 return false;
402405 }
403406
@@ -485,13 +488,13 @@
486489 return self::WRONG_TOKEN;
487490 }
488491
489 - // Load $wgUser now, and check to see if we're logging in as the same
490 - // name. This is necessary because loading $wgUser (say by calling
491 - // getName()) calls the UserLoadFromSession hook, which potentially
492 - // creates the user in the database. Until we load $wgUser, checking
493 - // for user existence using User::newFromName($name)->getId() below
 492+ // Load the current user now, and check to see if we're logging in as
 493+ // the same name. This is necessary because loading the current user
 494+ // (say by calling getName()) calls the UserLoadFromSession hook, which
 495+ // potentially creates the user in the database. Until we load $wgUser,
 496+ // checking for user existence using User::newFromName($name)->getId() below
494497 // will effectively be using stale data.
495 - if ( $wgUser->getName() === $this->mUsername ) {
 498+ if ( $this->getUser()->getName() === $this->mUsername ) {
496499 wfDebug( __METHOD__ . ": already logged in as {$this->mUsername}\n" );
497500 return self::SUCCESS;
498501 }
@@ -572,7 +575,7 @@
573576 // This should set it for OutputPage and the Skin
574577 // which is needed or the personal links will be
575578 // wrong.
576 - RequestContext::getMain()->setUser( $u );
 579+ $this->getContext()->setUser( $u );
577580
578581 // Please reset throttle for successful logins, thanks!
579582 if ( $throttleCount ) {
@@ -581,7 +584,7 @@
582585
583586 if ( $isAutoCreated ) {
584587 // Must be run after $wgUser is set, for correct new user log
585 - wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
 588+ wfRunHooks( 'AuthPluginAutoCreate', array( $u ) );
586589 }
587590
588591 $retval = self::SUCCESS;
@@ -641,9 +644,9 @@
642645 * @return integer Status code
643646 */
644647 function attemptAutoCreate( $user ) {
645 - global $wgAuth, $wgUser, $wgAutocreatePolicy;
 648+ global $wgAuth, $wgAutocreatePolicy;
646649
647 - if ( $wgUser->isBlockedFromCreateAccount() ) {
 650+ if ( $this->getUser()->isBlockedFromCreateAccount() ) {
648651 wfDebug( __METHOD__ . ": user is blocked from account creation\n" );
649652 return self::CREATE_BLOCKED;
650653 }
@@ -691,31 +694,34 @@
692695 }
693696
694697 function processLogin() {
695 - global $wgUser, $wgRequest, $wgLang;
 698+ global $wgMemc, $wgLang;
696699
697700 switch ( $this->authenticateUserData() ) {
698701 case self::SUCCESS:
699702 # We've verified now, update the real record
700 - if( (bool)$this->mRemember != (bool)$wgUser->getOption( 'rememberpassword' ) ) {
701 - $wgUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
702 - $wgUser->saveSettings();
 703+ $user = $this->getUser();
 704+ if( (bool)$this->mRemember != (bool)$user->getOption( 'rememberpassword' ) ) {
 705+ $user->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
 706+ $user->saveSettings();
703707 } else {
704 - $wgUser->invalidateCache();
 708+ $user->invalidateCache();
705709 }
706 - $wgUser->setCookies();
 710+ $user->setCookies();
707711 self::clearLoginToken();
708712
709713 // Reset the throttle
710 - $key = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $this->mUsername ) );
711 - global $wgMemc;
 714+ $request = $this->getRequest();
 715+ $key = wfMemcKey( 'password-throttle', $request->getIP(), md5( $this->mUsername ) );
712716 $wgMemc->delete( $key );
713717
714718 if( $this->hasSessionCookie() || $this->mSkipCookieCheck ) {
715719 /* Replace the language object to provide user interface in
716720 * correct language immediately on this first page load.
717721 */
718 - $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
719 - $wgLang = Language::factory( $code );
 722+ $code = $request->getVal( 'uselang', $user->getOption( 'language' ) );
 723+ $userLang = Language::factory( $code );
 724+ $wgLang = $userLang;
 725+ $this->getContext()->setLang( $userLang );
720726 return $this->successfulLogin();
721727 } else {
722728 return $this->cookieRedirectCheck( 'login' );
@@ -723,48 +729,48 @@
724730 break;
725731
726732 case self::NEED_TOKEN:
727 - $this->mainLoginForm( wfMsgExt( 'nocookiesforlogin', array( 'parseinline' ) ) );
 733+ $this->mainLoginForm( $this->msg( 'nocookiesforlogin' )->parse() );
728734 break;
729735 case self::WRONG_TOKEN:
730 - $this->mainLoginForm( wfMsg( 'sessionfailure' ) );
 736+ $this->mainLoginForm( $this->msg( 'sessionfailure' )->text() );
731737 break;
732738 case self::NO_NAME:
733739 case self::ILLEGAL:
734 - $this->mainLoginForm( wfMsg( 'noname' ) );
 740+ $this->mainLoginForm( $this->msg( 'noname' )->text() );
735741 break;
736742 case self::WRONG_PLUGIN_PASS:
737 - $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
 743+ $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() );
738744 break;
739745 case self::NOT_EXISTS:
740 - if( $wgUser->isAllowed( 'createaccount' ) ) {
741 - $this->mainLoginForm( wfMsgExt( 'nosuchuser', 'parseinline',
742 - wfEscapeWikiText( $this->mUsername ) ) );
 746+ if( $this->getUser()->isAllowed( 'createaccount' ) ) {
 747+ $this->mainLoginForm( $this->msg( 'nosuchuser',
 748+ wfEscapeWikiText( $this->mUsername ) )->parse() );
743749 } else {
744 - $this->mainLoginForm( wfMsg( 'nosuchusershort',
745 - wfEscapeWikiText( $this->mUsername ) ) );
 750+ $this->mainLoginForm( $this->msg( 'nosuchusershort',
 751+ wfEscapeWikiText( $this->mUsername ) )->text() );
746752 }
747753 break;
748754 case self::WRONG_PASS:
749 - $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
 755+ $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() );
750756 break;
751757 case self::EMPTY_PASS:
752 - $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
 758+ $this->mainLoginForm( $this->msg( 'wrongpasswordempty' )->text() );
753759 break;
754760 case self::RESET_PASS:
755 - $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
 761+ $this->resetLoginForm( $this->msg( 'resetpass_announce' )->text() );
756762 break;
757763 case self::CREATE_BLOCKED:
758 - $this->userBlockedMessage( $wgUser->mBlock );
 764+ $this->userBlockedMessage( $this->getUser()->mBlock );
759765 break;
760766 case self::THROTTLED:
761 - $this->mainLoginForm( wfMsg( 'login-throttled' ) );
 767+ $this->mainLoginForm( $this->msg( 'login-throttled' )->text() );
762768 break;
763769 case self::USER_BLOCKED:
764 - $this->mainLoginForm( wfMsgExt( 'login-userblocked',
765 - array( 'parsemag', 'escape' ), $this->mUsername ) );
 770+ $this->mainLoginForm( $this->msg( 'login-userblocked',
 771+ $this->mUsername )->escaped() );
766772 break;
767773 case self::ABORTED:
768 - $this->mainLoginForm( wfMsg( $this->mAbortLoginErrorMsg ) );
 774+ $this->mainLoginForm( $this->msg( $this->mAbortLoginErrorMsg )->text() );
769775 break;
770776 default:
771777 throw new MWException( 'Unhandled case value' );
@@ -772,9 +778,9 @@
773779 }
774780
775781 function resetLoginForm( $error ) {
776 - global $wgOut;
777 - $wgOut->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) );
 782+ $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) );
778783 $reset = new SpecialChangePassword();
 784+ $reset->setContext( $this );
779785 $reset->execute( null );
780786 }
781787
@@ -786,25 +792,26 @@
787793 * @return Status object
788794 */
789795 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
790 - global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry, $wgRequest;
 796+ global $wgServer, $wgScript, $wgNewPasswordExpiry;
791797
792798 if ( $u->getEmail() == '' ) {
793799 return Status::newFatal( 'noemail', $u->getName() );
794800 }
795 - $ip = $wgRequest->getIP();
 801+ $ip = $this->getRequest()->getIP();
796802 if( !$ip ) {
797803 return Status::newFatal( 'badipaddress' );
798804 }
799805
800 - wfRunHooks( 'User::mailPasswordInternal', array( &$wgUser, &$ip, &$u ) );
 806+ $currentUser = $this->getUser();
 807+ wfRunHooks( 'User::mailPasswordInternal', array( &$currentUser, &$ip, &$u ) );
801808
802809 $np = $u->randomPassword();
803810 $u->setNewpassword( $np, $throttle );
804811 $u->saveSettings();
805812 $userLanguage = $u->getOption( 'language' );
806 - $m = wfMsgExt( $emailText, array( 'parsemag', 'language' => $userLanguage ), $ip, $u->getName(), $np,
807 - $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 ) );
808 - $result = $u->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $userLanguage ) ), $m );
 813+ $m = $this->msg( $emailText, $ip, $u->getName(), $np, $wgServer . $wgScript,
 814+ round( $wgNewPasswordExpiry / 86400 ) )->inLanguage( $userLanguage )->text();
 815+ $result = $u->sendMail( $this->msg( $emailTitle )->inLanguage( $userLanguage )->text(), $m );
809816
810817 return $result;
811818 }
@@ -821,11 +828,10 @@
822829 * @private
823830 */
824831 function successfulLogin() {
825 - global $wgUser, $wgOut;
826 -
827832 # Run any hooks; display injected HTML if any, else redirect
 833+ $currentUser = $this->getUser();
828834 $injected_html = '';
829 - wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
 835+ wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
830836
831837 if( $injected_html !== '' ) {
832838 $this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
@@ -839,7 +845,7 @@
840846 if( $wgSecureLogin && !$this->mStickHTTPS ) {
841847 $redirectUrl = preg_replace( '/^https:/', 'http:', $redirectUrl );
842848 }
843 - $wgOut->redirect( $redirectUrl );
 849+ $this->getOutput()->redirect( $redirectUrl );
844850 }
845851 }
846852
@@ -850,12 +856,12 @@
851857 * @private
852858 */
853859 function successfulCreation() {
854 - global $wgUser;
855860 # Run any hooks; display injected HTML
 861+ $currentUser = $this->getUser();
856862 $injected_html = '';
857863 $welcome_creation_msg = 'welcomecreation';
858864
859 - wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
 865+ wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
860866
861867 //let any extensions change what message is shown
862868 wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
@@ -867,19 +873,18 @@
868874 * Display a "login successful" page.
869875 */
870876 private function displaySuccessfulLogin( $msgname, $injected_html ) {
871 - global $wgOut, $wgUser;
872 -
873 - $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
 877+ $out = $this->getOutput();
 878+ $out->setPageTitle( $this->msg( 'loginsuccesstitle' )->text() );
874879 if( $msgname ){
875 - $wgOut->addWikiMsg( $msgname, wfEscapeWikiText( $wgUser->getName() ) );
 880+ $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
876881 }
877882
878 - $wgOut->addHTML( $injected_html );
 883+ $out->addHTML( $injected_html );
879884
880885 if ( !empty( $this->mReturnTo ) ) {
881 - $wgOut->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery );
 886+ $out->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery );
882887 } else {
883 - $wgOut->returnToMain( null );
 888+ $out->returnToMain( null );
884889 }
885890 }
886891
@@ -891,8 +896,6 @@
892897 * @param $block Block the block causing this error
893898 */
894899 function userBlockedMessage( Block $block ) {
895 - global $wgOut;
896 -
897900 # Let's be nice about this, it's likely that this feature will be used
898901 # for blocking large numbers of innocent people, e.g. range blocks on
899902 # schools. Don't blame it on the user. There's a small chance that it
@@ -901,56 +904,56 @@
902905 # evade it, but we'll leave that to their guilty conscience to figure
903906 # out.
904907
905 - $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
 908+ $out = $this->getOutput();
 909+ $out->setPageTitle( $this->msg( 'cantcreateaccounttitle' )->text() );
906910
907911 $block_reason = $block->mReason;
908912 if ( strval( $block_reason ) === '' ) {
909 - $block_reason = wfMsg( 'blockednoreason' );
 913+ $block_reason = $this->msg( 'blockednoreason' )->text();
910914 }
911915
912 - $wgOut->addWikiMsg(
 916+ $out->addWikiMsg(
913917 'cantcreateaccount-text',
914918 $block->getTarget(),
915919 $block_reason,
916920 $block->getBlocker()->getName()
917921 );
918922
919 - $wgOut->returnToMain( false );
 923+ $out->returnToMain( false );
920924 }
921925
922926 /**
923927 * @private
924928 */
925929 function mainLoginForm( $msg, $msgtype = 'error' ) {
926 - global $wgUser, $wgOut, $wgHiddenPrefs;
927930 global $wgEnableEmail, $wgEnableUserEmail;
928 - global $wgRequest, $wgLoginLanguageSelector;
 931+ global $wgHiddenPrefs, $wgLoginLanguageSelector;
929932 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
930933 global $wgSecureLogin, $wgPasswordResetRoutes;
931934
932 - $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
 935+ $titleObj = $this->getTitle();
 936+ $user = $this->getUser();
933937
934938 if ( $this->mType == 'signup' ) {
935939 // Block signup here if in readonly. Keeps user from
936940 // going through the process (filling out data, etc)
937941 // and being informed later.
938942 if ( wfReadOnly() ) {
939 - $wgOut->readOnlyPage();
 943+ throw new ReadOnlyError;
 944+ } elseif ( $user->isBlockedFromCreateAccount() ) {
 945+ $this->userBlockedMessage( $user->isBlockedFromCreateAccount() );
940946 return;
941 - } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
942 - $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() );
 947+ } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $user, true ) )>0 ) {
 948+ $this->getOutput()->showPermissionsErrorPage( $permErrors, 'createaccount' );
943949 return;
944 - } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
945 - $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
946 - return;
947950 }
948951 }
949952
950953 if ( $this->mUsername == '' ) {
951 - if ( $wgUser->isLoggedIn() ) {
952 - $this->mUsername = $wgUser->getName();
 954+ if ( $user->isLoggedIn() ) {
 955+ $this->mUsername = $user->getName();
953956 } else {
954 - $this->mUsername = $wgRequest->getCookie( 'UserName' );
 957+ $this->mUsername = $this->getRequest()->getCookie( 'UserName' );
955958 }
956959 }
957960
@@ -976,18 +979,16 @@
977980 $linkq .= $returnto;
978981 }
979982
980 - # Pass any language selection on to the mode switch link
981 - if( $wgLoginLanguageSelector && $this->mLanguage ) {
982 - $linkq .= '&uselang=' . $this->mLanguage;
983 - }
984 -
985 - $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalURL( $linkq ) ) . '">';
986 - $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
987 - $link .= '</a>';
988 -
989983 # Don't show a "create account" link if the user can't
990 - if( $this->showCreateOrLoginLink( $wgUser ) ) {
991 - $template->set( 'link', wfMsgExt( $linkmsg, array( 'parseinline', 'replaceafter' ), $link ) );
 984+ if( $this->showCreateOrLoginLink( $user ) ) {
 985+ # Pass any language selection on to the mode switch link
 986+ if( $wgLoginLanguageSelector && $this->mLanguage ) {
 987+ $linkq .= '&uselang=' . $this->mLanguage;
 988+ }
 989+ $link = Html::element( 'a', array( 'href' => $titleObj->getLocalURL( $linkq ) ),
 990+ $this->msg( $linkmsg . 'link' )->text() ); # Calling either 'gotaccountlink' or 'nologinlink'
 991+
 992+ $template->set( 'link', $this->msg( $linkmsg )->rawParams( $link )->parse() );
992993 } else {
993994 $template->set( 'link', '' );
994995 }
@@ -1008,7 +1009,7 @@
10091010 $template->set( 'action', $titleObj->getLocalURL( $q ) );
10101011 $template->set( 'message', $msg );
10111012 $template->set( 'messagetype', $msgtype );
1012 - $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
 1013+ $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
10131014 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) );
10141015 $template->set( 'useemail', $wgEnableEmail );
10151016 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
@@ -1016,8 +1017,8 @@
10171018 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
10181019 $template->set( 'resetlink', $resetLink );
10191020 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
1020 - $template->set( 'usereason', $wgUser->isLoggedIn() );
1021 - $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) || $this->mRemember );
 1021+ $template->set( 'usereason', $user->isLoggedIn() );
 1022+ $template->set( 'remember', $user->getOption( 'rememberpassword' ) || $this->mRemember );
10221023 $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
10231024 $template->set( 'stickHTTPS', $this->mStickHTTPS );
10241025
@@ -1043,17 +1044,17 @@
10441045 // Use loginend-https for HTTPS requests if it's not blank, loginend otherwise
10451046 // Ditto for signupend
10461047 $usingHTTPS = WebRequest::detectProtocol() == 'https';
1047 - $loginendHTTPS = wfMessage( 'loginend-https' );
1048 - $signupendHTTPS = wfMessage( 'signupend-https' );
 1048+ $loginendHTTPS = $this->msg( 'loginend-https' );
 1049+ $signupendHTTPS = $this->msg( 'signupend-https' );
10491050 if ( $usingHTTPS && !$loginendHTTPS->isBlank() ) {
10501051 $template->set( 'loginend', $loginendHTTPS->parse() );
10511052 } else {
1052 - $template->set( 'loginend', wfMessage( 'loginend' )->parse() );
 1053+ $template->set( 'loginend', $this->msg( 'loginend' )->parse() );
10531054 }
10541055 if ( $usingHTTPS && !$signupendHTTPS->isBlank() ) {
10551056 $template->set( 'signupend', $signupendHTTPS->parse() );
10561057 } else {
1057 - $template->set( 'signupend', wfMessage( 'signupend' )->parse() );
 1058+ $template->set( 'signupend', $this->msg( 'signupend' )->parse() );
10581059 }
10591060
10601061 // Give authentication and captcha plugins a chance to modify the form
@@ -1065,14 +1066,15 @@
10661067 }
10671068
10681069 // Changes the title depending on permissions for creating account
1069 - if ( $wgUser->isAllowed( 'createaccount' ) ) {
1070 - $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
 1070+ $out = $this->getOutput();
 1071+ if ( $user->isAllowed( 'createaccount' ) ) {
 1072+ $out->setPageTitle( $this->msg( 'userlogin' )->text() );
10711073 } else {
1072 - $wgOut->setPageTitle( wfMsg( 'userloginnocreate' ) );
 1074+ $out->setPageTitle( $this->msg( 'userloginnocreate' )->text() );
10731075 }
10741076
1075 - $wgOut->disallowUserJs(); // just in case...
1076 - $wgOut->addTemplate( $template );
 1077+ $out->disallowUserJs(); // just in case...
 1078+ $out->addTemplate( $template );
10771079 }
10781080
10791081 /**
@@ -1102,8 +1104,8 @@
11031105 * @private
11041106 */
11051107 function hasSessionCookie() {
1106 - global $wgDisableCookieCheck, $wgRequest;
1107 - return $wgDisableCookieCheck ? true : $wgRequest->checkSessionCookie();
 1108+ global $wgDisableCookieCheck;
 1109+ return $wgDisableCookieCheck ? true : $this->getRequest()->checkSessionCookie();
11081110 }
11091111
11101112 /**
@@ -1160,8 +1162,6 @@
11611163 * @private
11621164 */
11631165 function cookieRedirectCheck( $type ) {
1164 - global $wgOut;
1165 -
11661166 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
11671167 $query = array( 'wpCookieCheck' => $type );
11681168 if ( $this->mReturnTo ) {
@@ -1169,7 +1169,7 @@
11701170 }
11711171 $check = $titleObj->getFullURL( $query );
11721172
1173 - return $wgOut->redirect( $check );
 1173+ return $this->getOutput()->redirect( $check );
11741174 }
11751175
11761176 /**
@@ -1178,12 +1178,12 @@
11791179 function onCookieRedirectCheck( $type ) {
11801180 if ( !$this->hasSessionCookie() ) {
11811181 if ( $type == 'new' ) {
1182 - return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
 1182+ return $this->mainLoginForm( $this->msg( 'nocookiesnew' )->parse() );
11831183 } elseif ( $type == 'login' ) {
1184 - return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
 1184+ return $this->mainLoginForm( $this->msg( 'nocookieslogin' )->parse() );
11851185 } else {
11861186 # shouldn't happen
1187 - return $this->mainLoginForm( wfMsg( 'error' ) );
 1187+ return $this->mainLoginForm( $this->msg( 'error' )->text() );
11881188 }
11891189 } else {
11901190 return $this->successfulLogin();
@@ -1194,7 +1194,7 @@
11951195 * @private
11961196 */
11971197 function throttleHit( $limit ) {
1198 - $this->mainLoginForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $limit ) );
 1198+ $this->mainLoginForm( $this->msg( 'acct_creation_throttle_hit' )->numParams( $limit )->parse() );
11991199 }
12001200
12011201 /**
@@ -1204,9 +1204,7 @@
12051205 * @return string
12061206 */
12071207 function makeLanguageSelector() {
1208 - global $wgLang;
1209 -
1210 - $msg = wfMessage( 'loginlanguagelinks' )->inContentLanguage();
 1208+ $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
12111209 if( !$msg->isBlank() ) {
12121210 $langs = explode( "\n", $msg->text() );
12131211 $links = array();
@@ -1217,7 +1215,8 @@
12181216 $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
12191217 }
12201218 }
1221 - return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', $wgLang->pipeList( $links ) ) : '';
 1219+ return count( $links ) > 0 ? $this->msg( 'loginlanguagelabel' )->rawParams(
 1220+ $this->getLang()->pipeList( $links ) )->escaped() : '';
12221221 } else {
12231222 return '';
12241223 }
@@ -1231,7 +1230,6 @@
12321231 * @param $lang Language code
12331232 */
12341233 function makeLanguageSelectorLink( $text, $lang ) {
1235 - $self = SpecialPage::getTitleFor( 'Userlogin' );
12361234 $attr = array( 'uselang' => $lang );
12371235 if( $this->mType == 'signup' ) {
12381236 $attr['type'] = 'signup';
@@ -1240,7 +1238,7 @@
12411239 $attr['returnto'] = $this->mReturnTo;
12421240 }
12431241 return Linker::linkKnown(
1244 - $self,
 1242+ $this->getTitle(),
12451243 htmlspecialchars( $text ),
12461244 array(),
12471245 $attr

Follow-up revisions

RevisionCommit summaryAuthorDate
r100140Fix for r100114: make API and tests work againialex18:07, 18 October 2011
r113099Special pages aren't a contextsource. Ping r100114, pass $this->getContext()reedy22:43, 5 March 2012

Comments

#Comment by 😂 (talk | contribs)   17:15, 18 October 2011

This broke API logins beginning with build #207

#Comment by IAlex (talk | contribs)   18:08, 18 October 2011

Fixed in r100140.

Status & tagging log