* Loader
*/
function load() {
- global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
+ global $wgAuth, $wgHiddenPrefs, $wgEnableEmail;
if ( $this->mLoaded ) {
return;
$this->mLanguage = $request->getText( 'uselang' );
$this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
$this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
-
- if ( $wgRedirectOnLogin ) {
- $this->mReturnTo = $wgRedirectOnLogin;
- $this->mReturnToQuery = '';
- } else {
- $this->mReturnTo = $request->getVal( 'returnto', '' );
- $this->mReturnToQuery = $request->getVal( 'returntoquery', '' );
- }
+ $this->mReturnTo = $request->getVal( 'returnto', '' );
+ $this->mReturnToQuery = $request->getVal( 'returntoquery', '' );
if( $wgEnableEmail ) {
$this->mEmail = $request->getText( 'wpEmail' );
$this->mainLoginForm( $this->msg( 'mailerror', $result->getWikiText() )->text() );
} else {
$out->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
- $out->returnToMain( false );
+ $this->executeReturnTo( 'success' );
}
}
# Confirm that the account was created
$out->setPageTitle( $this->msg( 'accountcreated' ) );
$out->addWikiMsg( 'accountcreatedtext', $u->getName() );
- $out->returnToMain( false, $this->getTitle() );
+ $out->addReturnTo( $this->getTitle() );
wfRunHooks( 'AddNewAccount', array( $u, false ) );
$u->addNewUserLogEntry( false, $this->mReason );
}
if( $injected_html !== '' ) {
$this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
} else {
- $titleObj = Title::newFromText( $this->mReturnTo );
- if ( !$titleObj instanceof Title ) {
- $titleObj = Title::newMainPage();
- }
- $redirectUrl = $titleObj->getFullURL( $this->mReturnToQuery );
- global $wgSecureLogin;
- if( $wgSecureLogin && !$this->mStickHTTPS ) {
- $redirectUrl = preg_replace( '/^https:/', 'http:', $redirectUrl );
- }
- $this->getOutput()->redirect( $redirectUrl );
+ $this->executeReturnTo( 'successredirect' );
}
}
$out->addHTML( $injected_html );
- if ( $this->mReturnTo !== '' ) {
- $out->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery );
- } else {
- $out->returnToMain( null );
- }
+ $this->executeReturnTo( 'success' );
}
/**
$block->getByName()
);
- $out->returnToMain( false );
+ $this->executeReturnTo( 'error' );
+ }
+
+ /**
+ * Add a "return to" link or redirect to it.
+ *
+ * @param $type string, one of the following:
+ * - error: display a return to link ignoring $wgRedirectOnLogin
+ * - success: display a return to link using $wgRedirectOnLogin if needed
+ * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
+ */
+ private function executeReturnTo( $type ) {
+ global $wgRedirectOnLogin, $wgSecureLogin;
+
+ if ( $type != 'error' && $wgRedirectOnLogin !== null ) {
+ $returnTo = $wgRedirectOnLogin;
+ $returnToQuery = array();
+ } else {
+ $returnTo = $this->mReturnTo;
+ $returnToQuery = wfCgiToArray( $this->mReturnToQuery );
+ }
+
+ $returnToTitle = Title::newFromText( $returnTo );
+ if ( !$returnToTitle ) {
+ $returnToTitle = Title::newMainPage();
+ }
+
+ if ( $type == 'successredirect' ) {
+ $redirectUrl = $returnToTitle->getFullURL( $returnToQuery );
+ if( $wgSecureLogin && !$this->mStickHTTPS ) {
+ $redirectUrl = preg_replace( '/^https:/', 'http:', $redirectUrl );
+ }
+ $this->getOutput()->redirect( $redirectUrl );
+ } else {
+ $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery );
+ }
}
/**