jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/396082 )

Change subject: Cookie must be set on server side
......................................................................


Cookie must be set on server side

Setting the cookie on the client doesn't work.
It needs to be stored on the server.
This is because a call to MobileContext::setMobileMode must be
made to opt-in to beta, and cookies are not automatically forwarded from
the request to this method as needed. MobileOptions when submitted will
directly call this function.

We could of course update this behaviour must it would mean processing
cookies for every page view (not good!).

Submitting the form without an async save also avoids
the problem of having to refresh the page so after talking to Nirzar we
agreed to keep this simple and make it submit the form.

Changes:
* returnto parameter no longer honoured from Special:MobileOptions
* Remove MobileOptions::getURL which is dead code
* Successbox will only show in no-JavaScript mode. A toast is shown
in its place with JS.

Bug: T169369
Change-Id: I4028a0d37f51d8f6c6e64d49b52a76781b38676c
---
M extension.json
M includes/specials/SpecialMobileOptions.php
M resources/mobile.special.mobileoptions.scripts/mobileoptions.js
M resources/mobile.special.mobileoptions.styles/mobileoptions.less
4 files changed, 21 insertions(+), 44 deletions(-)

Approvals:
  Pmiazga: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index b4be0f0..de15843 100644
--- a/extension.json
+++ b/extension.json
@@ -944,7 +944,6 @@
                        "targets": [ "mobile", "desktop" ],
                        "position": "top",
                        "dependencies": [
-                               "jquery.cookie",
                                "mobile.startup"
                        ],
                        "scripts": [
diff --git a/includes/specials/SpecialMobileOptions.php 
b/includes/specials/SpecialMobileOptions.php
index 62dc4fe..4401371 100644
--- a/includes/specials/SpecialMobileOptions.php
+++ b/includes/specials/SpecialMobileOptions.php
@@ -79,8 +79,9 @@
 
                if ( $this->getRequest()->getCheck( 'success' ) ) {
                        $out->wrapWikiMsg(
-                               "<div 
class=\"successbox\"><strong>\n$1\n</strong></div><div 
id=\"mw-pref-clear\"></div>",
-                               'savedprefs'
+                               MobileUI::contentElement(
+                                       Html::successBox( $this->msg( 
'savedprefs' ) )
+                               )
                        );
                }
 
@@ -132,8 +133,6 @@
                        $fields[] = new OOUI\HiddenInputWidget( [ 'name' => 
'token',
                                'value' => $user->getEditToken() ] );
                }
-               $fields[] = new OOUI\HiddenInputWidget( [ 'name' => 'returnto',
-                       'value' => $this->returnToTitle->getFullText() ] );
 
                // @codingStandardsIgnoreEnd
                $form->appendContent(
@@ -196,8 +195,7 @@
        }
 
        /**
-        * Saves the settings submitted by the settings form. Redirects the 
user to the destination
-        * of returnto or, if not set, back to this special page
+        * Saves the settings submitted by the settings form
         */
        private function submitSettingsForm() {
                $schema = 'MobileOptionsTracking';
@@ -238,34 +236,8 @@
                        }
                }
                $context->setMobileMode( $group );
-               $returnToTitle = Title::newFromText( $request->getText( 
'returnto' ) );
-               if ( $returnToTitle ) {
-                       $url = $returnToTitle->getFullURL();
-               } else {
-                       $url = $this->getPageTitle()->getFullURL( 'success' );
-               }
+               $url = $this->getPageTitle()->getFullURL( 'success' );
                $context->getOutput()->redirect( 
MobileContext::singleton()->getMobileUrl( $url ) );
-       }
-
-       /**
-        * Get the URL of this special page
-        * @param string|null $option Subpage string, or false to not use a 
subpage
-        * @param Title $returnTo Destination to returnto after successfully 
action on the page returned
-        * @param bool $fullUrl Whether to get the local url, or the full url
-        *
-        * @return string
-        */
-       public static function getURL( $option, Title $returnTo = null, 
$fullUrl = false ) {
-               $t = SpecialPage::getTitleFor( 'MobileOptions', $option );
-               $params = [];
-               if ( $returnTo ) {
-                       $params['returnto'] = $returnTo->getPrefixedText();
-               }
-               if ( $fullUrl ) {
-                       return MobileContext::singleton()->getMobileUrl( 
$t->getFullURL( $params ) );
-               } else {
-                       return $t->getLocalURL( $params );
-               }
        }
 
        public function getSubpagesForPrefixSearch() {
diff --git a/resources/mobile.special.mobileoptions.scripts/mobileoptions.js 
b/resources/mobile.special.mobileoptions.scripts/mobileoptions.js
index 228b142..9a77ccd 100644
--- a/resources/mobile.special.mobileoptions.scripts/mobileoptions.js
+++ b/resources/mobile.special.mobileoptions.scripts/mobileoptions.js
@@ -1,6 +1,5 @@
 ( function ( M, $ ) {
        var storage = mw.storage,
-               cookie = $.cookie,
                notification,
                toast = M.require( 'mobile.startup/toast' ),
                EXPAND_SECTIONS_KEY = 'expandSections',
@@ -10,15 +9,20 @@
        /**
         * Notifies the user that settings were asynchronously saved.
         * @method
+        * @param {Boolean} isPending if set toast will show after page has 
been reloaded.
         * @ignore
         */
-       function notify() {
+       function notify( isPending ) {
                if ( notification ) {
                        clearTimeout( notification );
                }
-               notification = setTimeout( function () {
-                       toast.show( msg( 'mobile-frontend-settings-save' ) );
-               }, 1000 );
+               if ( isPending ) {
+                       toast.showOnPageReload( msg( 
'mobile-frontend-settings-save' ) );
+               } else {
+                       notification = setTimeout( function () {
+                               toast.show( msg( 
'mobile-frontend-settings-save' ) );
+                       }, 1000 );
+               }
        }
        /**
         * Creates a label for use with a form input
@@ -128,11 +132,10 @@
                        enableToggle = OO.ui.infuse( $( '#enable-beta-toggle' ) 
),
                        $form = $( '#mobile-options' );
 
-               // The beta toggle will now work without clicking submit
                enableToggle.on( 'change', function () {
-                       cookie( 'optin', this.isSelected() ? 'beta' : '' );
-                       notify();
-               }.bind( enableToggle ) );
+                       notify( true );
+                       $form.submit();
+               } );
 
                if ( mw.config.get( 'wgMFExpandAllSectionsUserOption' ) ) {
                        addExpandAllSectionsToForm( $form );
diff --git a/resources/mobile.special.mobileoptions.styles/mobileoptions.less 
b/resources/mobile.special.mobileoptions.styles/mobileoptions.less
index a67f027..7978d66 100644
--- a/resources/mobile.special.mobileoptions.styles/mobileoptions.less
+++ b/resources/mobile.special.mobileoptions.styles/mobileoptions.less
@@ -4,7 +4,10 @@
 SETTINGS PAGE
 */
 .client-js {
-
+       // toast will be shown in JS mode.
+       .successbox {
+               display: none;
+       }
        #mw-mf-settings-save {
                display: none;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/396082
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4028a0d37f51d8f6c6e64d49b52a76781b38676c
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: specialpages
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Pmiazga <pmia...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to