From 486bc2073a09adfa6f6ff8279a31bc4b87eb452d Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sat, 9 Jan 2016 22:41:46 +0000 Subject: [PATCH] Preferences: Use session data instead of URL parameter for success 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 | 8 ++++++-- includes/specials/SpecialPreferences.php | 10 ++++++++-- .../mediawiki.special/mediawiki.special.preferences.js | 5 ----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/includes/Preferences.php b/includes/Preferences.php index ad25fa8d91..5f37e3f75d 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -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(); diff --git a/includes/specials/SpecialPreferences.php b/includes/specials/SpecialPreferences.php index b45946f10f..3fa5fd526c 100644 --- a/includes/specials/SpecialPreferences.php +++ b/includes/specials/SpecialPreferences.php @@ -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; diff --git a/resources/src/mediawiki.special/mediawiki.special.preferences.js b/resources/src/mediawiki.special/mediawiki.special.preferences.js index c2b9a4ff1d..92064a698c 100644 --- a/resources/src/mediawiki.special/mediawiki.special.preferences.js +++ b/resources/src/mediawiki.special/mediawiki.special.preferences.js @@ -94,11 +94,6 @@ 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/, '' ) ); - } } } -- 2.20.1