M4tx has uploaded a new change for review.

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


Change subject: Add 'You need cookies' message to 'Switch to desktop' link
......................................................................

Add 'You need cookies' message to 'Switch to desktop' link

* When user has JavaScript enabled, an alert is shown
* Otherwise, (s)he is redirected to Special:MobileEnableCookies

Bug: 51277
Change-Id: I29adc92c357f0e4a5ec0df95e77a951b0c29c50a
---
M MobileFrontend.i18n.php
M MobileFrontend.php
M includes/MobileContext.php
M includes/skins/SkinMobile.php
A includes/specials/SpecialMobileEnableCookies.php
M javascripts/modules/mf-stop-mobile-redirect.js
6 files changed, 42 insertions(+), 1 deletion(-)


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

diff --git a/MobileFrontend.i18n.php b/MobileFrontend.i18n.php
index 3154f0a..b30278d 100644
--- a/MobileFrontend.i18n.php
+++ b/MobileFrontend.i18n.php
@@ -398,6 +398,10 @@
        'mobile-frontend-profile-description-placeholder' => 'Why do 
{{GENDER:$1|you}} edit? What do {{GENDER:$1|you}} want to improve? Share 
{{GENDER:$1|your}} interests with others.',
        'mobile-frontend-profile-edit-summary' => 'Updating user profile 
introduction',
 
+       // Special:MobileEnableCookies
+       'mobile-frontend-enable-cookies' => 'Cookies are not enabled!',
+       'mobile-frontend-enable-cookies-message' => 'You don\'t seem to have 
cookies enabled. Please, enable them and try again.',
+
        // geo not a hack
        'mobile-frontend-geonotahack' => 'Near this page',
 
diff --git a/MobileFrontend.php b/MobileFrontend.php
index e5b9596..a762a78 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -68,6 +68,7 @@
 
        'SpecialUploads' => 'specials/SpecialUploads',
        'SpecialUserProfile' => 'specials/SpecialUserProfile',
+       'SpecialMobileEnableCookies' => 'specials/SpecialMobileEnableCookies',
        'SpecialMobileHistory' => 'specials/SpecialMobileHistory',
        'SpecialMobileUserlogin' => 'specials/SpecialMobileUserlogin',
        'SpecialMobileDiff' => 'specials/SpecialMobileDiff',
@@ -142,6 +143,7 @@
 $wgHooks['OutputPageParserOutput'][] = 
'MobileFrontendHooks::onOutputPageParserOutput';
 
 $wgSpecialPages['MobileDiff'] = 'SpecialMobileDiff';
+$wgSpecialPages['MobileEnableCookies'] = 'SpecialMobileEnableCookies';
 $wgSpecialPages['MobileEditor'] = 'SpecialMobileEditor';
 $wgSpecialPages['MobileOptions'] = 'SpecialMobileOptions';
 $wgSpecialPages['MobileMenu'] = 'SpecialMobileMenu';
diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index 2427584..824ae3f 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -793,6 +793,11 @@
         * and set a cookie to keep them on that view for subsequent requests.
         */
        public function toggleView( $view, $temporary = false ) {
+               if ( !$this->getRequest()->getCookie( 'mf_cookies_enabled' ) ) {
+                       $this->getOutput()->redirect( SpecialPage::getTitleFor( 
'MobileEnableCookies' )->getFullURL() );
+                       return;
+               }
+               
                global $wgMobileUrlTemplate;
 
                $url = $this->getTitle()->getFullURL();
@@ -839,7 +844,7 @@
        /**
         * Determine whether or not we need to toggle the view, and toggle it
         */
-       public function checkToggleView() {
+       public function checkToggleView() {             
                $mobileAction = $this->getMobileAction();
                if ( $mobileAction == 'toggle_view_desktop' ) {
                        $this->toggleView( 'desktop' );
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index dd19524..c4e558b 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -114,6 +114,8 @@
                $desktop = wfMessage( 'mobile-frontend-view-desktop' 
)->escaped();
                $mobile = wfMessage( 'mobile-frontend-view-mobile' )->escaped();
 
+               setcookie('mf_cookies_enabled', 'true', time()+60*60*24*30);
+
                $switcherHtml = <<<HTML
 <h2>{$this->getSitename()}</h2>
 <ul>
diff --git a/includes/specials/SpecialMobileEnableCookies.php 
b/includes/specials/SpecialMobileEnableCookies.php
new file mode 100644
index 0000000..d85892f
--- /dev/null
+++ b/includes/specials/SpecialMobileEnableCookies.php
@@ -0,0 +1,14 @@
+<?php
+
+class SpecialMobileEnableCookies extends MobileSpecialPage {
+       public function __construct() {
+               parent::__construct( 'MobileEnableCookies' );
+       }
+
+       public function execute( $par = '' ) {
+               $this->setHeaders();
+               $out = $this->getOutput();
+               $out->setPageTitle( wfMessage( 'mobile-frontend-enable-cookies' 
)->text() );
+               $out->addHTML( wfMessage( 
'mobile-frontend-enable-cookies-message' )->text() );
+       }
+}
diff --git a/javascripts/modules/mf-stop-mobile-redirect.js 
b/javascripts/modules/mf-stop-mobile-redirect.js
index 8d7b485..1a04b1e 100644
--- a/javascripts/modules/mf-stop-mobile-redirect.js
+++ b/javascripts/modules/mf-stop-mobile-redirect.js
@@ -17,7 +17,21 @@
        var
                writeCookie = M.settings.writeCookie;
 
+       function checkCookiesEnabled(){
+               var cookieEnabled = (navigator.cookieEnabled) ? true : false   
+               if (typeof navigator.cookieEnabled == 'undefined' && 
!cookieEnabled) { 
+                       document.cookie = 'testcookie';
+                       cookieEnabled = (document.cookie.indexOf( 'testcookie') 
!= -1) ? true : false;
+               }
+               return cookieEnabled;
+       }
+
        function desktopViewClick() {
+               if (!checkCookiesEnabled()) {
+                       alert( 'You have to enable cookies in order to switch 
to desktop mode!' );
+                       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/104209
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

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

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

Reply via email to