Preferences: Use session data instead of URL parameter for success
authorFomafix <fomafix@googlemail.com>
Sat, 9 Jan 2016 22:41:46 +0000 (22:41 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Sat, 9 Jan 2016 22:41:46 +0000 (22:41 +0000)
The session data gets set in the POST and gets deleted in the GET.

This change avoids changing the URL for the success message.
A reload of the page does not show the success message again.

The URL manipulation in mediawiki.special.preferences.js is superfluous.

Bug: T26700
Change-Id: I1c2b011e7a66b2b9379dd4a3fdcc6f978dd43b52

includes/Preferences.php
includes/specials/SpecialPreferences.php
resources/src/mediawiki.special/mediawiki.special.preferences.js

index ad25fa8..5f37e3f 100644 (file)
@@ -1470,7 +1470,7 @@ class Preferences {
                $res = self::tryFormSubmit( $formData, $form );
 
                if ( $res ) {
-                       $urlOptions = array( 'success' => 1 );
+                       $urlOptions = array();
 
                        if ( $res === 'eauth' ) {
                                $urlOptions['eauth'] = 1;
@@ -1480,7 +1480,11 @@ class Preferences {
 
                        $url = $form->getTitle()->getFullURL( $urlOptions );
 
-                       $form->getContext()->getOutput()->redirect( $url );
+                       $context = $form->getContext();
+                       // Set session data for the success message
+                       $context->getRequest()->setSessionData( 'specialPreferencesSaveSuccess', 1 );
+
+                       $context->getOutput()->redirect( $url );
                }
 
                return Status::newGood();
index b45946f..3fa5fd5 100644 (file)
@@ -49,7 +49,11 @@ class SpecialPreferences extends SpecialPage {
                $out->addModules( 'mediawiki.special.preferences' );
                $out->addModuleStyles( 'mediawiki.special.preferences.styles' );
 
-               if ( $this->getRequest()->getCheck( 'success' ) ) {
+               $request = $this->getRequest();
+               if ( $request->getSessionData( 'specialPreferencesSaveSuccess' ) ) {
+                       // Remove session data for the success message
+                       $request->setSessionData( 'specialPreferencesSaveSuccess', null );
+
                        $out->wrapWikiMsg(
                                Html::rawElement(
                                        'div',
@@ -132,8 +136,10 @@ class SpecialPreferences extends SpecialPage {
                $user->resetOptions( 'all', $this->getContext() );
                $user->saveSettings();
 
-               $url = $this->getPageTitle()->getFullURL( 'success' );
+               // Set session data for the success message
+               $this->getRequest()->setSessionData( 'specialPreferencesSaveSuccess', 1 );
 
+               $url = $this->getPageTitle()->getFullURL();
                $this->getOutput()->redirect( $url );
 
                return true;
index c2b9a4f..92064a6 100644 (file)
                                                notif = null;
                                        }
                                } );
-
-                               // Remove now-unnecessary success=1 querystring to prevent reappearance of notification on reload
-                               if ( history.replaceState ) {
-                                       history.replaceState( {}, document.title, location.href.replace( /&?success=1/, '' ) );
-                               }
                        }
                }