From fe8ab5a01d6b340773ff2b41c4f34e1835d06fdb Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 18 Oct 2011 14:08:48 +0000 Subject: [PATCH] * Use local context instead of global variables * Pass the context between Special:Userlogin and Special:ChangePassword when calling the other one --- includes/specials/SpecialChangePassword.php | 1 + includes/specials/SpecialUserlogin.php | 332 ++++++++++---------- 2 files changed, 166 insertions(+), 167 deletions(-) diff --git a/includes/specials/SpecialChangePassword.php b/includes/specials/SpecialChangePassword.php index f87aa0e8da..2e2be557ef 100644 --- a/includes/specials/SpecialChangePassword.php +++ b/includes/specials/SpecialChangePassword.php @@ -91,6 +91,7 @@ class SpecialChangePassword extends UnlistedSpecialPage { $data['wpRemember'] = 1; } $login = new LoginForm( new FauxRequest( $data, true ) ); + $login->setContext( $this->getContext() ); $login->execute( null ); } $this->doReturnTo(); diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 9ad513d986..9dfc3ce74b 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -55,18 +55,18 @@ class LoginForm extends SpecialPage { */ private $mExtUser = null; + /** + * @ var WebRequest + */ + private $mOverrideRequest = null; + /** * @param WebRequest $request */ public function __construct( $request = null ) { parent::__construct( 'Userlogin' ); - if ( $request === null ) { - global $wgRequest; - $this->load( $wgRequest ); - } else { - $this->load( $request ); - } + $this->mOverrideRequest = $request; } /** @@ -132,6 +132,13 @@ class LoginForm extends SpecialPage { wfSetupSession(); } + if ( $this->mOverrideRequest === null ) { + $request = $this->getRequest(); + } else { + $request = $this->mOverrideRequest; + } + $this->load( $request ); + if ( $par == 'signup' ) { # Check for [[Special:Userlogin/signup]] $this->mType = 'signup'; } @@ -155,10 +162,8 @@ class LoginForm extends SpecialPage { * @private */ function addNewAccountMailPassword() { - global $wgOut; - if ( $this->mEmail == '' ) { - $this->mainLoginForm( wfMsgExt( 'noemailcreate', array( 'parsemag', 'escape' ) ) ); + $this->mainLoginForm( $this->msg( 'noemailcreate' )->escaped() ); return; } @@ -176,13 +181,14 @@ class LoginForm extends SpecialPage { wfRunHooks( 'AddNewAccount', array( $u, true ) ); $u->addNewUserLogEntry( true, $this->mReason ); - $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) ); + $out = $this->getOutput(); + $out->setPageTitle( $this->msg( 'accmailtitle' )->text() ); if( !$result->isGood() ) { - $this->mainLoginForm( wfMsg( 'mailerror', $result->getWikiText() ) ); + $this->mainLoginForm( $this->msg( 'mailerror', $result->getWikiText() )->text() ); } else { - $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() ); - $wgOut->returnToMain( false ); + $out->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() ); + $out->returnToMain( false ); } } @@ -190,7 +196,7 @@ class LoginForm extends SpecialPage { * @private */ function addNewAccount() { - global $wgUser, $wgEmailAuthentication, $wgOut; + global $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector; # Create the account and abort if there's a problem doing so $u = $this->addNewAccountInternal(); @@ -200,18 +206,19 @@ class LoginForm extends SpecialPage { # If we showed up language selection links, and one was in use, be # smart (and sensible) and save that language as the user's preference - global $wgLoginLanguageSelector; if( $wgLoginLanguageSelector && $this->mLanguage ) { $u->setOption( 'language', $this->mLanguage ); } + $out = $this->getOutput(); + # Send out an email authentication message if needed if( $wgEmailAuthentication && Sanitizer::validateEmail( $u->getEmail() ) ) { $status = $u->sendConfirmationMail(); if( $status->isGood() ) { - $wgOut->addWikiMsg( 'confirmemail_oncreate' ); + $out->addWikiMsg( 'confirmemail_oncreate' ); } else { - $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); + $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); } } @@ -221,15 +228,15 @@ class LoginForm extends SpecialPage { # If not logged in, assume the new account as the current one and set # session cookies then show a "welcome" message or a "need cookies" # message as needed - if( $wgUser->isAnon() ) { + if( $this->getUser()->isAnon() ) { + $u->setCookies(); $wgUser = $u; - $wgUser->setCookies(); // This should set it for OutputPage and the Skin // which is needed or the personal links will be // wrong. - RequestContext::getMain()->setUser( $u ); - wfRunHooks( 'AddNewAccount', array( $wgUser, false ) ); - $wgUser->addNewUserLogEntry(); + $this->getContext()->setUser( $u ); + wfRunHooks( 'AddNewAccount', array( $u, false ) ); + $u->addNewUserLogEntry(); if( $this->hasSessionCookie() ) { return $this->successfulCreation(); } else { @@ -237,10 +244,9 @@ class LoginForm extends SpecialPage { } } else { # Confirm that the account was created - $self = SpecialPage::getTitleFor( 'Userlogin' ); - $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) ); - $wgOut->addWikiMsg( 'accountcreatedtext', $u->getName() ); - $wgOut->returnToMain( false, $self ); + $out->setPageTitle( $this->msg( 'accountcreated' )->text() ); + $out->addWikiMsg( 'accountcreatedtext', $u->getName() ); + $out->returnToMain( false, $this->getTitle() ); wfRunHooks( 'AddNewAccount', array( $u, false ) ); $u->addNewUserLogEntry( false, $this->mReason ); return true; @@ -251,14 +257,12 @@ class LoginForm extends SpecialPage { * @private */ function addNewAccountInternal() { - global $wgUser, $wgOut, $wgRequest; - global $wgMemc, $wgAccountCreationThrottle; - global $wgAuth, $wgMinimalPasswordLength; - global $wgEmailConfirmToEdit; + global $wgAuth, $wgMemc, $wgAccountCreationThrottle, + $wgMinimalPasswordLength, $wgEmailConfirmToEdit; // If the user passes an invalid domain, something is fishy if( !$wgAuth->validDomain( $this->mDomain ) ) { - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); + $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() ); return false; } @@ -270,47 +274,46 @@ class LoginForm extends SpecialPage { if( 'local' != $this->mDomain && $this->mDomain != '' ) { if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mUsername ) || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) { - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); + $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() ); return false; } } if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return false; + throw new ReadOnlyError; } # Request forgery checks. if ( !self::getCreateaccountToken() ) { self::setCreateaccountToken(); - $this->mainLoginForm( wfMsgExt( 'nocookiesfornew', array( 'parseinline' ) ) ); + $this->mainLoginForm( $this->msg( 'nocookiesfornew' )->parse() ); return false; } # The user didn't pass a createaccount token if ( !$this->mToken ) { - $this->mainLoginForm( wfMsg( 'sessionfailure' ) ); + $this->mainLoginForm( $this->msg( 'sessionfailure' )->text() ); return false; } # Validate the createaccount token if ( $this->mToken !== self::getCreateaccountToken() ) { - $this->mainLoginForm( wfMsg( 'sessionfailure' ) ); + $this->mainLoginForm( $this->msg( 'sessionfailure' )->text() ); return false; } # Check permissions - if ( !$wgUser->isAllowed( 'createaccount' ) ) { - $wgOut->permissionRequired( 'createaccount' ); - return false; - } elseif ( $wgUser->isBlockedFromCreateAccount() ) { - $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); + $currentUser = $this->getUser(); + if ( !$currentUser->isAllowed( 'createaccount' ) ) { + throw new PermissionsError( 'createaccount' ); + } elseif ( $currentUser->isBlockedFromCreateAccount() ) { + $this->userBlockedMessage( $currentUser->isBlockedFromCreateAccount() ); return false; } - $ip = $wgRequest->getIP(); - if ( $wgUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) { - $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' ); + $ip = $this->getRequest()->getIP(); + if ( $currentUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) { + $this->mainLoginForm( $this->msg( 'sorbs_create_account_reason' )->text() . ' (' . htmlspecialchars( $ip ) . ')' ); return false; } @@ -318,17 +321,17 @@ class LoginForm extends SpecialPage { $name = trim( $this->mUsername ); $u = User::newFromName( $name, 'creatable' ); if ( !is_object( $u ) ) { - $this->mainLoginForm( wfMsg( 'noname' ) ); + $this->mainLoginForm( $this->msg( 'noname' )->text() ); return false; } if ( 0 != $u->idForName() ) { - $this->mainLoginForm( wfMsg( 'userexists' ) ); + $this->mainLoginForm( $this->msg( 'userexists' )->text() ); return false; } if ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) { - $this->mainLoginForm( wfMsg( 'badretype' ) ); + $this->mainLoginForm( $this->msg( 'badretype' )->text() ); return false; } @@ -343,7 +346,7 @@ class LoginForm extends SpecialPage { $message = $valid; $params = array( $wgMinimalPasswordLength ); } - $this->mainLoginForm( wfMsgExt( $message, array( 'parsemag' ), $params ) ); + $this->mainLoginForm( $this->msg( $message, $params )->text() ); return false; } else { # do not force a password for account creation by email @@ -355,12 +358,12 @@ class LoginForm extends SpecialPage { # if you need a confirmed email address to edit, then obviously you # need an email address. if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) { - $this->mainLoginForm( wfMsg( 'noemailtitle' ) ); + $this->mainLoginForm( $this->msg( 'noemailtitle' )->text() ); return false; } if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) { - $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) ); + $this->mainLoginForm( $this->msg( 'invalidemailaddress' )->text() ); return false; } @@ -381,7 +384,7 @@ class LoginForm extends SpecialPage { if ( !wfRunHooks( 'exemptFromAccountCreationThrottle', array( $ip ) ) ) { wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook allowed account creation w/o throttle\n" ); } else { - if ( ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) ) { + if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) { $key = wfMemcKey( 'acctcreate', 'ip', $ip ); $value = $wgMemc->get( $key ); if ( !$value ) { @@ -396,7 +399,7 @@ class LoginForm extends SpecialPage { } if( !$wgAuth->addUser( $u, $this->mPassword, $this->mEmail, $this->mRealName ) ) { - $this->mainLoginForm( wfMsg( 'externaldberror' ) ); + $this->mainLoginForm( $this->msg( 'externaldberror' )->text() ); return false; } @@ -485,13 +488,13 @@ class LoginForm extends SpecialPage { return self::WRONG_TOKEN; } - // Load $wgUser now, and check to see if we're logging in as the same - // name. This is necessary because loading $wgUser (say by calling - // getName()) calls the UserLoadFromSession hook, which potentially - // creates the user in the database. Until we load $wgUser, checking - // for user existence using User::newFromName($name)->getId() below + // Load the current user now, and check to see if we're logging in as + // the same name. This is necessary because loading the current user + // (say by calling getName()) calls the UserLoadFromSession hook, which + // potentially creates the user in the database. Until we load $wgUser, + // checking for user existence using User::newFromName($name)->getId() below // will effectively be using stale data. - if ( $wgUser->getName() === $this->mUsername ) { + if ( $this->getUser()->getName() === $this->mUsername ) { wfDebug( __METHOD__ . ": already logged in as {$this->mUsername}\n" ); return self::SUCCESS; } @@ -572,7 +575,7 @@ class LoginForm extends SpecialPage { // This should set it for OutputPage and the Skin // which is needed or the personal links will be // wrong. - RequestContext::getMain()->setUser( $u ); + $this->getContext()->setUser( $u ); // Please reset throttle for successful logins, thanks! if ( $throttleCount ) { @@ -581,7 +584,7 @@ class LoginForm extends SpecialPage { if ( $isAutoCreated ) { // Must be run after $wgUser is set, for correct new user log - wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) ); + wfRunHooks( 'AuthPluginAutoCreate', array( $u ) ); } $retval = self::SUCCESS; @@ -641,9 +644,9 @@ class LoginForm extends SpecialPage { * @return integer Status code */ function attemptAutoCreate( $user ) { - global $wgAuth, $wgUser, $wgAutocreatePolicy; + global $wgAuth, $wgAutocreatePolicy; - if ( $wgUser->isBlockedFromCreateAccount() ) { + if ( $this->getUser()->isBlockedFromCreateAccount() ) { wfDebug( __METHOD__ . ": user is blocked from account creation\n" ); return self::CREATE_BLOCKED; } @@ -691,31 +694,34 @@ class LoginForm extends SpecialPage { } function processLogin() { - global $wgUser, $wgRequest, $wgLang; + global $wgMemc, $wgLang; switch ( $this->authenticateUserData() ) { case self::SUCCESS: # We've verified now, update the real record - if( (bool)$this->mRemember != (bool)$wgUser->getOption( 'rememberpassword' ) ) { - $wgUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 ); - $wgUser->saveSettings(); + $user = $this->getUser(); + if( (bool)$this->mRemember != (bool)$user->getOption( 'rememberpassword' ) ) { + $user->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 ); + $user->saveSettings(); } else { - $wgUser->invalidateCache(); + $user->invalidateCache(); } - $wgUser->setCookies(); + $user->setCookies(); self::clearLoginToken(); // Reset the throttle - $key = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $this->mUsername ) ); - global $wgMemc; + $request = $this->getRequest(); + $key = wfMemcKey( 'password-throttle', $request->getIP(), md5( $this->mUsername ) ); $wgMemc->delete( $key ); if( $this->hasSessionCookie() || $this->mSkipCookieCheck ) { /* Replace the language object to provide user interface in * correct language immediately on this first page load. */ - $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) ); - $wgLang = Language::factory( $code ); + $code = $request->getVal( 'uselang', $user->getOption( 'language' ) ); + $userLang = Language::factory( $code ); + $wgLang = $userLang; + $this->getContext()->setLang( $userLang ); return $this->successfulLogin(); } else { return $this->cookieRedirectCheck( 'login' ); @@ -723,48 +729,48 @@ class LoginForm extends SpecialPage { break; case self::NEED_TOKEN: - $this->mainLoginForm( wfMsgExt( 'nocookiesforlogin', array( 'parseinline' ) ) ); + $this->mainLoginForm( $this->msg( 'nocookiesforlogin' )->parse() ); break; case self::WRONG_TOKEN: - $this->mainLoginForm( wfMsg( 'sessionfailure' ) ); + $this->mainLoginForm( $this->msg( 'sessionfailure' )->text() ); break; case self::NO_NAME: case self::ILLEGAL: - $this->mainLoginForm( wfMsg( 'noname' ) ); + $this->mainLoginForm( $this->msg( 'noname' )->text() ); break; case self::WRONG_PLUGIN_PASS: - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); + $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() ); break; case self::NOT_EXISTS: - if( $wgUser->isAllowed( 'createaccount' ) ) { - $this->mainLoginForm( wfMsgExt( 'nosuchuser', 'parseinline', - wfEscapeWikiText( $this->mUsername ) ) ); + if( $this->getUser()->isAllowed( 'createaccount' ) ) { + $this->mainLoginForm( $this->msg( 'nosuchuser', + wfEscapeWikiText( $this->mUsername ) )->parse() ); } else { - $this->mainLoginForm( wfMsg( 'nosuchusershort', - wfEscapeWikiText( $this->mUsername ) ) ); + $this->mainLoginForm( $this->msg( 'nosuchusershort', + wfEscapeWikiText( $this->mUsername ) )->text() ); } break; case self::WRONG_PASS: - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); + $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() ); break; case self::EMPTY_PASS: - $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) ); + $this->mainLoginForm( $this->msg( 'wrongpasswordempty' )->text() ); break; case self::RESET_PASS: - $this->resetLoginForm( wfMsg( 'resetpass_announce' ) ); + $this->resetLoginForm( $this->msg( 'resetpass_announce' )->text() ); break; case self::CREATE_BLOCKED: - $this->userBlockedMessage( $wgUser->mBlock ); + $this->userBlockedMessage( $this->getUser()->mBlock ); break; case self::THROTTLED: - $this->mainLoginForm( wfMsg( 'login-throttled' ) ); + $this->mainLoginForm( $this->msg( 'login-throttled' )->text() ); break; case self::USER_BLOCKED: - $this->mainLoginForm( wfMsgExt( 'login-userblocked', - array( 'parsemag', 'escape' ), $this->mUsername ) ); + $this->mainLoginForm( $this->msg( 'login-userblocked', + $this->mUsername )->escaped() ); break; case self::ABORTED: - $this->mainLoginForm( wfMsg( $this->mAbortLoginErrorMsg ) ); + $this->mainLoginForm( $this->msg( $this->mAbortLoginErrorMsg )->text() ); break; default: throw new MWException( 'Unhandled case value' ); @@ -772,9 +778,9 @@ class LoginForm extends SpecialPage { } function resetLoginForm( $error ) { - global $wgOut; - $wgOut->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) ); + $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) ); $reset = new SpecialChangePassword(); + $reset->setContext( $this ); $reset->execute( null ); } @@ -786,25 +792,26 @@ class LoginForm extends SpecialPage { * @return Status object */ function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) { - global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry, $wgRequest; + global $wgServer, $wgScript, $wgNewPasswordExpiry; if ( $u->getEmail() == '' ) { return Status::newFatal( 'noemail', $u->getName() ); } - $ip = $wgRequest->getIP(); + $ip = $this->getRequest()->getIP(); if( !$ip ) { return Status::newFatal( 'badipaddress' ); } - wfRunHooks( 'User::mailPasswordInternal', array( &$wgUser, &$ip, &$u ) ); + $currentUser = $this->getUser(); + wfRunHooks( 'User::mailPasswordInternal', array( &$currentUser, &$ip, &$u ) ); $np = $u->randomPassword(); $u->setNewpassword( $np, $throttle ); $u->saveSettings(); $userLanguage = $u->getOption( 'language' ); - $m = wfMsgExt( $emailText, array( 'parsemag', 'language' => $userLanguage ), $ip, $u->getName(), $np, - $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 ) ); - $result = $u->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $userLanguage ) ), $m ); + $m = $this->msg( $emailText, $ip, $u->getName(), $np, $wgServer . $wgScript, + round( $wgNewPasswordExpiry / 86400 ) )->inLanguage( $userLanguage )->text(); + $result = $u->sendMail( $this->msg( $emailTitle )->inLanguage( $userLanguage )->text(), $m ); return $result; } @@ -821,11 +828,10 @@ class LoginForm extends SpecialPage { * @private */ function successfulLogin() { - global $wgUser, $wgOut; - # Run any hooks; display injected HTML if any, else redirect + $currentUser = $this->getUser(); $injected_html = ''; - wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) ); + wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) ); if( $injected_html !== '' ) { $this->displaySuccessfulLogin( 'loginsuccess', $injected_html ); @@ -839,7 +845,7 @@ class LoginForm extends SpecialPage { if( $wgSecureLogin && !$this->mStickHTTPS ) { $redirectUrl = preg_replace( '/^https:/', 'http:', $redirectUrl ); } - $wgOut->redirect( $redirectUrl ); + $this->getOutput()->redirect( $redirectUrl ); } } @@ -850,12 +856,12 @@ class LoginForm extends SpecialPage { * @private */ function successfulCreation() { - global $wgUser; # Run any hooks; display injected HTML + $currentUser = $this->getUser(); $injected_html = ''; $welcome_creation_msg = 'welcomecreation'; - wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) ); + wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) ); //let any extensions change what message is shown wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) ); @@ -867,19 +873,18 @@ class LoginForm extends SpecialPage { * Display a "login successful" page. */ private function displaySuccessfulLogin( $msgname, $injected_html ) { - global $wgOut, $wgUser; - - $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) ); + $out = $this->getOutput(); + $out->setPageTitle( $this->msg( 'loginsuccesstitle' )->text() ); if( $msgname ){ - $wgOut->addWikiMsg( $msgname, wfEscapeWikiText( $wgUser->getName() ) ); + $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) ); } - $wgOut->addHTML( $injected_html ); + $out->addHTML( $injected_html ); if ( !empty( $this->mReturnTo ) ) { - $wgOut->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery ); + $out->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery ); } else { - $wgOut->returnToMain( null ); + $out->returnToMain( null ); } } @@ -891,8 +896,6 @@ class LoginForm extends SpecialPage { * @param $block Block the block causing this error */ function userBlockedMessage( Block $block ) { - global $wgOut; - # Let's be nice about this, it's likely that this feature will be used # for blocking large numbers of innocent people, e.g. range blocks on # schools. Don't blame it on the user. There's a small chance that it @@ -901,56 +904,56 @@ class LoginForm extends SpecialPage { # evade it, but we'll leave that to their guilty conscience to figure # out. - $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) ); + $out = $this->getOutput(); + $out->setPageTitle( $this->msg( 'cantcreateaccounttitle' )->text() ); $block_reason = $block->mReason; if ( strval( $block_reason ) === '' ) { - $block_reason = wfMsg( 'blockednoreason' ); + $block_reason = $this->msg( 'blockednoreason' )->text(); } - $wgOut->addWikiMsg( + $out->addWikiMsg( 'cantcreateaccount-text', $block->getTarget(), $block_reason, $block->getBlocker()->getName() ); - $wgOut->returnToMain( false ); + $out->returnToMain( false ); } /** * @private */ function mainLoginForm( $msg, $msgtype = 'error' ) { - global $wgUser, $wgOut, $wgHiddenPrefs; global $wgEnableEmail, $wgEnableUserEmail; - global $wgRequest, $wgLoginLanguageSelector; + global $wgHiddenPrefs, $wgLoginLanguageSelector; global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration; global $wgSecureLogin, $wgPasswordResetRoutes; - $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); + $titleObj = $this->getTitle(); + $user = $this->getUser(); if ( $this->mType == 'signup' ) { // Block signup here if in readonly. Keeps user from // going through the process (filling out data, etc) // and being informed later. if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); + throw new ReadOnlyError; + } elseif ( $user->isBlockedFromCreateAccount() ) { + $this->userBlockedMessage( $user->isBlockedFromCreateAccount() ); return; - } elseif ( $wgUser->isBlockedFromCreateAccount() ) { - $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); - return; - } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) { - $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' ); + } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $user, true ) )>0 ) { + $this->getOutput()->showPermissionsErrorPage( $permErrors, 'createaccount' ); return; } } if ( $this->mUsername == '' ) { - if ( $wgUser->isLoggedIn() ) { - $this->mUsername = $wgUser->getName(); + if ( $user->isLoggedIn() ) { + $this->mUsername = $user->getName(); } else { - $this->mUsername = $wgRequest->getCookie( 'UserName' ); + $this->mUsername = $this->getRequest()->getCookie( 'UserName' ); } } @@ -976,18 +979,16 @@ class LoginForm extends SpecialPage { $linkq .= $returnto; } - # Pass any language selection on to the mode switch link - if( $wgLoginLanguageSelector && $this->mLanguage ) { - $linkq .= '&uselang=' . $this->mLanguage; - } - - $link = ''; - $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink' - $link .= ''; - # Don't show a "create account" link if the user can't - if( $this->showCreateOrLoginLink( $wgUser ) ) { - $template->set( 'link', wfMsgExt( $linkmsg, array( 'parseinline', 'replaceafter' ), $link ) ); + if( $this->showCreateOrLoginLink( $user ) ) { + # Pass any language selection on to the mode switch link + if( $wgLoginLanguageSelector && $this->mLanguage ) { + $linkq .= '&uselang=' . $this->mLanguage; + } + $link = Html::element( 'a', array( 'href' => $titleObj->getLocalURL( $linkq ) ), + $this->msg( $linkmsg . 'link' )->text() ); # Calling either 'gotaccountlink' or 'nologinlink' + + $template->set( 'link', $this->msg( $linkmsg )->rawParams( $link )->parse() ); } else { $template->set( 'link', '' ); } @@ -1008,7 +1009,7 @@ class LoginForm extends SpecialPage { $template->set( 'action', $titleObj->getLocalURL( $q ) ); $template->set( 'message', $msg ); $template->set( 'messagetype', $msgtype ); - $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() ); + $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() ); $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) ); $template->set( 'useemail', $wgEnableEmail ); $template->set( 'emailrequired', $wgEmailConfirmToEdit ); @@ -1016,8 +1017,8 @@ class LoginForm extends SpecialPage { $template->set( 'canreset', $wgAuth->allowPasswordChange() ); $template->set( 'resetlink', $resetLink ); $template->set( 'canremember', ( $wgCookieExpiration > 0 ) ); - $template->set( 'usereason', $wgUser->isLoggedIn() ); - $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) || $this->mRemember ); + $template->set( 'usereason', $user->isLoggedIn() ); + $template->set( 'remember', $user->getOption( 'rememberpassword' ) || $this->mRemember ); $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) ); $template->set( 'stickHTTPS', $this->mStickHTTPS ); @@ -1043,17 +1044,17 @@ class LoginForm extends SpecialPage { // Use loginend-https for HTTPS requests if it's not blank, loginend otherwise // Ditto for signupend $usingHTTPS = WebRequest::detectProtocol() == 'https'; - $loginendHTTPS = wfMessage( 'loginend-https' ); - $signupendHTTPS = wfMessage( 'signupend-https' ); + $loginendHTTPS = $this->msg( 'loginend-https' ); + $signupendHTTPS = $this->msg( 'signupend-https' ); if ( $usingHTTPS && !$loginendHTTPS->isBlank() ) { $template->set( 'loginend', $loginendHTTPS->parse() ); } else { - $template->set( 'loginend', wfMessage( 'loginend' )->parse() ); + $template->set( 'loginend', $this->msg( 'loginend' )->parse() ); } if ( $usingHTTPS && !$signupendHTTPS->isBlank() ) { $template->set( 'signupend', $signupendHTTPS->parse() ); } else { - $template->set( 'signupend', wfMessage( 'signupend' )->parse() ); + $template->set( 'signupend', $this->msg( 'signupend' )->parse() ); } // Give authentication and captcha plugins a chance to modify the form @@ -1065,14 +1066,15 @@ class LoginForm extends SpecialPage { } // Changes the title depending on permissions for creating account - if ( $wgUser->isAllowed( 'createaccount' ) ) { - $wgOut->setPageTitle( wfMsg( 'userlogin' ) ); + $out = $this->getOutput(); + if ( $user->isAllowed( 'createaccount' ) ) { + $out->setPageTitle( $this->msg( 'userlogin' )->text() ); } else { - $wgOut->setPageTitle( wfMsg( 'userloginnocreate' ) ); + $out->setPageTitle( $this->msg( 'userloginnocreate' )->text() ); } - $wgOut->disallowUserJs(); // just in case... - $wgOut->addTemplate( $template ); + $out->disallowUserJs(); // just in case... + $out->addTemplate( $template ); } /** @@ -1102,8 +1104,8 @@ class LoginForm extends SpecialPage { * @private */ function hasSessionCookie() { - global $wgDisableCookieCheck, $wgRequest; - return $wgDisableCookieCheck ? true : $wgRequest->checkSessionCookie(); + global $wgDisableCookieCheck; + return $wgDisableCookieCheck ? true : $this->getRequest()->checkSessionCookie(); } /** @@ -1160,8 +1162,6 @@ class LoginForm extends SpecialPage { * @private */ function cookieRedirectCheck( $type ) { - global $wgOut; - $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); $query = array( 'wpCookieCheck' => $type ); if ( $this->mReturnTo ) { @@ -1169,7 +1169,7 @@ class LoginForm extends SpecialPage { } $check = $titleObj->getFullURL( $query ); - return $wgOut->redirect( $check ); + return $this->getOutput()->redirect( $check ); } /** @@ -1178,12 +1178,12 @@ class LoginForm extends SpecialPage { function onCookieRedirectCheck( $type ) { if ( !$this->hasSessionCookie() ) { if ( $type == 'new' ) { - return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) ); + return $this->mainLoginForm( $this->msg( 'nocookiesnew' )->parse() ); } elseif ( $type == 'login' ) { - return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) ); + return $this->mainLoginForm( $this->msg( 'nocookieslogin' )->parse() ); } else { # shouldn't happen - return $this->mainLoginForm( wfMsg( 'error' ) ); + return $this->mainLoginForm( $this->msg( 'error' )->text() ); } } else { return $this->successfulLogin(); @@ -1194,7 +1194,7 @@ class LoginForm extends SpecialPage { * @private */ function throttleHit( $limit ) { - $this->mainLoginForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $limit ) ); + $this->mainLoginForm( $this->msg( 'acct_creation_throttle_hit' )->numParams( $limit )->parse() ); } /** @@ -1204,9 +1204,7 @@ class LoginForm extends SpecialPage { * @return string */ function makeLanguageSelector() { - global $wgLang; - - $msg = wfMessage( 'loginlanguagelinks' )->inContentLanguage(); + $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage(); if( !$msg->isBlank() ) { $langs = explode( "\n", $msg->text() ); $links = array(); @@ -1217,7 +1215,8 @@ class LoginForm extends SpecialPage { $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) ); } } - return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', $wgLang->pipeList( $links ) ) : ''; + return count( $links ) > 0 ? $this->msg( 'loginlanguagelabel' )->rawParams( + $this->getLang()->pipeList( $links ) )->escaped() : ''; } else { return ''; } @@ -1231,7 +1230,6 @@ class LoginForm extends SpecialPage { * @param $lang Language code */ function makeLanguageSelectorLink( $text, $lang ) { - $self = SpecialPage::getTitleFor( 'Userlogin' ); $attr = array( 'uselang' => $lang ); if( $this->mType == 'signup' ) { $attr['type'] = 'signup'; @@ -1240,7 +1238,7 @@ class LoginForm extends SpecialPage { $attr['returnto'] = $this->mReturnTo; } return Linker::linkKnown( - $self, + $this->getTitle(), htmlspecialchars( $text ), array(), $attr -- 2.20.1