Theopolisme has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/104210


Change subject: Warn user when attempting to switch to desktop without cookies
......................................................................

Warn user when attempting to switch to desktop without cookies

If user has JavaScript enabled, a warning will be shown
when they click on the "Desktop" link. If JavaScript is
not enabled, current behavior is for the the page to refresh
in place with the mobileaction parameter set to
"toggle_view_desktop" -- we watch for this and display an
appropriate error.

This is currently only enabled in the beta.

Bug: 51277
 Please enter the commit message for your changes. Lines starting

Change-Id: Iaa61dee1a285249ba662f935dd257ebdfc8ca10d
---
M MobileFrontend.i18n.php
M includes/Resources.php
M includes/skins/MinervaTemplate.php
M includes/skins/SkinMobileBeta.php
M javascripts/common/settings.js
M javascripts/modules/mf-stop-mobile-redirect.js
6 files changed, 38 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/10/104210/1

diff --git a/MobileFrontend.i18n.php b/MobileFrontend.i18n.php
index 3154f0a..2a14ca2 100644
--- a/MobileFrontend.i18n.php
+++ b/MobileFrontend.i18n.php
@@ -65,6 +65,7 @@
        'mobile-frontend-view' => 'Mobile view',
        'mobile-frontend-view-desktop' => 'Desktop',
        'mobile-frontend-view-mobile' => 'Mobile',
+       'mobile-frontend-cookies-required' => 'Cookies are required to switch 
to the desktop site. Please enable them and try again.',
        'mobile-frontend-opt-in-explain' => 'By joining the beta, you will get 
access to experimental features, at the risk of encountering bugs and issues.',
        'mobile-frontend-images-status' => 'Images',
        'mobile-frontend-disable-images' => 'Disable images on mobile site',
@@ -515,6 +516,7 @@
 {{Identical|Desktop}}',
        'mobile-frontend-view-mobile' => 'This appears at the bottom of the 
mobile page, meaning that the current view is mobile. It appears near the 
message {{msg-mw|Mobile-frontend-view-desktop}} and should be worded similarly.
 {{Identical|Mobile}}',
+       'mobile-frontend-cookies-required' => 'Error message shown when user 
attempts to switch to the desktop site and cookies are not enabled.',
        'mobile-frontend-opt-in-explain' => 'Used as description for the "Beta" 
in [[Special:MobileOptions]], if the beta is not enabled.',
        'mobile-frontend-images-status' => 'On settings page label for turning 
on/off images.
 {{Identical|Image}}',
diff --git a/includes/Resources.php b/includes/Resources.php
index 7c9eeef..187b894 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -196,6 +196,9 @@
                        'javascripts/common/settings.js',
                        'javascripts/modules/mf-stop-mobile-redirect.js',
                ),
+               'messages' => array(
+                       'mobile-frontend-cookies-required',
+               ),
                'position' => 'bottom',
        ),
 
diff --git a/includes/skins/MinervaTemplate.php 
b/includes/skins/MinervaTemplate.php
index c8414b8..cac3248 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -159,6 +159,10 @@
                        <?php
                                if ( $notSpecialPage ) {
                                        echo $data['prebodytext'];
+                                       // FIXME: Temporary solution; needs 
design
+                                       if ( isset( 
$data['_desktop_view_error'] ) ) {
+                                               echo 
$data['_desktop_view_error'];
+                                       }
                                        // FIXME: Temporary solution until we 
have design
                                        if ( isset( 
$data['_old_revision_warning'] ) ) {
                                                echo 
$data['_old_revision_warning'];
diff --git a/includes/skins/SkinMobileBeta.php 
b/includes/skins/SkinMobileBeta.php
index d3d8800..ff92686 100644
--- a/includes/skins/SkinMobileBeta.php
+++ b/includes/skins/SkinMobileBeta.php
@@ -168,6 +168,7 @@
        protected function prepareWarnings( BaseTemplate $tpl ) {
                parent::prepareWarnings( $tpl );
                $out = $this->getOutput();
+               // Warning if viewing an old revision
                if ( $out->getRequest()->getText( 'oldid' ) ) {
                        $subtitle = $out->getSubtitle();
                        $tpl->set( '_old_revision_warning',
@@ -179,5 +180,13 @@
                                $subtitle .
                                Html::closeElement( 'div' ) );
                }
+               // Warning if an attempted switch to desktop mode was 
unsuccessful
+               if ( $out->getRequest()->getText( 'mobileaction' ) === 
'toggle_view_desktop' ) {
+                       $tpl->set( '_desktop_view_error',
+                               Html::openElement( 'div', array( 'class' => 
'alert error' ) ) .
+                               Html::element( 'p', array(),
+                                       $this->msg( 
'mobile-frontend-cookies-required' )->text() ) .
+                               Html::closeElement( 'div' ) );
+               }
        }
 }
diff --git a/javascripts/common/settings.js b/javascripts/common/settings.js
index 29cca26..16e7dc8 100644
--- a/javascripts/common/settings.js
+++ b/javascripts/common/settings.js
@@ -10,6 +10,17 @@
                supportsLocalStorage = false;
        }
 
+       function cookiesEnabled() {
+               $.cookie( 'TEST_COOKIE', 'test_value', { path: '/' } );
+               if ( $.cookie( 'TEST_COOKIE' ) === 'test_value' ) {
+                       $.removeCookie( 'TEST_COOKIE',  { path: '/' } );
+                       return true;
+               } else {
+                       return false;
+               }
+
+       }
+
        // FIXME: Deprecate - use $.cookie instead
        function writeCookie( name, value, days, path, domain ) {
                $.cookie( name, value, { path: path, expires: days, domain: 
domain } );
@@ -36,7 +47,8 @@
                readCookie: readCookie,
                saveUserSetting: saveUserSetting,
                supportsLocalStorage: supportsLocalStorage,
-               writeCookie: writeCookie
+               writeCookie: writeCookie,
+               cookiesEnabled: cookiesEnabled
        };
 }());
 
diff --git a/javascripts/modules/mf-stop-mobile-redirect.js 
b/javascripts/modules/mf-stop-mobile-redirect.js
index 8d7b485..7fcedab 100644
--- a/javascripts/modules/mf-stop-mobile-redirect.js
+++ b/javascripts/modules/mf-stop-mobile-redirect.js
@@ -14,10 +14,15 @@
 
 ( function( M, $ ) {
 
-       var
-               writeCookie = M.settings.writeCookie;
+       var cookiesEnabled = M.settings.cookiesEnabled;
 
        function desktopViewClick() {
+               // If using the beta/alpha version and cookies are not enabled, 
die
+               if ( M.isBetaGroupMember() && !cookiesEnabled() ) {
+                       alert( mw.msg( 'mobile-frontend-cookies-required' ) );
+                       return false;
+               }
+
                // get info from cookie defined by wgUseFormatCookie
                var useFormatCookie = mw.config.get( 'wgUseFormatCookie' ),
                        redirectCookie = mw.config.get( 
'wgStopMobileRedirectCookie' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa61dee1a285249ba662f935dd257ebdfc8ca10d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Theopolisme <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to