Use and forward returntoquery parameter in Special:ChangePassword
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 4 Feb 2013 21:14:41 +0000 (22:14 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 11 Feb 2013 10:45:51 +0000 (11:45 +0100)
Refactored the generation of hidden fields so that the returnto
and returntoquery only get added to the output if they actually
were provided in the request.

Change-Id: I144f04bec2fdd0947b5d206684d9c63a3d868168

includes/specials/SpecialChangePassword.php

index fba2bf0..2b505b3 100644 (file)
@@ -85,11 +85,7 @@ class SpecialChangePassword extends UnlistedSpecialPage {
                                                'wpDomain'     => $this->mDomain,
                                                'wpLoginToken' => $token,
                                                'wpPassword'   => $request->getVal( 'wpNewPassword' ),
-                                               'returnto'     => $request->getVal( 'returnto' ),
-                                       );
-                                       if( $request->getCheck( 'wpRemember' ) ) {
-                                               $data['wpRemember'] = 1;
-                                       }
+                                       ) + $request->getValues( 'wpRemember', 'returnto', 'returntoquery' );
                                        $login = new LoginForm( new FauxRequest( $data, true ) );
                                        $login->setContext( $this->getContext() );
                                        $login->execute( null );
@@ -103,11 +99,13 @@ class SpecialChangePassword extends UnlistedSpecialPage {
        }
 
        function doReturnTo() {
-               $titleObj = Title::newFromText( $this->getRequest()->getVal( 'returnto' ) );
+               $request = $this->getRequest();
+               $titleObj = Title::newFromText( $request->getVal( 'returnto' ) );
                if ( !$titleObj instanceof Title ) {
                        $titleObj = Title::newMainPage();
                }
-               $this->getOutput()->redirect( $titleObj->getFullURL() );
+               $query = $request->getVal( 'returntoquery' );
+               $this->getOutput()->redirect( $titleObj->getFullURL( $query ) );
        }
 
        /**
@@ -150,6 +148,15 @@ class SpecialChangePassword extends UnlistedSpecialPage {
                                        array( 'wpRetype', 'retypenew', 'password', null ),
                                );
                $prettyFields = array_merge( $prettyFields, $extraFields );
+               $hiddenFields = array(
+                       'token' => $user->getEditToken(),
+                       'wpName' => $this->mUserName,
+                       'wpDomain' => $this->mDomain,
+               ) + $this->getRequest()->getValues( 'returnto', 'returntoquery' );
+               $hiddenFieldsStr = '';
+               foreach( $hiddenFields as $fieldname => $fieldvalue ) {
+                       $hiddenFieldsStr .= Html::hidden( $fieldname, $fieldvalue ) . "\n";
+               }
                $this->getOutput()->addHTML(
                        Xml::fieldset( $this->msg( 'resetpass_header' )->text() ) .
                        Xml::openElement( 'form',
@@ -157,10 +164,7 @@ class SpecialChangePassword extends UnlistedSpecialPage {
                                        'method' => 'post',
                                        'action' => $this->getTitle()->getLocalUrl(),
                                        'id' => 'mw-resetpass-form' ) ) . "\n" .
-                       Html::hidden( 'token', $user->getEditToken() ) . "\n" .
-                       Html::hidden( 'wpName', $this->mUserName ) . "\n" .
-                       Html::hidden( 'wpDomain', $this->mDomain ) . "\n" .
-                       Html::hidden( 'returnto', $this->getRequest()->getVal( 'returnto' ) ) . "\n" .
+                       $hiddenFieldsStr .
                        $this->msg( 'resetpass_text' )->parseAsBlock() . "\n" .
                        Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) . "\n" .
                        $this->pretty( $prettyFields ) . "\n" .